mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
chore: add clang-format and pre-commit configuration
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
#include <Cubed/tools/cubed_assert.hpp>
|
||||
#include "Cubed/tools/cubed_assert.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
enum class Color {
|
||||
BLACK,
|
||||
WHITE,
|
||||
@@ -25,37 +25,36 @@ inline constexpr glm::vec4 color_value(Color color) {
|
||||
using glm::vec4;
|
||||
|
||||
switch (color) {
|
||||
case Color::BLACK:
|
||||
return vec4{0.0f, 0.0f, 0.0f, 1.0f};
|
||||
case Color::WHITE:
|
||||
return vec4{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
case Color::RED:
|
||||
return vec4{1.0f, 0.0f, 0.0f, 1.0f};
|
||||
case Color::GREEN:
|
||||
return vec4{0.0f, 1.0f, 0.0f, 1.0f};
|
||||
case Color::BLUE:
|
||||
return vec4{0.0f, 0.0f, 1.0f, 1.0f};
|
||||
case Color::YELLOW:
|
||||
return vec4{1.0f, 1.0f, 0.0f, 1.0f};
|
||||
case Color::CYAN:
|
||||
return vec4{0.0f, 1.0f, 1.0f, 1.0f};
|
||||
case Color::MAGENTA:
|
||||
return vec4{1.0f, 0.0f, 1.0f, 1.0f};
|
||||
case Color::GRAY:
|
||||
return vec4{0.5f, 0.5f, 0.5f, 1.0f};
|
||||
case Color::ORANGE:
|
||||
return vec4{1.0f, 0.647f, 0.0f, 1.0f};
|
||||
case Color::PURPLE:
|
||||
return vec4{0.502f, 0.0f, 0.502f, 1.0f};
|
||||
case Color::PINK:
|
||||
return vec4{1.0f, 0.753f, 0.769f, 1.0f};
|
||||
case Color::BROWN:
|
||||
return vec4{0.647f, 0.165f, 0.165f, 1.0f};
|
||||
default:
|
||||
ASSERT_MSG(false, "Unknown Color");
|
||||
return vec4{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
case Color::BLACK:
|
||||
return vec4{0.0f, 0.0f, 0.0f, 1.0f};
|
||||
case Color::WHITE:
|
||||
return vec4{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
case Color::RED:
|
||||
return vec4{1.0f, 0.0f, 0.0f, 1.0f};
|
||||
case Color::GREEN:
|
||||
return vec4{0.0f, 1.0f, 0.0f, 1.0f};
|
||||
case Color::BLUE:
|
||||
return vec4{0.0f, 0.0f, 1.0f, 1.0f};
|
||||
case Color::YELLOW:
|
||||
return vec4{1.0f, 1.0f, 0.0f, 1.0f};
|
||||
case Color::CYAN:
|
||||
return vec4{0.0f, 1.0f, 1.0f, 1.0f};
|
||||
case Color::MAGENTA:
|
||||
return vec4{1.0f, 0.0f, 1.0f, 1.0f};
|
||||
case Color::GRAY:
|
||||
return vec4{0.5f, 0.5f, 0.5f, 1.0f};
|
||||
case Color::ORANGE:
|
||||
return vec4{1.0f, 0.647f, 0.0f, 1.0f};
|
||||
case Color::PURPLE:
|
||||
return vec4{0.502f, 0.0f, 0.502f, 1.0f};
|
||||
case Color::PINK:
|
||||
return vec4{1.0f, 0.753f, 0.769f, 1.0f};
|
||||
case Color::BROWN:
|
||||
return vec4{0.647f, 0.165f, 0.165f, 1.0f};
|
||||
default:
|
||||
ASSERT_MSG(false, "Unknown Color");
|
||||
return vec4{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline glm::vec4 rgb255_to_float(int r, int g, int b, int a) {
|
||||
@@ -67,4 +66,4 @@ inline glm::vec4 rgb255_to_float(int r, int g, int b, int a) {
|
||||
return glm::vec4{nr, ng, nb, na};
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
@@ -1,32 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cubed/primitive_data.hpp"
|
||||
#include "Cubed/ui/color.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <string>
|
||||
|
||||
#include <Cubed/config.hpp>
|
||||
#include <Cubed/primitive_data.hpp>
|
||||
#include <Cubed/ui/color.hpp>
|
||||
namespace Cubed {
|
||||
|
||||
|
||||
class Shader;
|
||||
|
||||
class Text {
|
||||
public:
|
||||
explicit Text(std::string_view name);
|
||||
Text(std::string_view name, std::string_view str, glm::vec2 pos = glm::vec2{0.0f, 0.0f}, Color color = Color::BLACK);
|
||||
Text(std::string_view name, std::string_view str,
|
||||
glm::vec2 pos = glm::vec2{0.0f, 0.0f}, Color color = Color::BLACK);
|
||||
~Text();
|
||||
Text(const Text&) = delete;
|
||||
Text(Text&&) noexcept;
|
||||
Text& operator=(const Text&) = delete;
|
||||
Text& operator=(Text&&) noexcept = delete;
|
||||
Text& color(Color color);
|
||||
//Text& color(const glm::vec4& color, int pos);
|
||||
// Text& color(const glm::vec4& color, int pos);
|
||||
Text& position(float x, float y);
|
||||
Text& scale(float s);
|
||||
Text& text(std::string_view str);
|
||||
|
||||
|
||||
std::size_t uuid() const;
|
||||
static void set_loc(const Shader& shader);
|
||||
void render();
|
||||
@@ -42,7 +41,7 @@ private:
|
||||
std::string m_text;
|
||||
glm::vec4 m_color{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
glm::mat4 m_model_matrix;
|
||||
|
||||
|
||||
std::vector<Vertex2D> m_vertices;
|
||||
GLuint m_vbo = 0;
|
||||
static inline GLuint m_color_loc = 0;
|
||||
@@ -50,7 +49,6 @@ private:
|
||||
|
||||
void update_vertices();
|
||||
void upload_to_gpu();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user