2020-04-13 11:24:53 +00:00
|
|
|
#ifndef SHAPE_H
|
|
|
|
#define SHAPE_H
|
|
|
|
|
|
|
|
#include "../base/vecmath.h"
|
2020-06-30 22:23:07 +00:00
|
|
|
#include "drawable.h"
|
2020-04-13 11:24:53 +00:00
|
|
|
|
|
|
|
namespace eng {
|
|
|
|
|
2020-06-30 22:23:07 +00:00
|
|
|
class Animatable : public Drawable {
|
2020-04-13 11:24:53 +00:00
|
|
|
public:
|
|
|
|
Animatable() = default;
|
2020-06-30 22:23:07 +00:00
|
|
|
~Animatable() override = default;
|
2020-04-13 11:24:53 +00:00
|
|
|
|
2021-02-18 14:42:08 +00:00
|
|
|
void Translate(const base::Vector2f& pos);
|
|
|
|
void Scale(const base::Vector2f& scale);
|
2020-04-13 11:24:53 +00:00
|
|
|
void Scale(float scale);
|
|
|
|
void Rotate(float angle);
|
|
|
|
|
2021-02-18 14:42:08 +00:00
|
|
|
void SetPosition(const base::Vector2f& pos) { position_ = pos; }
|
|
|
|
void SetSize(const base::Vector2f& size) { size_ = size; }
|
2020-04-13 11:24:53 +00:00
|
|
|
void SetTheta(float theta);
|
|
|
|
|
2021-02-18 14:42:08 +00:00
|
|
|
base::Vector2f GetPosition() const { return position_; }
|
|
|
|
base::Vector2f GetSize() const { return size_ * scale_; }
|
2020-04-13 11:24:53 +00:00
|
|
|
float GetTheta() const { return theta_; }
|
2021-02-18 14:42:08 +00:00
|
|
|
base::Vector2f GetRotation() const { return rotation_; }
|
2020-04-13 11:24:53 +00:00
|
|
|
|
|
|
|
// Pure virtuals for frame animation support.
|
|
|
|
virtual void SetFrame(size_t frame) = 0;
|
|
|
|
virtual size_t GetFrame() const = 0;
|
|
|
|
virtual size_t GetNumFrames() const = 0;
|
|
|
|
|
2021-02-18 14:42:08 +00:00
|
|
|
virtual void SetColor(const base::Vector4f& color) = 0;
|
|
|
|
virtual base::Vector4f GetColor() const = 0;
|
2020-04-13 11:24:53 +00:00
|
|
|
|
|
|
|
void PlaceToLeftOf(const Animatable& s) {
|
2020-09-17 22:03:21 +00:00
|
|
|
Translate({s.GetSize().x / -2.0f + GetSize().x / -2.0f, 0});
|
2020-04-13 11:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaceToRightOf(const Animatable& s) {
|
2020-09-17 22:03:21 +00:00
|
|
|
Translate({s.GetSize().x / 2.0f + GetSize().x / 2.0f, 0});
|
2020-04-13 11:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaceToTopOf(const Animatable& s) {
|
2020-09-17 22:03:21 +00:00
|
|
|
Translate({0, s.GetSize().y / 2.0f + GetSize().y / 2.0f});
|
2020-04-13 11:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaceToBottomOf(const Animatable& s) {
|
2020-09-17 22:03:21 +00:00
|
|
|
Translate({0, s.GetSize().y / -2.0f + GetSize().y / -2.0f});
|
2020-04-13 11:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2021-02-18 14:42:08 +00:00
|
|
|
base::Vector2f position_ = {0, 0};
|
|
|
|
base::Vector2f size_ = {1, 1};
|
|
|
|
base::Vector2f scale_ = {1, 1};
|
|
|
|
base::Vector2f rotation_ = {0, 1};
|
2020-04-13 11:24:53 +00:00
|
|
|
float theta_ = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace eng
|
|
|
|
|
|
|
|
#endif // SHAPE_H
|