home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- Listing 13 - ARC.CPP
-
- Written by Kevin D. Weeks, April 1990
- Released to the Public Domain
- */
-
- #include "arc.hpp"
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- Constructor - creates an empty instance.
- */
- Arc::Arc(void)
- {
- struct linesettingstype line_type;
-
- // set attributes to 0 or current BGI defaults
- start_angle = 0;
- end_angle = 0;
- radius = 0;
- getlinesettings(&line_type);
- width = (line_widths)line_type.thickness;
- color = (COLORS)getcolor();
- visible = FALSE;
- }
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- Constructor - since the "copy constructor", Arc(const Arc &source),
- won't accept a pointer easily so we define a separate pointer
- constructor for convenience' sake.
- */
- Arc::Arc(const Arc *source)
- {
- start_angle = source->start_angle;
- end_angle = source->end_angle;
- radius = source->radius;
- center = source->center;
- width = source->width;
- color = source->color;
- visible = FALSE;
- }
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- Constructor - primary constructor. Copies of all attributes are
- accepted although init_color and init_width may be defaults.
- */
- Arc::Arc(const int starting_angle, const int ending_angle,
- const int init_radius, const Point &init_center,
- const COLORS init_color, const line_widths init_width)
- {
- struct linesettingstype line_type;
-
- if (init_width == DEFAULT)
- {
- getlinesettings(&line_type);
- width = (line_widths)line_type.thickness;
- }
- else
- width = init_width;
-
- if (init_color == DEFAULT)
- color = (COLORS)getcolor();
- else
- color = init_color;
-
- start_angle = starting_angle;
- end_angle = ending_angle;
- radius = init_radius;
- center = init_center;
- visible = FALSE;
- }
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- color can be set whether the line is visible or not
- */
- void Arc::set_color(const COLORS new_color)
- {
- if (new_color == DEFAULT)
- color = (COLORS)getcolor();
- else
- color = new_color;
- if (visible)
- {
- erase();
- draw();
- }
- }
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- width can be set whether the line is visible or not
- */
- void Arc::set_width(line_widths new_width)
- {
- struct linesettingstype line_type;
-
- if (new_width == DEFAULT)
- {
- getlinesettings(&line_type);
- new_width = (line_widths)line_type.thickness;
- }
- if (visible)
- {
- erase(); // erase using old width
- width = new_width; // change style
- draw(); // draw using new width
- }
- else
- width = new_width;
- }
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- the draw() method first preserves the current BGI settings, then
- resets the BGI defaults for this particular object, and finally
- restores the original settings. had we written the graphics routines
- from scratch the step of preserving and then restoring the settings
- wouldn't be neccessary.
- */
- void Arc::draw(void)
- {
- struct linesettingstype hold_current;
- int default_color;
-
- // don't draw it twice
- if (visible)
- return;
-
- // preserve current settings
- getlinesettings(&hold_current);
- default_color = getcolor();
-
- // select color and line style for this object and draw it
- setcolor(color);
- setlinestyle(hold_current.linestyle,0,width);
- arc(center.get_x(),center.get_y(),start_angle,end_angle,radius);
-
- // restore original settings
- setlinestyle(hold_current.linestyle,hold_current.upattern,
- hold_current.thickness);
- setcolor(default_color);
- visible = TRUE;
- }
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- the erase method draws over the existing arc using the background
- color. as with the draw method, the current BGI settings must be
- preserved and then restored.
- */
- void Arc::erase(void)
- {
- struct linesettingstype hold_current;
- int default_color;
-
- // don't erase it if it isn't visible
- if (!visible)
- return;
-
- // preserve current settings
- getlinesettings(&hold_current);
- default_color = getcolor();
-
- // set the foreground current color to the background color and set the
- // BGI defaults for this object and draw over it
- setcolor(getbkcolor());
- setlinestyle(hold_current.linestyle,0,width);
- arc(center.get_x(),center.get_y(),start_angle,end_angle,radius);
-
- // restore the defaults
- setlinestyle(hold_current.linestyle,hold_current.upattern,
- hold_current.thickness);
- setcolor(default_color);
- visible = FALSE;
- }
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- void Arc::move_relative(Point &distance)
- {
- erase();
- center += distance;
- draw();
- }
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- void Arc::move_absolute(Point &new_location, Point &reference)
- {
- erase();
- center += new_location - reference;
- draw();
- }
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- this is the private method used by the copy constructor and the =
- operator. Note that the visible attribute is forced to FALSE.
- */
- Arc &Arc::copy(const Arc &source)
- {
- start_angle = source.start_angle;
- end_angle = source.end_angle;
- radius = source.radius;
- center = source.center;
- width = source.width;
- color = source.color;
- visible = FALSE;
- return *this;
- }
-