Blender
V4.3
source
blender
animrig
intern
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 "
UI_resources.hh
"
14
15
#include <cstring>
16
17
namespace
blender::animrig
{
18
19
BoneColor::BoneColor()
20
{
21
this->
palette_index
= 0;
22
}
23
BoneColor::BoneColor(
const
BoneColor
&other)
24
{
25
this->
palette_index
= other.
palette_index
;
26
std::memcpy(&this->
custom
, &other.
custom
,
sizeof
(this->custom));
27
}
28
BoneColor::~BoneColor() {}
29
30
const
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
44
bool
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
65
bool
BoneColor::operator!=(
const
BoneColor
&other)
const
66
{
67
return
!(*
this
== other);
68
}
69
70
uint64_t
BoneColor::hash()
const
71
{
72
if
(
palette_index
>= 0) {
73
/* Theme colors are simple. */
74
return
get_default_hash
(
palette_index
);
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
88
const
BoneColor
&
ANIM_bonecolor_posebone_get
(
const
bPoseChannel
*pose_bone)
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
ANIM_bonecolor.hh
C++ part of the BoneColor DNA struct.
BLI_hash.hh
UI_resources.hh
UI_GetTheme
bTheme * UI_GetTheme()
Definition
resources.cc:1129
blender::animrig::BoneColor
Definition
ANIM_bonecolor.hh:25
blender::animrig::BoneColor::BoneColor
BoneColor()
Definition
bonecolor.cc:19
blender::animrig
Definition
ANIM_action.hh:36
blender::animrig::ANIM_bonecolor_posebone_get
const BoneColor & ANIM_bonecolor_posebone_get(const bPoseChannel *pose_bone)
Definition
bonecolor.cc:88
blender::get_default_hash
uint64_t get_default_hash(const T &v)
Definition
BLI_hash.hh:219
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:90
int8_t
signed char int8_t
Definition
stdint.h:75
BoneColor::custom
ThemeWireColor custom
Definition
DNA_armature_types.h:47
BoneColor::palette_index
int8_t palette_index
Definition
DNA_armature_types.h:45
Bone::color
BoneColor color
Definition
DNA_armature_types.h:82
ThemeWireColor
Definition
DNA_userdef_types.h:464
ThemeWireColor::select
unsigned char select[4]
Definition
DNA_userdef_types.h:466
ThemeWireColor::solid
unsigned char solid[4]
Definition
DNA_userdef_types.h:465
ThemeWireColor::active
unsigned char active[4]
Definition
DNA_userdef_types.h:467
ThemeWireColor::flag
short flag
Definition
DNA_userdef_types.h:470
bPoseChannel
Definition
DNA_action_types.h:282
bPoseChannel::bone
struct Bone * bone
Definition
DNA_action_types.h:312
bPoseChannel::color
BoneColor color
Definition
DNA_action_types.h:423
bTheme
Definition
DNA_userdef_types.h:494
bTheme::tarm
ThemeWireColor tarm[20]
Definition
DNA_userdef_types.h:537
Generated on Sat Oct 4 2025 05:32:23 for Blender by
doxygen
1.14.0