Blender V4.3
bonecolor.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "ANIM_bonecolor.hh"
10
11#include "BLI_hash.hh"
12
13#include "UI_resources.hh"
14
15#include <cstring>
16
17namespace blender::animrig {
18
19BoneColor::BoneColor()
20{
21 this->palette_index = 0;
22}
23BoneColor::BoneColor(const BoneColor &other)
24{
25 this->palette_index = other.palette_index;
26 std::memcpy(&this->custom, &other.custom, sizeof(this->custom));
27}
28BoneColor::~BoneColor() {}
29
30const ThemeWireColor *BoneColor::effective_color() const
31{
32 const int8_t color_index = this->palette_index;
33 if (color_index == 0) {
34 return nullptr;
35 }
36 if (color_index < 0) {
37 return &this->custom;
38 }
39
40 const bTheme *btheme = UI_GetTheme();
41 return &btheme->tarm[(color_index - 1)];
42}
43
44bool BoneColor::operator==(const BoneColor &other) const
45{
46 if (palette_index != other.palette_index) {
47 return false;
48 }
49 if (palette_index == -1) {
50 /* Explicitly compare each field, skipping the DNA padding fields. */
51 /* TODO: maybe there is already a DNA-level-comparison function for this? */
52
53 /* The last byte of the colors isn't used, but it's still in memory. The annoying thing is that
54 * values are inconsistently either 0 or 255 depending on how the color was set, and there is
55 * no way to influence this with the color picker in the GUI. So, just skip the last byte in
56 * the comparisons. */
57 return std::memcmp(custom.solid, other.custom.solid, sizeof(custom.solid) - 1) == 0 &&
58 std::memcmp(custom.select, other.custom.select, sizeof(custom.select) - 1) == 0 &&
59 std::memcmp(custom.active, other.custom.active, sizeof(custom.active) - 1) == 0 &&
60 custom.flag == other.custom.flag;
61 }
62 return true;
63}
64
65bool BoneColor::operator!=(const BoneColor &other) const
66{
67 return !(*this == other);
68}
69
70uint64_t BoneColor::hash() const
71{
72 if (palette_index >= 0) {
73 /* Theme colors are simple. */
75 }
76
77 /* For custom colors, hash everything together. */
78
79 /* The last byte of the color is skipped, as it is inconsistent (see note above). */
80 const uint64_t hash_solid = get_default_hash(custom.solid[0], custom.solid[1], custom.solid[2]);
81 const uint64_t hash_select = get_default_hash(
82 custom.select[0], custom.select[1], custom.select[2]);
83 const uint64_t hash_active = get_default_hash(
84 custom.active[0], custom.active[1], custom.active[2]);
85 return get_default_hash(hash_solid, hash_select, hash_active, custom.flag);
86}
87
89{
90 if (pose_bone->color.palette_index == 0) {
91 return pose_bone->bone->color.wrap();
92 }
93 return pose_bone->color.wrap();
94}
95
96}; // namespace blender::animrig
C++ part of the BoneColor DNA struct.
bTheme * UI_GetTheme()
const BoneColor & ANIM_bonecolor_posebone_get(const bPoseChannel *pose_bone)
Definition bonecolor.cc:88
uint64_t get_default_hash(const T &v)
Definition BLI_hash.hh:219
unsigned __int64 uint64_t
Definition stdint.h:90
signed char int8_t
Definition stdint.h:75
ThemeWireColor custom
BoneColor color
struct Bone * bone
ThemeWireColor tarm[20]