code integration
This commit is contained in:
68
quokka_gfx/utils/Colors.cpp
Normal file
68
quokka_gfx/utils/Colors.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "Colors.h"
|
||||
|
||||
using namespace quokka_gfx;
|
||||
//--------------------------------------------------------------
|
||||
const Color Color::Black{ 0, 0, 0, 255 };
|
||||
const Color Color::White{ 255, 255, 255, 255 };
|
||||
const Color Color::Red{ 255, 0, 0, 255 };
|
||||
const Color Color::Green{ 0, 255, 0, 255 };
|
||||
const Color Color::Blue{ 0, 0, 255, 255 };
|
||||
const Color Color::Yellow{ 255, 255, 0, 255 };
|
||||
const Color Color::Magenta{ 255, 0, 255, 255 };
|
||||
const Color Color::Cyan{ 0, 255, 255, 255 };
|
||||
const Color Color::Transparent{ 0, 0, 0, 0 };
|
||||
//--------------------------------------------------------------
|
||||
/* Constructor */
|
||||
constexpr Color::Color(const uint8_t red, const uint8_t green, const uint8_t blue, const uint8_t alpha)
|
||||
: r(red)
|
||||
, g(green)
|
||||
, b(blue)
|
||||
, a(alpha)
|
||||
{
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
/* Constructor */
|
||||
constexpr Color::Color(const uint32_t hexColor)
|
||||
: r((hexColor >> 16) & 0xFF)
|
||||
, g((hexColor >> 8) & 0xFF)
|
||||
, b(hexColor & 0xFF)
|
||||
, a((hexColor >> 24) & 0xFF ? (hexColor >> 24) & 0xFF : 255)
|
||||
{
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
/* Convert Color to SDL_Color */
|
||||
constexpr Color::operator SDL_Color() const
|
||||
{
|
||||
return toSDL_Color();
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
/* Convert Color to SDL_FColor */
|
||||
constexpr Color::operator SDL_FColor() const
|
||||
{
|
||||
return toSDL_FColor();
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
/* Convert Color to hex representation */
|
||||
constexpr uint32_t Color::toHex() const
|
||||
{
|
||||
return (static_cast<uint32_t>(a) << 24) |
|
||||
(static_cast<uint32_t>(r) << 16) |
|
||||
(static_cast<uint32_t>(g) << 8) |
|
||||
static_cast<uint32_t>(b);
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
/* Convert Color to SDL_Color */
|
||||
constexpr SDL_Color Color::toSDL_Color() const
|
||||
{
|
||||
return SDL_Color{ r, g, b, a };
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
/* Convert Color to SDL_FColor */
|
||||
constexpr SDL_FColor Color::toSDL_FColor() const
|
||||
{
|
||||
return SDL_FColor{ static_cast<float>(r) / 255.0f,
|
||||
static_cast<float>(g) / 255.0f,
|
||||
static_cast<float>(b) / 255.0f,
|
||||
static_cast<float>(a) / 255.0f };
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
91
quokka_gfx/utils/Colors.h
Normal file
91
quokka_gfx/utils/Colors.h
Normal file
@@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <compare>
|
||||
|
||||
namespace quokka_gfx
|
||||
{
|
||||
//--------------------------------------------------------------
|
||||
struct Color
|
||||
{
|
||||
uint8_t r = 255;
|
||||
uint8_t g = 255;
|
||||
uint8_t b = 255;
|
||||
uint8_t a = 255;
|
||||
|
||||
constexpr Color() = default; // Default Constructor
|
||||
constexpr Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255); // Constructor
|
||||
explicit constexpr Color(uint32_t hexColor); // Constructor
|
||||
|
||||
[[nodiscard]] constexpr auto operator<=>(const Color &) const = default; // Three-way comparison operator
|
||||
[[nodiscard]] constexpr operator SDL_Color() const; // Convert Color to SDL_Color
|
||||
[[nodiscard]] constexpr operator SDL_FColor() const; // Convert Color to SDL_FColor
|
||||
|
||||
[[nodiscard]] constexpr uint32_t toHex() const; // Convert Color to hex representation
|
||||
[[nodiscard]] constexpr SDL_Color toSDL_Color() const; // Convert Color to SDL_Color
|
||||
[[nodiscard]] constexpr SDL_FColor toSDL_FColor() const; // Convert Color to SDL_FColor
|
||||
|
||||
// Predefined Colors
|
||||
static const Color Black;
|
||||
static const Color White;
|
||||
static const Color Red;
|
||||
static const Color Green;
|
||||
static const Color Blue;
|
||||
static const Color Yellow;
|
||||
static const Color Magenta;
|
||||
static const Color Cyan;
|
||||
static const Color Transparent;
|
||||
};
|
||||
//--------------------------------------------------------------
|
||||
///* Constructor */
|
||||
// inline constexpr Color::Color(const uint8_t red, const uint8_t green, const uint8_t blue, const uint8_t alpha)
|
||||
// : r(red)
|
||||
// , g(green)
|
||||
// , b(blue)
|
||||
// , a(alpha)
|
||||
//{
|
||||
// }
|
||||
////--------------------------------------------------------------
|
||||
///* Constructor */
|
||||
// inline constexpr Color::Color(const uint32_t hexColor)
|
||||
// : r((hexColor >> 16) & 0xFF)
|
||||
// , g((hexColor >> 8) & 0xFF)
|
||||
// , b(hexColor & 0xFF)
|
||||
// , a((hexColor >> 24) & 0xFF ? (hexColor >> 24) & 0xFF : 255)
|
||||
//{
|
||||
// }
|
||||
////--------------------------------------------------------------
|
||||
///* Convert Color to SDL_Color */
|
||||
// inline constexpr Color::operator SDL_Color() const
|
||||
//{
|
||||
// return toSDL_Color();
|
||||
// }
|
||||
////--------------------------------------------------------------
|
||||
///* Convert Color to SDL_FColor */
|
||||
// inline constexpr Color::operator SDL_FColor() const
|
||||
//{
|
||||
// return toSDL_FColor();
|
||||
// }
|
||||
////--------------------------------------------------------------
|
||||
///* Convert Color to hex representation */
|
||||
// inline constexpr uint32_t Color::toHex() const
|
||||
//{
|
||||
// return (static_cast<uint32_t>(a) << 24) |
|
||||
// (static_cast<uint32_t>(r) << 16) |
|
||||
// (static_cast<uint32_t>(g) << 8) |
|
||||
// static_cast<uint32_t>(b);
|
||||
// }
|
||||
////--------------------------------------------------------------
|
||||
///* Convert Color to SDL_Color */
|
||||
// inline constexpr SDL_Color Color::toSDL_Color() const
|
||||
//{
|
||||
// return SDL_Color{ r, g, b, a };
|
||||
// }
|
||||
////--------------------------------------------------------------
|
||||
///* Convert Color to SDL_FColor */
|
||||
// inline constexpr SDL_FColor Color::toSDL_FColor() const
|
||||
//{
|
||||
// return SDL_FColor{ r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f };
|
||||
// }
|
||||
//--------------------------------------------------------------
|
||||
} // namespace quokka_gfx
|
||||
32
quokka_gfx/utils/Coords.h
Normal file
32
quokka_gfx/utils/Coords.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
namespace quokka_gfx
|
||||
{
|
||||
//--------------------------------------------------------------
|
||||
struct Size
|
||||
{
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
};
|
||||
//--------------------------------------------------------------
|
||||
struct FSize
|
||||
{
|
||||
float w = 0.0f;
|
||||
float h = 0.0f;
|
||||
};
|
||||
//--------------------------------------------------------------
|
||||
struct Pos
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
};
|
||||
//--------------------------------------------------------------
|
||||
struct FPos
|
||||
{
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
};
|
||||
//--------------------------------------------------------------
|
||||
} // namespace quokka_gfx
|
||||
Reference in New Issue
Block a user