2016-10-31 00:21:24 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-01-24 11:37:19 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
|
2016-10-31 00:21:24 +00:00
|
|
|
#include "common.hpp"
|
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS
|
2016-10-31 00:21:24 +00:00
|
|
|
|
2020-11-27 19:35:31 +00:00
|
|
|
/**
|
|
|
|
* Represents immutable 32-bit color values.
|
|
|
|
*/
|
|
|
|
class rgba {
|
|
|
|
public:
|
2020-12-17 19:37:28 +00:00
|
|
|
enum class type { NONE = 0, ARGB, ALPHA_ONLY };
|
2017-01-19 04:38:42 +00:00
|
|
|
|
2019-10-27 21:06:25 +00:00
|
|
|
explicit rgba();
|
2020-12-17 19:37:28 +00:00
|
|
|
explicit rgba(uint32_t value, type type = type::ARGB);
|
2019-10-27 21:06:25 +00:00
|
|
|
explicit rgba(string hex);
|
|
|
|
|
|
|
|
operator string() const;
|
|
|
|
operator uint32_t() const;
|
|
|
|
bool operator==(const rgba& other) const;
|
|
|
|
|
2020-11-27 19:35:31 +00:00
|
|
|
uint32_t value() const;
|
2020-12-17 19:37:28 +00:00
|
|
|
type type() const;
|
2020-11-27 19:35:31 +00:00
|
|
|
|
2020-11-27 20:05:50 +00:00
|
|
|
double alpha_d() const;
|
|
|
|
double red_d() const;
|
|
|
|
double green_d() const;
|
|
|
|
double blue_d() const;
|
2019-10-27 21:06:25 +00:00
|
|
|
|
2020-11-27 20:05:50 +00:00
|
|
|
uint8_t alpha_i() const;
|
|
|
|
uint8_t red_i() const;
|
|
|
|
uint8_t green_i() const;
|
|
|
|
uint8_t blue_i() const;
|
2019-10-27 21:06:25 +00:00
|
|
|
|
|
|
|
bool has_color() const;
|
2020-12-01 13:49:41 +00:00
|
|
|
rgba apply_alpha_to(rgba other) const;
|
|
|
|
rgba try_apply_alpha_to(rgba other) const;
|
2020-11-27 19:35:31 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Color value in the form ARGB or A000 depending on the type
|
|
|
|
*
|
|
|
|
* Cannot be const because we have to assign to it in the constructor and initializer lists are not possible.
|
|
|
|
*/
|
|
|
|
uint32_t m_value;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NONE marks this instance as invalid. If such a color is encountered, it
|
|
|
|
* should be treated as if no color was set.
|
|
|
|
*
|
|
|
|
* ALPHA_ONLY is used for color strings that only have an alpha channel (#AA)
|
|
|
|
* these kinds should be combined with another color that has RGB channels
|
|
|
|
* before they are used to render anything.
|
|
|
|
*
|
|
|
|
* Cannot be const because we have to assign to it in the constructor and initializer lists are not possible.
|
|
|
|
*/
|
2020-12-17 19:37:28 +00:00
|
|
|
enum type m_type { type::NONE };
|
2017-01-19 04:38:42 +00:00
|
|
|
};
|
|
|
|
|
2019-10-27 21:06:25 +00:00
|
|
|
namespace color_util {
|
|
|
|
string simplify_hex(string hex);
|
|
|
|
} // namespace color_util
|
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS_END
|