JNGL
Drawable.hpp
Go to the documentation of this file.
1 // Copyright 2012-2020 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 
27  virtual void setPos(double x, double y);
28 
29  jngl::Vec2 getCenter() const;
30 
31  virtual void setCenter(double x, double y);
32 
33  template <class Vect> void setCenter(Vect c) {
34  setCenter(c.x, c.y);
35  }
36 
38  double getLeft() const;
39  void setLeft(double x);
40 
42  double getTop() const;
43  void setTop(double y);
44 
46  double getRight() const;
47  void setRight(double x);
48 
50  double getBottom() const;
51  void setBottom(double y);
52 
53  double getX() const;
54  void setX(double);
55 
56  double getY() const;
57  void setY(double);
58 
60  Vec2 getSize() const;
61 
63  float getWidth() const;
64 
66  float getHeight() const;
67 
68  void drawBoundingBox() const;
69 
71  bool contains(jngl::Vec2 point) const;
72 
73 protected:
74  Vec2 position;
75  float width = 0;
76  float height = 0;
77 };
78 
79 } // 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.
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.
float getHeight() const
Returns the height in screen coordinates.
Vec2 getSize() const
Returns {width, height} in screen coordinates.
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