UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
frame.h
Go to the documentation of this file.
1 #ifndef UGDK_MATH_FRAME_H_
2 #define UGDK_MATH_FRAME_H_
3 
4 namespace ugdk {
5 namespace math {
6 
7 // Representa um quadro (retangulo) na tela e/ou numa imagem.
8 // Util para trabalhar com animacoes, detectar colisoes
9 // (bounding box), etc.
10 //
11 // left, top, right e bottom sao usados para determinar as
12 // coordenadas do retangulo.
13 //
14 // (left,top)
15 // +------------------+
16 // | |
17 // | |
18 // +------------------+
19 // (right,bottom)
20 
28 class Frame {
29  public:
30  // Construtores e destrutores
32  Frame() : left_(0), top_(0), right_(0), bottom_(0) { }
34 
40  Frame(double _left, double _top, double _right, double _bottom) :
41  left_(_left), top_(_top), right_(_right), bottom_(_bottom) { }
42  ~Frame() { }
43 
44  // Utilidades inline
46  double width() const { return right_ - left_; }
48  double height() const { return bottom_ - top_; }
49 
50  // Accessors e mutators
55  void set_left(double _left) { left_ = _left; }
56  void set_top(double _top) { top_ = _top; }
57  void set_right(double _right) { right_ = _right; }
58  void set_bottom(double _bottom) { bottom_ = _bottom; }
59 
60  double left() const { return left_; }
61  double top() const { return top_; }
62  double right() const { return right_; }
63  double bottom() const { return bottom_; }
66  // Devolve true se houver colisao entre
67  // 'frame' e este retangulo.
69  bool Collides(const math::Frame& frame) const;
70 
71  private:
72  double left_, top_, right_, bottom_;
73 };
74 
75 } // namespace math
76 } // namespace ugdk
77 
78 #endif // UGDK_MATH_FRAME_H_
Represents a frame on the screen or an image.
Definition: frame.h:28
~Frame()
Definition: frame.h:42
double right() const
Definition: frame.h:62
void set_left(double _left)
Definition: frame.h:55
double bottom() const
Definition: frame.h:63
Definition: animation.h:11
double width() const
Returns the width of the frame.
Definition: frame.h:46
Frame(double _left, double _top, double _right, double _bottom)
Creates a frame with the given coordinates.
Definition: frame.h:40
double top() const
Definition: frame.h:61
void set_right(double _right)
Definition: frame.h:57
Frame()
Creates an empty frame at (0, 0).
Definition: frame.h:32
void set_top(double _top)
Definition: frame.h:56
double left() const
Definition: frame.h:60
bool Collides(const math::Frame &frame) const
Returns whether this frame and the other frame are colliding.
double height() const
Returns the height of the frame.
Definition: frame.h:48
void set_bottom(double _bottom)
Definition: frame.h:58