ADD: Convert translation to ndc
This commit is contained in:
parent
1e266709c5
commit
47d18092ac
56
src/engine/core/gui/uiComponent/layout/LayoutStyle.h
Normal file
56
src/engine/core/gui/uiComponent/layout/LayoutStyle.h
Normal file
@ -0,0 +1,56 @@
|
||||
//
|
||||
// Created by sebastian on 12.02.26.
|
||||
//
|
||||
|
||||
#ifndef DICEWARS_SIEDLER_LAYOUTSTYLE_H
|
||||
#define DICEWARS_SIEDLER_LAYOUTSTYLE_H
|
||||
|
||||
enum class SizeUnit {
|
||||
Pixels,
|
||||
Percent
|
||||
};
|
||||
|
||||
struct SizeValue {
|
||||
float value;
|
||||
SizeUnit unit;
|
||||
};
|
||||
|
||||
struct Margin {
|
||||
SizeValue left;
|
||||
SizeValue right;
|
||||
SizeValue top;
|
||||
SizeValue bottom;
|
||||
};
|
||||
|
||||
enum class FlexDirection {
|
||||
Row,
|
||||
Column
|
||||
};
|
||||
|
||||
enum class JustifyContent {
|
||||
Start,
|
||||
Center,
|
||||
End,
|
||||
SpaceBetween,
|
||||
};
|
||||
|
||||
enum class AlignItems {
|
||||
Start,
|
||||
Center,
|
||||
End,
|
||||
Stretch
|
||||
};
|
||||
|
||||
struct LayoutStyle {
|
||||
SizeValue width = {1.0f, SizeUnit::Percent};
|
||||
SizeValue height = {1.0f, SizeUnit::Percent};
|
||||
|
||||
Margin margin;
|
||||
FlexDirection flexDirection = FlexDirection::Column;
|
||||
JustifyContent justifyContent = JustifyContent::Start;
|
||||
AlignItems alignItems = AlignItems::Start;
|
||||
|
||||
float flexGrow = 0.0f;
|
||||
};
|
||||
|
||||
#endif //DICEWARS_SIEDLER_LAYOUTSTYLE_H
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#ifndef MATHUTILS_H
|
||||
#define MATHUTILS_H
|
||||
#include "../core/Application.h"
|
||||
#include "../layer/entities/Camera.h"
|
||||
#include "glm/mat4x4.hpp"
|
||||
#include "glm/vec3.hpp"
|
||||
@ -24,8 +25,12 @@ namespace MathUtils {
|
||||
}
|
||||
|
||||
inline static glm::mat4 createTransformationMatrix(const glm::vec2 translation, const glm::vec2 scale) {
|
||||
glm::vec2 translationNDC;
|
||||
translationNDC.x = translation.x * 2.0f - 1.0f + scale.x;
|
||||
translationNDC.y = 1.0f - translation.y * 2.0f - scale.y;
|
||||
|
||||
auto matrix = glm::identity<glm::mat4>();
|
||||
matrix = glm::translate(matrix, glm::vec3( translation.x, translation.y, 0.0f));
|
||||
matrix = glm::translate(matrix, glm::vec3( translationNDC, 0.0f));
|
||||
matrix = glm::scale(matrix, glm::vec3(scale.x, scale.y, 1.0f));
|
||||
return matrix;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user