Apply formating to all files. CLeanup

This commit is contained in:
IlyaShurupov 2023-10-22 17:07:28 +03:00 committed by Ilya Shurupov
parent b4ae5dde77
commit 91fb72bd49
928 changed files with 14515 additions and 21479 deletions

View file

@ -1,104 +1,92 @@
#include "Animations.hpp"
using namespace tp;
bool AnimValue::gInTransition = false;
halnf AnimValue::interpolate() const {
if (!mTimeAnim) {
return mVal;
}
auto dt = gCurrentTime - mTimeStart;
if (dt > mTimeAnim) dt = mTimeAnim;
auto t = (halnf)dt / (halnf)mTimeAnim;
t = (halnf)(0.511 + atan((t - 0.36) * 28) / 2.9);
t = clamp(t, 0.f, 1.f);
auto out = mValPrev + (mVal - mValPrev) * t;
return out;
}
AnimValue::AnimValue() = default;
void AnimValue::setAnimTime(halni time) {
mTimeAnim = time;
}
AnimValue::AnimValue(halnf val) {
mVal = val;
mValPrev = mVal;
mTimeStart = gCurrentTime;
}
bool AnimValue::inTransition() const {
auto timePassed = gCurrentTime - mTimeStart >= mTimeAnim;
return !timePassed;
}
void AnimValue::set(halnf val) {
if (!inTransition()) mValPrev = mVal;
if (val == mVal) return;
mValPrev = get();
mVal = val;
if (!inTransition()) mTimeStart = (halni)gCurrentTime;
}
halnf AnimValue::getTarget() const {
return mVal;
}
void AnimValue::setNoTransition(halnf val) {
mValPrev = val;
mVal = val;
mTimeStart -= mTimeStart;
}
halnf AnimValue::get() const {
if (inTransition()) {
gInTransition = true;
}
return interpolate();
}
AnimValue::operator halnf() const {
return get();
}
RectF AnimRect::get() const {
return { x.get(), y.get() , z.get(), w.get() };
}
RectF AnimRect::getTarget() const {
return { x.getTarget(), y.getTarget() , z.getTarget(), w.getTarget() };
}
void AnimRect::setNoTransition(RectF rec) {
x.setNoTransition(rec.x);
y.setNoTransition(rec.y);
z.setNoTransition(rec.z);
w.setNoTransition(rec.w);
}
void AnimRect::setAnimTime(const halni time) {
x.setAnimTime(time);
y.setAnimTime(time);
z.setAnimTime(time);
w.setAnimTime(time);
}
void AnimRect::set(const RectF& in) {
x.set(in.x);
y.set(in.y);
z.set(in.z);
w.set(in.w);
}
RGBA AnimColor::get() const {
auto col = mColor.get();
return {col.x, col.y, col.z, col.w};
}
void AnimColor::set(const RGBA& col) {
mColor.set(RectF(col.r, col.g, col.b, col.a));
}
#include "Animations.hpp"
using namespace tp;
bool AnimValue::gInTransition = false;
halnf AnimValue::interpolate() const {
if (!mTimeAnim) {
return mVal;
}
auto dt = gCurrentTime - mTimeStart;
if (dt > mTimeAnim) dt = mTimeAnim;
auto t = (halnf) dt / (halnf) mTimeAnim;
t = (halnf) (0.511 + atan((t - 0.36) * 28) / 2.9);
t = clamp(t, 0.f, 1.f);
auto out = mValPrev + (mVal - mValPrev) * t;
return out;
}
AnimValue::AnimValue() = default;
void AnimValue::setAnimTime(halni time) { mTimeAnim = time; }
AnimValue::AnimValue(halnf val) {
mVal = val;
mValPrev = mVal;
mTimeStart = gCurrentTime;
}
bool AnimValue::inTransition() const {
auto timePassed = gCurrentTime - mTimeStart >= mTimeAnim;
return !timePassed;
}
void AnimValue::set(halnf val) {
if (!inTransition()) mValPrev = mVal;
if (val == mVal) return;
mValPrev = get();
mVal = val;
if (!inTransition()) mTimeStart = (halni) gCurrentTime;
}
halnf AnimValue::getTarget() const { return mVal; }
void AnimValue::setNoTransition(halnf val) {
mValPrev = val;
mVal = val;
mTimeStart -= mTimeStart;
}
halnf AnimValue::get() const {
if (inTransition()) {
gInTransition = true;
}
return interpolate();
}
AnimValue::operator halnf() const { return get(); }
RectF AnimRect::get() const { return { x.get(), y.get(), z.get(), w.get() }; }
RectF AnimRect::getTarget() const { return { x.getTarget(), y.getTarget(), z.getTarget(), w.getTarget() }; }
void AnimRect::setNoTransition(RectF rec) {
x.setNoTransition(rec.x);
y.setNoTransition(rec.y);
z.setNoTransition(rec.z);
w.setNoTransition(rec.w);
}
void AnimRect::setAnimTime(const halni time) {
x.setAnimTime(time);
y.setAnimTime(time);
z.setAnimTime(time);
w.setAnimTime(time);
}
void AnimRect::set(const RectF& in) {
x.set(in.x);
y.set(in.y);
z.set(in.z);
w.set(in.w);
}
RGBA AnimColor::get() const {
auto col = mColor.get();
return { col.x, col.y, col.z, col.w };
}
void AnimColor::set(const RGBA& col) { mColor.set(RectF(col.r, col.g, col.b, col.a)); }

View file

@ -19,17 +19,11 @@ namespace tp {
using namespace tp;
Graphics::Canvas::Canvas() {
mContext = new Context();
}
Graphics::Canvas::Canvas() { mContext = new Context(); }
Graphics::Canvas::~Canvas() {
delete mContext;
}
Graphics::Canvas::~Canvas() { delete mContext; }
void Graphics::Canvas::init() {
mContext->vg = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
}
void Graphics::Canvas::init() { mContext->vg = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES); }
void Graphics::Canvas::deinit() {
// Cleanup

View file

@ -17,13 +17,9 @@ namespace tp {
using namespace tp;
Graphics::GUI::GUI() {
mContext = new Context();
}
Graphics::GUI::GUI() { mContext = new Context(); }
Graphics::GUI::~GUI() {
delete mContext;
}
Graphics::GUI::~GUI() { delete mContext; }
void Graphics::GUI::init(Window* window) {
IMGUI_CHECKVERSION();

View file

@ -14,22 +14,18 @@ namespace tp {
GLuint vao{};
GLuint vbo{};
GLfloat vertices[9] = {
-0.0f, -0.0f, 0.0f, // Left vertex
1.0f, 0.0f, 0.0f, // Right vertex
0.5f, 1.0f, 0.0f // Top vertex
-0.0f, -0.0f, 0.0f, // Left vertex
1.0f, 0.0f, 0.0f, // Right vertex
0.5f, 1.0f, 0.0f // Top vertex
};
};
}
using namespace tp;
Graphics::GL::GL() {
mContext = new Context();
}
Graphics::GL::GL() { mContext = new Context(); }
Graphics::GL::~GL() {
delete mContext;
}
Graphics::GL::~GL() { delete mContext; }
void Graphics::GL::init() {
// Create a Vertex Array Object (VAO)
@ -51,13 +47,9 @@ void Graphics::GL::deinit() {
glDeleteVertexArrays(1, &mContext->vao);
}
void Graphics::GL::proc() {
glClear(GL_COLOR_BUFFER_BIT);
}
void Graphics::GL::proc() { glClear(GL_COLOR_BUFFER_BIT); }
void Graphics::GL::draw() {
glDrawArrays(GL_TRIANGLES, 0, 3);
}
void Graphics::GL::draw() { glDrawArrays(GL_TRIANGLES, 0, 3); }
void Graphics::init(Window* window) {
mGl.init();
@ -110,7 +102,6 @@ Window::~Window() {
delete mContext;
}
Window* Window::createWindow(int width, int height, const char* title) {
tp::HeapAllocGlobal::startIgnore();
@ -128,9 +119,7 @@ Window* Window::createWindow(int width, int height, const char* title) {
}
// Set the GLFW error callback
glfwSetErrorCallback([] (int error, const char* description) {
printf("GLFW Error: %i %s\n", error, description);
});
glfwSetErrorCallback([](int error, const char* description) { printf("GLFW Error: %i %s\n", error, description); });
auto out = new Window(width, height, title);
@ -143,9 +132,7 @@ void Window::destroyWindow(Window* window) {
glfwTerminate();
}
bool Window::shouldClose() const {
return glfwWindowShouldClose(mContext->window);
}
bool Window::shouldClose() const { return glfwWindowShouldClose(mContext->window); }
void Window::processEvents() {
glfwPollEvents();

View file

@ -10,6 +10,7 @@ namespace tp {
friend Graphics::GL;
friend Graphics::GUI;
friend Graphics::Canvas;
public:
GLFWwindow* window;
};