IceDragon200

C++ Rect Class

Jun 9th, 2011
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. struct SRect
  2. {
  3.   int x;
  4.   int y;
  5.   int width;
  6.   int height;
  7. };  
  8.  
  9. class Rect
  10. {
  11. private: // # Though its already private but what the heck
  12.   int x;
  13.   int y;
  14.   int width;
  15.   int height;
  16.  
  17. public:  // # Public functions
  18.  
  19.   Rect() // # No Args
  20.   {
  21.     x = 0;
  22.     y = 0;
  23.     width = 0;
  24.     height = 0;
  25.   }
  26.  
  27.   // # With Parameters
  28.   Rect( int sx, int sy, int swidth, int sheight )
  29.   {
  30.     x = sx;
  31.     y = sy;
  32.     width = swidth;
  33.     height = sheight;
  34.   }
  35.  
  36.   // Getters
  37.   int getX() { return x; }
  38.   int getY() { return y; }
  39.   int getWidth() { return width; }
  40.   int getHeight() { return height; }
  41.   // Setter
  42.   void set( int nx, int ny, int nwidth, int nheight )
  43.   {
  44.     x      = nx      ;
  45.     y      = ny      ;
  46.     width  = nwidth  ;
  47.     height = nheight ;
  48.   }
  49.   void setX(int nx)           { x = nx; }
  50.   void setY(int ny)           { y = ny; }
  51.   void setWidth(int nwidth)   { if (nwidth > 0 ) { width = nwidth; } }
  52.   void setHeight(int nheight) { if (nheight > 0 ) { height = nheight; } }
  53.  
  54. };
Advertisement
Add Comment
Please, Sign In to add comment