|
|
|
|
#pragma region License
|
|
|
|
|
/*
|
|
|
|
|
License (OLC-3)
|
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Copyright 2018 - 2024 OneLoneCoder.com
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
1. Redistributions or derivations of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
|
|
2. Redistributions or derivative works in binary form must reproduce the above
|
|
|
|
|
copyright notice. This list of conditions and the following disclaimer must be
|
|
|
|
|
reproduced in the documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
3. Neither the name of the copyright holder nor the names of its contributors may
|
|
|
|
|
be used to endorse or promote products derived from this software without specific
|
|
|
|
|
prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
|
|
|
|
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
|
|
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
|
|
|
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
|
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
Portions of this software are copyright <EFBFBD> 2024 The FreeType
|
|
|
|
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Links
|
|
|
|
|
~~~~~
|
|
|
|
|
YouTube: https://www.youtube.com/javidx9
|
|
|
|
|
https://www.youtube.com/javidx9extra
|
|
|
|
|
Discord: https://discord.gg/WhwHUMV
|
|
|
|
|
Twitter: https://www.twitter.com/javidx9
|
|
|
|
|
Twitch: https://www.twitch.tv/javidx9
|
|
|
|
|
GitHub: https://www.github.com/onelonecoder
|
|
|
|
|
Homepage: https://www.onelonecoder.com
|
|
|
|
|
Patreon: https://www.patreon.com/javidx9
|
|
|
|
|
Community: https://community.onelonecoder.com
|
|
|
|
|
*/
|
|
|
|
|
#pragma endregion
|
|
|
|
|
#pragma once
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
|
|
// O------------------------------------------------------------------------------O
|
|
|
|
|
// | olc::Pixel IMPLEMENTATION |
|
|
|
|
|
// O------------------------------------------------------------------------------O
|
|
|
|
|
// O------------------------------------------------------------------------------O
|
|
|
|
|
// | olc::Pixel - Represents a 32-Bit RGBA colour |
|
|
|
|
|
// O------------------------------------------------------------------------------O
|
|
|
|
|
namespace olc{
|
|
|
|
|
constexpr inline uint8_t nDefaultAlpha = 0xFF;
|
|
|
|
|
constexpr inline uint32_t nDefaultPixel = (nDefaultAlpha << 24);
|
|
|
|
|
#if !defined(OLC_IGNORE_PIXEL)
|
|
|
|
|
struct Pixel
|
|
|
|
|
{
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
uint32_t n = nDefaultPixel;
|
|
|
|
|
struct { uint8_t r; uint8_t g; uint8_t b; uint8_t a; };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum Mode { NORMAL, MASK, ALPHA, CUSTOM };
|
|
|
|
|
|
|
|
|
|
Pixel();
|
|
|
|
|
Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = nDefaultAlpha);
|
|
|
|
|
//Hex Implicit Constructor!! ALPHA IS ASSUMED TO BE 255! If you need access to modifying the raw value, use PixelRaw()
|
|
|
|
|
Pixel(uint32_t hex);
|
|
|
|
|
Pixel& operator = (const Pixel& v) = default;
|
|
|
|
|
bool operator ==(const Pixel& p) const;
|
|
|
|
|
bool operator !=(const Pixel& p) const;
|
|
|
|
|
Pixel operator * (const float i) const;
|
|
|
|
|
Pixel operator / (const float i) const;
|
|
|
|
|
Pixel& operator *=(const float i);
|
|
|
|
|
Pixel& operator /=(const float i);
|
|
|
|
|
Pixel operator + (const Pixel& p) const;
|
|
|
|
|
Pixel operator - (const Pixel& p) const;
|
|
|
|
|
Pixel& operator +=(const Pixel& p);
|
|
|
|
|
Pixel& operator -=(const Pixel& p);
|
|
|
|
|
Pixel operator * (const Pixel& p) const;
|
|
|
|
|
Pixel& operator *=(const Pixel& p);
|
|
|
|
|
bool operator < (const Pixel& p)const;
|
|
|
|
|
Pixel inv() const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Pixel PixelF(float red, float green, float blue, float alpha = 1.0f);
|
|
|
|
|
Pixel PixelLerp(const olc::Pixel& p1, const olc::Pixel& p2, float t);
|
|
|
|
|
Pixel PixelRaw(uint32_t n);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// O------------------------------------------------------------------------------O
|
|
|
|
|
// | USEFUL CONSTANTS |
|
|
|
|
|
// O------------------------------------------------------------------------------O
|
|
|
|
|
static const Pixel
|
|
|
|
|
GREY(192, 192, 192), DARK_GREY(128, 128, 128), VERY_DARK_GREY(64, 64, 64),
|
|
|
|
|
RED(255, 0, 0), DARK_RED(128, 0, 0), VERY_DARK_RED(64, 0, 0),
|
|
|
|
|
YELLOW(255, 255, 0), DARK_YELLOW(128, 128, 0), VERY_DARK_YELLOW(64, 64, 0),
|
|
|
|
|
GREEN(0, 255, 0), DARK_GREEN(0, 128, 0), VERY_DARK_GREEN(0, 64, 0),
|
|
|
|
|
CYAN(0, 255, 255), DARK_CYAN(0, 128, 128), VERY_DARK_CYAN(0, 64, 64),
|
|
|
|
|
BLUE(0, 0, 255), DARK_BLUE(0, 0, 128), VERY_DARK_BLUE(0, 0, 64),
|
|
|
|
|
MAGENTA(255, 0, 255), DARK_MAGENTA(128, 0, 128), VERY_DARK_MAGENTA(64, 0, 64),
|
|
|
|
|
WHITE(255, 255, 255), BLACK(0, 0, 0), BLANK(0, 0, 0, 0);
|
|
|
|
|
#endif
|
|
|
|
|
}
|