JNGL
Drawable.hpp
Go to the documentation of this file.
1 // Copyright 2012-2022 Jan Niklas Hasse <[email protected]>
2 // For conditions of distribution and use, see copyright notice in LICENSE.txt
5 #pragma once
6 
7 #include "Vec2.hpp"
8 
9 namespace jngl {
10 
12 class Drawable {
13 public:
14  Drawable();
15  Drawable(const Drawable&) = default;
16  Drawable& operator=(const Drawable&) = default;
17  Drawable(Drawable&&) = default;
18  Drawable& operator=(Drawable&&) = default;
19  virtual ~Drawable();
20 
22  virtual void step() = 0;
23 
25  virtual void draw() const = 0;
26 
28  virtual void setPos(double x, double y);
29 
31  template <class Vect> void setPos(Vect p) {
32  setPos(p.x, p.y);
33  }
34 
37 
38  virtual void setCenter(double x, double y);
39 
40  template <class Vect> void setCenter(Vect c) {
41  setCenter(c.x, c.y);
42  }
43 
45  double getLeft() const;
46  void setLeft(double x);
47 
49  double getTop() const;
50  void setTop(double y);
51 
53  double getRight() const;
54  void setRight(double x);
55 
57  double getBottom() const;
58  void setBottom(double y);
59 
60  double getX() const;
61  void setX(double);
62 
63  double getY() const;
64  void setY(double);
65 
67  Vec2 getSize() const;
68 
70  float getWidth() const;
71 
73  float getHeight() const;
74 
75  void drawBoundingBox() const;
76 
78  bool contains(jngl::Vec2 point) const;
79 
80 protected:
81  Vec2 position;
82  float width = 0;
83  float height = 0;
84 };
85 
86 } // namespace jngl
Contains jngl::Vec2 class.
Base class for drawable objects with a position and a rectangle size.
Definition: Drawable.hpp:12
double getBottom() const
Returns the distance from the bottom of the screen.
virtual void draw() const =0
Called when drawing a frame.
double getTop() const
Returns the distance from the top of the screen.
virtual void setPos(double x, double y)
Sets the position of the top-left of the Drawable.
bool contains(jngl::Vec2 point) const
Returns whether point is inside the bounding box.
virtual void step()=0
Advance object's state.
float getWidth() const
Returns the width in screen coordinates.
double getRight() const
Returns the distance from the right side of the screen.
jngl::Vec2 getCenter() const
Returns the position of the center of the Drawable.
float getHeight() const
Returns the height in screen coordinates.
Vec2 getSize() const
Returns {width, height} in screen coordinates.
void setPos(Vect p)
Sets the position of the top-left of the Drawable.
Definition: Drawable.hpp:31
double getLeft() const
Returns the distance from the left side of the screen.
Two-dimensional vector.
Definition: Vec2.hpp:35
JNGL's main namespace.
Definition: App.hpp:10