Advertisement
tEdDyXD

Color Class

Oct 5th, 2022 (edited)
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #pragma once
  2. #include <string>
  3.  
  4. namespace GTServer {
  5.     class Color {
  6.     public:
  7.         Color(const uint8_t& r, const uint8_t& g, const uint8_t& b, const uint8_t& a = 255) {
  8.             m_color[0] = b;
  9.             m_color[1] = g;
  10.             m_color[2] = r;
  11.             m_color[3] = a;
  12.         }
  13.         Color(const uint32_t& col) {
  14.             m_color[0] = (col >> 24) & 0xFF;
  15.             m_color[1] = (col >> 16) & 0xFF;
  16.             m_color[2] = (col >> 8) & 0xFF;
  17.             m_color[3] = (col) & 0xFF;
  18.         }
  19.         ~Color() = default;
  20.  
  21.         uint32_t GetInt() const {
  22.             uint32_t result = 0;
  23.             for (unsigned index = 0; index < sizeof(uint32_t); index++)
  24.                 result = (result << 8) + m_color[index];
  25.             return result;
  26.         }
  27.  
  28.         void SetRed(const uint8_t& col) { m_color[2] = col; }
  29.         [[nodiscard]] uint8_t GetRed() const { return m_color[2]; }
  30.         void SetGreen(const uint8_t& col) { m_color[1] = col; }
  31.         [[nodiscard]] uint8_t GetGreen() const { return m_color[1]; }
  32.         void SetBlue(const uint8_t& col) { m_color[0] = col; }
  33.         [[nodiscard]] uint8_t GetBlue() const { return m_color[0]; }
  34.         void SetAlpha(const uint8_t& col) { m_color[3] = col; }
  35.         [[nodiscard]] uint8_t GetAlpha() const { return m_color[3]; }
  36.        
  37.     private:
  38.         uint8_t m_color[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
  39.     };
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement