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  double x = 0;
75  double y = 0;
76  float width = 0;
77  float height = 0;
78 };
79 
80 } // namespace jngl
jngl::Drawable::getWidth
float getWidth() const
Returns the width in screen coordinates.
jngl::Drawable::step
virtual void step()=0
Advance object's state.
jngl::Drawable::getRight
double getRight() const
Returns the distance from the right side of the screen.
jngl::Drawable::getBottom
double getBottom() const
Returns the distance from the bottom of the screen.
jngl
JNGL's main namespace.
Definition: App.hpp:9
Vec2.hpp
jngl::Drawable
Base class for drawable objects with a position and a rectangle size.
Definition: Drawable.hpp:12
jngl::Drawable::draw
virtual void draw() const =0
Called when drawing a frame.
jngl::Drawable::getLeft
double getLeft() const
Returns the distance from the left side of the screen.
jngl::Drawable::getSize
Vec2 getSize() const
Returns {width, height} in screen coordinates.
jngl::Vec2
Two-dimensional vector.
Definition: Vec2.hpp:14
jngl::Drawable::getHeight
float getHeight() const
Returns the height in screen coordinates.
jngl::Drawable::contains
bool contains(jngl::Vec2 point) const
Returns whether point is inside the bounding box.
jngl::Drawable::getTop
double getTop() const
Returns the distance from the top of the screen.