Blender
V5.0
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 "
DNA_action_types.h
"
14
15
#include "
UI_resources.hh
"
16
17
#include <cstring>
18
19
namespace
blender::animrig
{
20
21
BoneColor::BoneColor()
22
{
23
this->
palette_index
= 0;
24
}
25
BoneColor::BoneColor(
const
BoneColor
&other)
26
{
27
this->
palette_index
= other.
palette_index
;
28
std::memcpy(&this->
custom
, &other.
custom
,
sizeof
(this->custom));
29
}
30
BoneColor::~BoneColor() =
default
;
31
32
const
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
46
bool
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
67
bool
BoneColor::operator!=(
const
BoneColor
&other)
const
68
{
69
return
!(*
this
== other);
70
}
71
72
uint64_t
BoneColor::hash()
const
73
{
74
if
(
palette_index
>= 0) {
75
/* Theme colors are simple. */
76
return
get_default_hash
(
palette_index
);
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
90
const
BoneColor
&
ANIM_bonecolor_posebone_get
(
const
bPoseChannel
*pose_bone)
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
ANIM_bonecolor.hh
C++ part of the BoneColor DNA struct.
BLI_hash.hh
DNA_action_types.h
UI_resources.hh
UI_GetTheme
bTheme * UI_GetTheme()
Definition
resources.cc:1147
uint64_t
unsigned long long int uint64_t
Definition
btConvexHullComputer.cpp:33
blender::animrig::BoneColor
Definition
ANIM_bonecolor.hh:25
blender::animrig::BoneColor::BoneColor
BoneColor()
Definition
bonecolor.cc:21
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:90
blender::get_default_hash
uint64_t get_default_hash(const T &v, const Args &...args)
Definition
BLI_hash.hh:233
BoneColor::custom
ThemeWireColor custom
Definition
DNA_armature_types.h:55
BoneColor::palette_index
int8_t palette_index
Definition
DNA_armature_types.h:53
Bone::color
BoneColor color
Definition
DNA_armature_types.h:97
ThemeWireColor
Definition
DNA_theme_types.h:471
ThemeWireColor::select
unsigned char select[4]
Definition
DNA_theme_types.h:473
ThemeWireColor::solid
unsigned char solid[4]
Definition
DNA_theme_types.h:472
ThemeWireColor::active
unsigned char active[4]
Definition
DNA_theme_types.h:474
ThemeWireColor::flag
short flag
Definition
DNA_theme_types.h:477
bPoseChannel
Definition
DNA_action_types.h:299
bPoseChannel::bone
struct Bone * bone
Definition
DNA_action_types.h:341
bPoseChannel::color
BoneColor color
Definition
DNA_action_types.h:452
bTheme
Definition
DNA_theme_types.h:501
bTheme::tarm
ThemeWireColor tarm[20]
Definition
DNA_theme_types.h:544
Generated on
for Blender by
doxygen
1.16.1