Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/fmt/xpm/ColorItem.h

raw
1 /*
2 * Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2026 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 18 янв. 2026 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_FMT_XPM_COLORITEM_H_
23 #define LSP_PLUG_IN_FMT_XPM_COLORITEM_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26
27 #include <lsp-plug.in/common/types.h>
28 #include <lsp-plug.in/runtime/Color.h>
29
30 namespace lsp
31 {
32 namespace xpm
33 {
34 /**
35 * XPM color item
36 */
37 class ColorItem
38 {
39 private:
40 enum state_t
41 {
42 STATE_UNSET = 1 << 0,
43 STATE_NAME = 1 << 1,
44 STATE_COLOR32 = 1 << 2,
45 STATE_COLOR64 = 1 << 3
46 };
47
48 private:
49 union
50 {
51 char *sName; // Name of color
52 uint32_t nColor32; // 32-bit color
53 uint64_t nColor64; // 64-bit color
54 };
55 state_t enState; // State
56
57 public:
58 ColorItem() noexcept;
59 ColorItem(const ColorItem & src);
60 ColorItem(ColorItem && src) noexcept;
61 explicit ColorItem(const char *name);
62 explicit ColorItem(uint32_t value) noexcept;
63 explicit ColorItem(uint64_t value) noexcept;
64 ~ColorItem();
65
66 ColorItem & operator = (const ColorItem & src);
67 ColorItem & operator = (ColorItem && src) noexcept;
68
69 public:
70 inline bool is_set() const noexcept { return enState != STATE_UNSET; }
71 inline bool is_wide() const noexcept { return enState == STATE_COLOR64; }
72 inline bool is_rgb48() const noexcept { return enState == STATE_COLOR64; }
73 inline bool is_regular() const noexcept { return enState == STATE_COLOR32; }
74 inline bool is_rgb24() const noexcept { return enState == STATE_COLOR32; }
75 inline bool is_name() const noexcept { return enState == STATE_NAME; }
76 inline bool is_color() const noexcept { return (enState == STATE_COLOR64) || (enState == STATE_COLOR32); }
77 inline bool is_rgb() const noexcept { return (enState == STATE_COLOR64) || (enState == STATE_COLOR32); }
78 inline bool has_name() const noexcept { return (enState == STATE_NAME) && (sName != NULL); }
79 bool has_name(const char *name) const noexcept;
80 inline bool is_none() const noexcept { return has_name("None"); }
81
82 inline const char *name() const noexcept { return (enState == STATE_NAME) ? sName : NULL; }
83 bool set_name(const char *alias);
84 bool set_name(const char *alias, size_t len);
85 void clear_name();
86
87 uint32_t rgb24() const noexcept;
88 uint64_t rgb48() const noexcept;
89 inline uint32_t regular() const noexcept { return rgb24(); }
90 inline uint32_t wide() const noexcept { return rgb48(); }
91 bool get(lsp::Color & color) const noexcept;
92 bool get(lsp::Color * color) const noexcept;
93
94 void set_rgb24(uint32_t v) noexcept;
95 void set_rgb48(uint64_t v) noexcept;
96 inline void set_regular(uint32_t v) noexcept { set_rgb24(v); }
97 inline void set_wide(uint64_t v) noexcept { set_rgb48(v); }
98 inline bool set_none() noexcept { return set_name("None"); }
99
100 bool set(const ColorItem & src);
101 void reset();
102
103 void swap(ColorItem & src) noexcept;
104 void swap(ColorItem * src) noexcept;
105
106 };
107
108 } /* namespace xpm */
109 } /* namespace lsp */
110
111
112
113 #endif /* LSP_PLUG_IN_FMT_XPM_COLORITEM_H_ */