Fl_Rect.H 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // "$Id: Fl_Rect.H 12260 2017-06-13 10:35:18Z AlbrechtS $"
  3. //
  4. // Fl_Rect header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2017 by Bill Spitzak and others.
  7. //
  8. // This library is free software. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. #ifndef Fl_Rect_H
  19. #define Fl_Rect_H
  20. #include <FL/Fl_Widget.H> // for c'tor based on Fl_Widget
  21. /**
  22. Rectangle with standard FLTK coordinates (X, Y, W, H).
  23. This may be used internally, for overloaded widget contructors and other
  24. overloaded methods like fl_measure(), fl_text_extents(), fl_rect(),
  25. fl_rectf(), and maybe more.
  26. */
  27. class FL_EXPORT Fl_Rect {
  28. int x_;
  29. int y_;
  30. int w_;
  31. int h_;
  32. public:
  33. /** The default constructor creates an empty rectangle (x = y = w = h = 0). */
  34. Fl_Rect()
  35. : x_(0), y_(0), w_(0), h_(0) {}
  36. /** This constructor creates a rectangle with x = y = 0 and
  37. the given width and height. */
  38. Fl_Rect(int W, int H)
  39. : x_(0), y_(0), w_(W), h_(H) {}
  40. /** This constructor creates a rectangle with the given x,y coordinates
  41. and the given width and height. */
  42. Fl_Rect(int X, int Y, int W, int H)
  43. : x_(X), y_(Y), w_(W), h_(H) {}
  44. /** This constructor creates a rectangle based on a widget's position and size. */
  45. Fl_Rect (const Fl_Widget& widget)
  46. : x_(widget.x()), y_(widget.y()), w_(widget.w()), h_(widget.h()) {}
  47. /** This constructor creates a rectangle based on a widget's position and size. */
  48. Fl_Rect (const Fl_Widget* const widget)
  49. : x_(widget->x()), y_(widget->y()), w_(widget->w()), h_(widget->h()) {}
  50. int x() const { return x_; } ///< gets the x coordinate (left edge)
  51. int y() const { return y_; } ///< gets the y coordinate (top edge)
  52. int w() const { return w_; } ///< gets the width
  53. int h() const { return h_; } ///< gets the height
  54. int r() const { return x_ + w_; } ///< gets the right edge (x + w)
  55. int b() const { return y_ + h_; } ///< gets the bottom edge (y + h)
  56. void x(int X) { x_ = X; } ///< sets the x coordinate (left edge)
  57. void y(int Y) { y_ = Y; } ///< sets the y coordinate (top edge)
  58. void w(int W) { w_ = W; } ///< sets the width
  59. void h(int H) { h_ = H; } ///< sets the height
  60. }; // class Fl_Rect
  61. #endif // Fl_Rect_H
  62. //
  63. // End of "$Id: Fl_Rect.H 12260 2017-06-13 10:35:18Z AlbrechtS $".
  64. //