File: color.hpp

package info (click to toggle)
polybar 3.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,108 kB
  • sloc: cpp: 30,424; python: 3,750; sh: 284; makefile: 83
file content (70 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once

#include <cstdlib>
#include <cstdint>

#include "common.hpp"

POLYBAR_NS

/**
 * Represents immutable 32-bit color values.
 */
class rgba {
 public:
  enum class type { NONE = 0, ARGB, ALPHA_ONLY };

  explicit rgba();
  explicit rgba(uint32_t value, type type = type::ARGB);
  explicit rgba(string hex);

  operator string() const;
  operator uint32_t() const;
  operator bool() const;
  bool operator==(const rgba& other) const;
  bool operator!=(const rgba& other) const;

  uint32_t value() const;
  type get_type() const;

  double alpha_d() const;
  double red_d() const;
  double green_d() const;
  double blue_d() const;

  uint8_t alpha_i() const;
  uint8_t red_i() const;
  uint8_t green_i() const;
  uint8_t blue_i() const;

  bool has_color() const;
  bool is_transparent() const;
  rgba apply_alpha_to(rgba other) const;
  rgba try_apply_alpha_to(rgba other) const;

 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.
   */
  enum type m_type { type::NONE };
};

namespace color_util {
  string simplify_hex(string hex);
}  // namespace color_util

POLYBAR_NS_END