home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 3.ddi / BGICLA.ZIP / DOT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-24  |  2.6 KB  |  94 lines

  1. /**************************************************************************
  2.     Listing 7 - DOT.CPP
  3.  
  4.     Written by Kevin D. Weeks, April 1990
  5.     Released to the Public Domain
  6. */
  7. #include "dot.hpp"
  8.  
  9. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  10.     Constructor - the location attribute will initialize itself so all
  11.     we need to do is set the color to the default.
  12. */
  13. Dot::Dot(void)
  14. {
  15.     color = (COLORS)getcolor();
  16. }
  17.  
  18. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  19.     Constructor - since the copy constructor", Dot(const Dot &source),
  20.     won't accept a pointer easily so we define a separate pointer
  21.     constructor for convenience' sake.
  22. */
  23. Dot::Dot(const Dot *source)
  24. {
  25.     location = source->location;
  26.     color = source->color;
  27.     visible = FALSE;
  28. }
  29.  
  30. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  31.     Constructor - primary constructor.
  32. */
  33. Dot::Dot(const Point &init_location, COLORS init_color)
  34. {
  35.     location = init_location;
  36.     if (init_color = (COLORS)DEFAULT)
  37.         color = (COLORS)getcolor();
  38.     else
  39.         color = init_color;
  40. }
  41.  
  42. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  43. void    Dot::set_color(COLORS new_color)
  44. {
  45.     if (new_color == (COLORS)DEFAULT)
  46.         color = (COLORS)getcolor();
  47.     else
  48.         color = new_color;
  49.     if (visible)
  50.         draw();
  51. }
  52.  
  53. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  54. void    Dot::draw(void)
  55. {
  56.     putpixel(location.get_x(),location.get_y(),(int)color);
  57. }
  58.  
  59. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  60.     Draws the dot in the background color.
  61. */
  62. void    Dot::erase(void)
  63. {
  64.     putpixel(location.get_x(),location.get_y(),getbkcolor());
  65. }
  66.  
  67. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  68. void    Dot::move_relative(Point &distance)
  69. {
  70.     erase();
  71.     location += distance;
  72.     draw();
  73. }
  74.  
  75. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  76. void    Dot::move_absolute(Point &new_location, Point &reference)
  77. {
  78.     erase();
  79.     location += new_location - reference;
  80.     draw();
  81. }
  82.  
  83. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  84.     this is the private method used by the copy constructor and the =
  85.     operator. Note that the visible attribute is forced to FALSE.
  86. */
  87. Dot     &Dot::copy(const Dot &source)
  88. {
  89.     location = source.location;
  90.     color = source.color;
  91.     visible = FALSE;
  92.     return *this;
  93. }
  94.