home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-3.ZIP / EXAMPLES.ZIP / CIRCLE.CPP < prev    next >
C/C++ Source or Header  |  1992-02-18  |  3KB  |  89 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3. /* CIRCLE.CPP--Example from Getting Started */
  4.  
  5. // CIRCLE.CPP   A Circle class derived from Point
  6.  
  7. #include <graphics.h>    // graphics library declarations
  8. #include "point.h"       // Location and Point class declarations
  9. #include <conio.h>       // for getch() function
  10.  
  11. // link with point2.obj and graphics.lib
  12.  
  13. class Circle : Point {   // derived privately from class Point
  14.                          // and ultimately from class Location
  15.    int Radius;           // private by default
  16.  
  17. public:
  18.    Circle(int InitX, int InitY, int InitRadius);
  19.    void Show(void);
  20.    void Hide(void);
  21.    void Expand(int ExpandBy);
  22.    void MoveTo(int NewX, int NewY);
  23.    void Contract(int ContractBy);
  24. };
  25.  
  26. Circle::Circle(int InitX, int InitY, int InitRadius) : Point(InitX,InitY)
  27. {
  28.    Radius = InitRadius;
  29. };
  30.  
  31. void Circle::Show(void)
  32. {
  33.    Visible = true;
  34.    circle(X, Y, Radius);      // draw the circle
  35. }
  36.  
  37. void Circle::Hide(void)
  38. {
  39.    unsigned int TempColor;    // to save current color
  40.    TempColor = getcolor();    // set to current color
  41.    setcolor(getbkcolor());    // set drawing color to background
  42.    Visible = false;
  43.    circle(X, Y, Radius);      // draw in background color to erase
  44.    setcolor(TempColor);       // set color back to current color
  45. };
  46.  
  47. void Circle::Expand(int ExpandBy)
  48. {
  49.    Hide();                       // erase old circle
  50.    Radius += ExpandBy;           // expand radius
  51.    if (Radius < 0)               // avoid negative radius
  52.       Radius = 0;
  53.    Show();                       // draw new circle
  54. };
  55.  
  56. void Circle::Contract(int ContractBy)
  57. {
  58.    Expand(-ContractBy);       // redraws with (Radius - ContractBy)
  59. };
  60.  
  61. void Circle::MoveTo(int NewX, int NewY)
  62. {
  63.    Hide();                    // erase old circle
  64.    X = NewX;                  // set new location
  65.    Y = NewY;
  66.    Show();                    // draw in new location
  67. };
  68.  
  69. main()                        // test the functions
  70. {
  71.    // initialize the graphics system
  72.    int graphdriver = DETECT, graphmode;
  73.    initgraph(&graphdriver, &graphmode, "..\\bgi");
  74.  
  75.    Circle MyCircle(100, 200, 50);   // declare a circle object
  76.    MyCircle.Show();                 // show it
  77.    getch();                         // wait for keypress
  78.    MyCircle.MoveTo(200, 250);       // move the circle (tests hide
  79.                                     // and show also)
  80.    getch();
  81.    MyCircle.Expand(50);             // make it bigger
  82.    getch();
  83.    MyCircle.Contract(75);           // make it smaller
  84.    getch();
  85.    closegraph();
  86.    return 0;
  87. }
  88.  
  89.