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