Cleanup: Move five interface files to C++

Builds on all four platforms on the buildbot. Includes clang tidy fixes.
This commit is contained in:
Hans Goudey 2022-07-29 23:16:58 -05:00
parent e6b1e97dd7
commit 599a7ddf17
10 changed files with 381 additions and 377 deletions

View File

@ -456,12 +456,12 @@ WorkSpaceLayout *BKE_workspace_layout_iter_circular(const WorkSpace *workspace,
WorkSpaceLayout *iter_layout;
if (iter_backward) {
LISTBASE_CIRCULAR_BACKWARD_BEGIN (&workspace->layouts, iter_layout, start) {
LISTBASE_CIRCULAR_BACKWARD_BEGIN (WorkSpaceLayout *, &workspace->layouts, iter_layout, start) {
if (!callback(iter_layout, arg)) {
return iter_layout;
}
}
LISTBASE_CIRCULAR_BACKWARD_END(&workspace->layouts, iter_layout, start);
LISTBASE_CIRCULAR_BACKWARD_END(WorkSpaceLayout *, &workspace->layouts, iter_layout, start);
}
else {
LISTBASE_CIRCULAR_FORWARD_BEGIN (&workspace->layouts, iter_layout, start) {

View File

@ -320,13 +320,13 @@ struct LinkData *BLI_genericNodeN(void *data);
} \
((void)0)
#define LISTBASE_CIRCULAR_BACKWARD_BEGIN(lb, lb_iter, lb_init) \
if ((lb)->last && (lb_init || (lb_init = (lb)->last))) { \
#define LISTBASE_CIRCULAR_BACKWARD_BEGIN(type, lb, lb_iter, lb_init) \
if ((lb)->last && (lb_init || (lb_init = (type)(lb)->last))) { \
lb_iter = lb_init; \
do {
#define LISTBASE_CIRCULAR_BACKWARD_END(lb, lb_iter, lb_init) \
#define LISTBASE_CIRCULAR_BACKWARD_END(type, lb, lb_iter, lb_init) \
} \
while ((lb_iter = (lb_iter)->prev ? (lb_iter)->prev : (lb)->last), (lb_iter != lb_init)) \
while ((lb_iter = (lb_iter)->prev ? (lb_iter)->prev : (type)(lb)->last), (lb_iter != lb_init)) \
; \
} \
((void)0)

View File

@ -36,7 +36,7 @@ set(SRC
eyedroppers/eyedropper_gpencil_color.c
interface.cc
interface_align.c
interface_anim.c
interface_anim.cc
interface_button_group.c
interface_context_menu.c
interface_context_path.cc
@ -47,8 +47,8 @@ set(SRC
interface_icons.c
interface_icons_event.c
interface_layout.c
interface_ops.c
interface_panel.c
interface_ops.cc
interface_panel.cc
interface_query.cc
interface_region_color_picker.cc
interface_region_hud.cc
@ -64,9 +64,9 @@ set(SRC
interface_template_attribute_search.cc
interface_template_list.cc
interface_template_search_menu.cc
interface_template_search_operator.c
interface_template_search_operator.cc
interface_templates.c
interface_undo.c
interface_undo.cc
interface_utils.cc
interface_widgets.c
resources.c

View File

@ -4,9 +4,9 @@
* \ingroup edinterface
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "MEM_guardedalloc.h"
@ -49,8 +49,14 @@ static FCurve *ui_but_get_fcurve(
* but works well enough in typical cases */
const int rnaindex = (but->rnaindex == -1) ? 0 : but->rnaindex;
return BKE_fcurve_find_by_rna_context_ui(
but->block->evil_C, &but->rnapoin, but->rnaprop, rnaindex, adt, action, r_driven, r_special);
return BKE_fcurve_find_by_rna_context_ui(static_cast<bContext *>(but->block->evil_C),
&but->rnapoin,
but->rnaprop,
rnaindex,
adt,
action,
r_driven,
r_special);
}
void ui_but_anim_flag(uiBut *but, const AnimationEvalContext *anim_eval_context)
@ -93,7 +99,7 @@ void ui_but_anim_flag(uiBut *but, const AnimationEvalContext *anim_eval_context)
}
/* XXX: this feature is totally broken and useless with NLA */
if (adt == NULL || adt->nla_tracks.first == NULL) {
if (adt == nullptr || adt->nla_tracks.first == nullptr) {
const AnimationEvalContext remapped_context = BKE_animsys_eval_context_construct_at(
anim_eval_context, cfra);
if (fcurve_is_changed(but->rnapoin, but->rnaprop, fcu, &remapped_context)) {
@ -109,13 +115,13 @@ void ui_but_anim_flag(uiBut *but, const AnimationEvalContext *anim_eval_context)
static uiBut *ui_but_anim_decorate_find_attached_button(uiButDecorator *but_decorate)
{
uiBut *but_iter = NULL;
uiBut *but_iter = nullptr;
BLI_assert(UI_but_is_decorator(&but_decorate->but));
BLI_assert(but_decorate->rnapoin.data && but_decorate->rnaprop);
LISTBASE_CIRCULAR_BACKWARD_BEGIN (
&but_decorate->but.block->buttons, but_iter, but_decorate->but.prev) {
uiBut *, &but_decorate->but.block->buttons, but_iter, but_decorate->but.prev) {
if (but_iter != (uiBut *)but_decorate &&
ui_but_rna_equals_ex(
but_iter, &but_decorate->rnapoin, but_decorate->rnaprop, but_decorate->rnaindex)) {
@ -123,9 +129,9 @@ static uiBut *ui_but_anim_decorate_find_attached_button(uiButDecorator *but_deco
}
}
LISTBASE_CIRCULAR_BACKWARD_END(
&but_decorate->but.block->buttons, but_iter, but_decorate->but.prev);
uiBut *, &but_decorate->but.block->buttons, but_iter, but_decorate->but.prev);
return NULL;
return nullptr;
}
void ui_but_anim_decorate_update_from_flag(uiButDecorator *decorator_but)
@ -173,7 +179,7 @@ bool ui_but_anim_expression_get(uiBut *but, char *str, size_t maxlen)
ChannelDriver *driver;
bool driven, special;
fcu = ui_but_get_fcurve(but, NULL, NULL, &driven, &special);
fcu = ui_but_get_fcurve(but, nullptr, nullptr, &driven, &special);
if (fcu && driven) {
driver = fcu->driver;
@ -195,13 +201,13 @@ bool ui_but_anim_expression_set(uiBut *but, const char *str)
ChannelDriver *driver;
bool driven, special;
fcu = ui_but_get_fcurve(but, NULL, NULL, &driven, &special);
fcu = ui_but_get_fcurve(but, nullptr, nullptr, &driven, &special);
if (fcu && driven) {
driver = fcu->driver;
if (driver && (driver->type == DRIVER_TYPE_PYTHON)) {
bContext *C = but->block->evil_C;
bContext *C = static_cast<bContext *>(but->block->evil_C);
BLI_strncpy_utf8(driver->expression, str, sizeof(driver->expression));
@ -213,7 +219,7 @@ bool ui_but_anim_expression_set(uiBut *but, const char *str)
fcu->flag &= ~FCURVE_DISABLED;
/* this notifier should update the Graph Editor and trigger depsgraph refresh? */
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME, nullptr);
DEG_relations_tag_update(CTX_data_main(C));
@ -226,14 +232,14 @@ bool ui_but_anim_expression_set(uiBut *but, const char *str)
bool ui_but_anim_expression_create(uiBut *but, const char *str)
{
bContext *C = but->block->evil_C;
bContext *C = static_cast<bContext *>(but->block->evil_C);
ID *id;
FCurve *fcu;
char *path;
bool ok = false;
/* button must have RNA-pointer to a numeric-capable property */
if (ELEM(NULL, but->rnapoin.data, but->rnaprop)) {
if (ELEM(nullptr, but->rnapoin.data, but->rnaprop)) {
if (G.debug & G_DEBUG) {
printf("ERROR: create expression failed - button has no RNA info attached\n");
}
@ -253,7 +259,7 @@ bool ui_but_anim_expression_create(uiBut *but, const char *str)
/* FIXME: until materials can be handled by depsgraph,
* don't allow drivers to be created for them */
id = but->rnapoin.owner_id;
if ((id == NULL) || (GS(id->name) == ID_MA) || (GS(id->name) == ID_TE)) {
if ((id == nullptr) || (GS(id->name) == ID_MA) || (GS(id->name) == ID_TE)) {
if (G.debug & G_DEBUG) {
printf("ERROR: create expression failed - invalid data-block for adding drivers (%p)\n", id);
}
@ -262,7 +268,7 @@ bool ui_but_anim_expression_create(uiBut *but, const char *str)
/* get path */
path = RNA_path_from_ID_to_property(&but->rnapoin, but->rnaprop);
if (path == NULL) {
if (path == nullptr) {
return false;
}
@ -282,7 +288,7 @@ bool ui_but_anim_expression_create(uiBut *but, const char *str)
/* updates */
BKE_driver_invalidate_expression(driver, true, false);
DEG_relations_tag_update(CTX_data_main(C));
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME, nullptr);
ok = true;
}
}
@ -300,19 +306,19 @@ void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
void ui_but_anim_copy_driver(bContext *C)
{
/* this operator calls UI_context_active_but_prop_get */
WM_operator_name_call(C, "ANIM_OT_copy_driver_button", WM_OP_INVOKE_DEFAULT, NULL, NULL);
WM_operator_name_call(C, "ANIM_OT_copy_driver_button", WM_OP_INVOKE_DEFAULT, nullptr, nullptr);
}
void ui_but_anim_paste_driver(bContext *C)
{
/* this operator calls UI_context_active_but_prop_get */
WM_operator_name_call(C, "ANIM_OT_paste_driver_button", WM_OP_INVOKE_DEFAULT, NULL, NULL);
WM_operator_name_call(C, "ANIM_OT_paste_driver_button", WM_OP_INVOKE_DEFAULT, nullptr, nullptr);
}
void ui_but_anim_decorate_cb(bContext *C, void *arg_but, void *UNUSED(arg_dummy))
{
wmWindowManager *wm = CTX_wm_manager(C);
uiButDecorator *but_decorate = arg_but;
uiButDecorator *but_decorate = static_cast<uiButDecorator *>(arg_but);
uiBut *but_anim = ui_but_anim_decorate_find_attached_button(but_decorate);
if (!but_anim) {
@ -332,7 +338,7 @@ void ui_but_anim_decorate_cb(bContext *C, void *arg_but, void *UNUSED(arg_dummy)
wmOperatorType *ot = WM_operatortype_find("ANIM_OT_keyframe_delete_button", false);
WM_operator_properties_create_ptr(&props_ptr, ot);
RNA_boolean_set(&props_ptr, "all", but_anim->rnaindex == -1);
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr, NULL);
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr, nullptr);
WM_operator_properties_free(&props_ptr);
}
else {
@ -340,7 +346,7 @@ void ui_but_anim_decorate_cb(bContext *C, void *arg_but, void *UNUSED(arg_dummy)
wmOperatorType *ot = WM_operatortype_find("ANIM_OT_keyframe_insert_button", false);
WM_operator_properties_create_ptr(&props_ptr, ot);
RNA_boolean_set(&props_ptr, "all", but_anim->rnaindex == -1);
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr, NULL);
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr, nullptr);
WM_operator_properties_free(&props_ptr);
}

View File

@ -468,6 +468,7 @@ typedef enum uiButtonGroupFlag {
/** The buttons in this group are inside a panel header. */
UI_BUTTON_GROUP_PANEL_HEADER = (1 << 1),
} uiButtonGroupFlag;
ENUM_OPERATORS(uiButtonGroupFlag, UI_BUTTON_GROUP_PANEL_HEADER);
struct uiBlock {
uiBlock *next, *prev;

View File

@ -5,7 +5,7 @@
* \ingroup edinterface
*/
#include <string.h>
#include <cstring>
#include "MEM_guardedalloc.h"
@ -128,7 +128,7 @@ static int copy_data_path_button_exec(bContext *C, wmOperator *op)
/* try to create driver using property retrieved from UI */
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
if (ptr.owner_id != NULL) {
if (ptr.owner_id != nullptr) {
if (full_path) {
if (prop) {
path = RNA_path_full_property_py_ex(bmain, &ptr, prop, index, true);
@ -217,7 +217,7 @@ static int copy_as_driver_button_exec(bContext *C, wmOperator *op)
if (ptr.owner_id && ptr.data && prop) {
ID *id;
const int dim = RNA_property_array_dimension(&ptr, prop, NULL);
const int dim = RNA_property_array_dimension(&ptr, prop, nullptr);
char *path = RNA_path_from_real_ID_to_property_index(bmain, &ptr, prop, dim, index, &id);
if (path) {
@ -261,25 +261,25 @@ static bool copy_python_command_button_poll(bContext *C)
{
uiBut *but = UI_context_active_but_get(C);
if (but && (but->optype != NULL)) {
return 1;
if (but && (but->optype != nullptr)) {
return true;
}
return 0;
return false;
}
static int copy_python_command_button_exec(bContext *C, wmOperator *UNUSED(op))
{
uiBut *but = UI_context_active_but_get(C);
if (but && (but->optype != NULL)) {
if (but && (but->optype != nullptr)) {
PointerRNA *opptr;
char *str;
opptr = UI_but_operator_ptr_get(but); /* allocated when needed, the button owns it */
str = WM_operator_pystring_ex(C, NULL, false, true, but->optype, opptr);
str = WM_operator_pystring_ex(C, nullptr, false, true, but->optype, opptr);
WM_clipboard_text_set(str, 0);
WM_clipboard_text_set(str, false);
MEM_freeN(str);
@ -391,7 +391,8 @@ static void UI_OT_reset_default_button(wmOperatorType *ot)
ot->flag = 0;
/* properties */
RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array");
RNA_def_boolean(
ot->srna, "all", true, "All", "Reset to default values all elements of the array");
}
/** \} */
@ -530,7 +531,7 @@ static EnumPropertyItem override_type_items[] = {
0,
"Factor",
"Store factor to linked data value (useful e.g. for scale)"},
{0, NULL, 0, NULL, NULL},
{0, nullptr, 0, nullptr, nullptr},
};
static bool override_type_set_button_poll(bContext *C)
@ -581,16 +582,16 @@ static int override_type_set_button_exec(bContext *C, wmOperator *op)
/* try to reset the nominated setting to its default value */
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
BLI_assert(ptr.owner_id != NULL);
BLI_assert(ptr.owner_id != nullptr);
if (all) {
index = -1;
}
IDOverrideLibraryPropertyOperation *opop = RNA_property_override_property_operation_get(
CTX_data_main(C), &ptr, prop, operation, index, true, NULL, &created);
CTX_data_main(C), &ptr, prop, operation, index, true, nullptr, &created);
if (opop == NULL) {
if (opop == nullptr) {
/* Sometimes e.g. RNA cannot generate a path to the given property. */
BKE_reportf(op->reports, RPT_WARNING, "Failed to create the override operation");
return OPERATOR_CANCELLED;
@ -601,7 +602,7 @@ static int override_type_set_button_exec(bContext *C, wmOperator *op)
}
/* Outliner e.g. has to be aware of this change. */
WM_main_add_notifier(NC_WM | ND_LIB_OVERRIDE_CHANGED, NULL);
WM_main_add_notifier(NC_WM | ND_LIB_OVERRIDE_CHANGED, nullptr);
return operator_button_property_finish(C, &ptr, prop);
}
@ -634,7 +635,8 @@ static void UI_OT_override_type_set_button(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
/* properties */
RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array");
RNA_def_boolean(
ot->srna, "all", true, "All", "Reset to default values all elements of the array");
ot->prop = RNA_def_enum(ot->srna,
"type",
override_type_items,
@ -671,8 +673,8 @@ static int override_remove_button_exec(bContext *C, wmOperator *op)
ID *id = ptr.owner_id;
IDOverrideLibraryProperty *oprop = RNA_property_override_property_find(bmain, &ptr, prop, &id);
BLI_assert(oprop != NULL);
BLI_assert(id != NULL && id->override_library != NULL);
BLI_assert(oprop != nullptr);
BLI_assert(id != nullptr && id->override_library != nullptr);
const bool is_template = ID_IS_OVERRIDE_LIBRARY_TEMPLATE(id);
@ -691,8 +693,8 @@ static int override_remove_button_exec(bContext *C, wmOperator *op)
/* Remove override operation for given item,
* add singular operations for the other items as needed. */
IDOverrideLibraryPropertyOperation *opop = BKE_lib_override_library_property_operation_find(
oprop, NULL, NULL, index, index, false, &is_strict_find);
BLI_assert(opop != NULL);
oprop, nullptr, nullptr, index, index, false, &is_strict_find);
BLI_assert(opop != nullptr);
if (!is_strict_find) {
/* No specific override operation, we have to get generic one,
* and create item-specific override operations for all but given index,
@ -700,7 +702,7 @@ static int override_remove_button_exec(bContext *C, wmOperator *op)
for (int idx = RNA_property_array_length(&ptr, prop); idx--;) {
if (idx != index) {
BKE_lib_override_library_property_operation_get(
oprop, opop->operation, NULL, NULL, idx, idx, true, NULL, NULL);
oprop, opop->operation, nullptr, nullptr, idx, idx, true, nullptr, nullptr);
}
}
}
@ -721,7 +723,7 @@ static int override_remove_button_exec(bContext *C, wmOperator *op)
}
/* Outliner e.g. has to be aware of this change. */
WM_main_add_notifier(NC_WM | ND_LIB_OVERRIDE_CHANGED, NULL);
WM_main_add_notifier(NC_WM | ND_LIB_OVERRIDE_CHANGED, nullptr);
return operator_button_property_finish(C, &ptr, prop);
}
@ -741,7 +743,8 @@ static void UI_OT_override_remove_button(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
/* properties */
RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array");
RNA_def_boolean(
ot->srna, "all", true, "All", "Reset to default values all elements of the array");
}
/** \} */
@ -750,8 +753,8 @@ static void UI_OT_override_remove_button(wmOperatorType *ot)
/** \name Copy To Selected Operator
* \{ */
#define NOT_NULL(assignment) ((assignment) != NULL)
#define NOT_RNA_NULL(assignment) ((assignment).data != NULL)
#define NOT_NULL(assignment) ((assignment) != nullptr)
#define NOT_RNA_NULL(assignment) ((assignment).data != nullptr)
static void ui_context_selected_bones_via_pose(bContext *C, ListBase *r_lb)
{
@ -760,7 +763,7 @@ static void ui_context_selected_bones_via_pose(bContext *C, ListBase *r_lb)
if (!BLI_listbase_is_empty(&lb)) {
LISTBASE_FOREACH (CollectionPointerLink *, link, &lb) {
bPoseChannel *pchan = link->ptr.data;
bPoseChannel *pchan = static_cast<bPoseChannel *>(link->ptr.data);
RNA_pointer_create(link->ptr.owner_id, &RNA_Bone, pchan->bone, &link->ptr);
}
}
@ -776,9 +779,9 @@ bool UI_context_copy_to_selected_list(bContext *C,
char **r_path)
{
*r_use_path_from_id = false;
*r_path = NULL;
*r_path = nullptr;
/* special case for bone constraints */
char *path_from_bone = NULL;
char *path_from_bone = nullptr;
/* Remove links from the collection list which don't contain 'prop'. */
bool ensure_list_items_contain_prop = false;
@ -792,29 +795,32 @@ bool UI_context_copy_to_selected_list(bContext *C,
*/
if (!RNA_property_is_idprop(prop) && RNA_struct_is_a(ptr->type, &RNA_PropertyGroup)) {
PointerRNA owner_ptr;
char *idpath = NULL;
char *idpath = nullptr;
/* First, check the active PoseBone and PoseBone->Bone. */
if (NOT_RNA_NULL(
owner_ptr = CTX_data_pointer_get_type(C, "active_pose_bone", &RNA_PoseBone))) {
if (NOT_NULL(idpath = RNA_path_from_struct_to_idproperty(&owner_ptr, ptr->data))) {
if (NOT_NULL(idpath = RNA_path_from_struct_to_idproperty(
&owner_ptr, static_cast<IDProperty *>(ptr->data)))) {
*r_lb = CTX_data_collection_get(C, "selected_pose_bones");
}
else {
bPoseChannel *pchan = owner_ptr.data;
bPoseChannel *pchan = static_cast<bPoseChannel *>(owner_ptr.data);
RNA_pointer_create(owner_ptr.owner_id, &RNA_Bone, pchan->bone, &owner_ptr);
if (NOT_NULL(idpath = RNA_path_from_struct_to_idproperty(&owner_ptr, ptr->data))) {
if (NOT_NULL(idpath = RNA_path_from_struct_to_idproperty(
&owner_ptr, static_cast<IDProperty *>(ptr->data)))) {
ui_context_selected_bones_via_pose(C, r_lb);
}
}
}
if (idpath == NULL) {
if (idpath == nullptr) {
/* Check the active EditBone if in edit mode. */
if (NOT_RNA_NULL(
owner_ptr = CTX_data_pointer_get_type_silent(C, "active_bone", &RNA_EditBone)) &&
NOT_NULL(idpath = RNA_path_from_struct_to_idproperty(&owner_ptr, ptr->data))) {
NOT_NULL(idpath = RNA_path_from_struct_to_idproperty(
&owner_ptr, static_cast<IDProperty *>(ptr->data)))) {
*r_lb = CTX_data_collection_get(C, "selected_editable_bones");
}
@ -867,30 +873,30 @@ bool UI_context_copy_to_selected_list(bContext *C,
}
else if (RNA_struct_is_a(ptr->type, &RNA_Constraint) &&
(path_from_bone = RNA_path_resolve_from_type_to_property(ptr, prop, &RNA_PoseBone)) !=
NULL) {
nullptr) {
*r_lb = CTX_data_collection_get(C, "selected_pose_bones");
*r_path = path_from_bone;
}
else if (RNA_struct_is_a(ptr->type, &RNA_Node) || RNA_struct_is_a(ptr->type, &RNA_NodeSocket)) {
ListBase lb = {NULL, NULL};
char *path = NULL;
bNode *node = NULL;
ListBase lb = {nullptr, nullptr};
char *path = nullptr;
bNode *node = nullptr;
/* Get the node we're editing */
if (RNA_struct_is_a(ptr->type, &RNA_NodeSocket)) {
bNodeTree *ntree = (bNodeTree *)ptr->owner_id;
bNodeSocket *sock = ptr->data;
if (nodeFindNode(ntree, sock, &node, NULL)) {
if ((path = RNA_path_resolve_from_type_to_property(ptr, prop, &RNA_Node)) != NULL) {
bNodeSocket *sock = static_cast<bNodeSocket *>(ptr->data);
if (nodeFindNode(ntree, sock, &node, nullptr)) {
if ((path = RNA_path_resolve_from_type_to_property(ptr, prop, &RNA_Node)) != nullptr) {
/* we're good! */
}
else {
node = NULL;
node = nullptr;
}
}
}
else {
node = ptr->data;
node = static_cast<bNode *>(ptr->data);
}
/* Now filter by type */
@ -898,7 +904,7 @@ bool UI_context_copy_to_selected_list(bContext *C,
lb = CTX_data_collection_get(C, "selected_nodes");
LISTBASE_FOREACH_MUTABLE (CollectionPointerLink *, link, &lb) {
bNode *node_data = link->ptr.data;
bNode *node_data = static_cast<bNode *>(link->ptr.data);
if (node_data->type != node->type) {
BLI_remlink(&lb, link);
@ -929,17 +935,17 @@ bool UI_context_copy_to_selected_list(bContext *C,
LISTBASE_FOREACH (CollectionPointerLink *, link, &lb) {
Object *ob = (Object *)link->ptr.owner_id;
if (ob->data) {
ID *id_data = ob->data;
ID *id_data = static_cast<ID *>(ob->data);
id_data->tag |= LIB_TAG_DOIT;
}
}
LISTBASE_FOREACH_MUTABLE (CollectionPointerLink *, link, &lb) {
Object *ob = (Object *)link->ptr.owner_id;
ID *id_data = ob->data;
ID *id_data = static_cast<ID *>(ob->data);
if ((id_data == NULL) || (id_data->tag & LIB_TAG_DOIT) == 0 || ID_IS_LINKED(id_data) ||
(GS(id_data->name) != id_code)) {
if ((id_data == nullptr) || (id_data->tag & LIB_TAG_DOIT) == 0 ||
ID_IS_LINKED(id_data) || (GS(id_data->name) != id_code)) {
BLI_remlink(&lb, link);
MEM_freeN(link);
}
@ -961,7 +967,8 @@ bool UI_context_copy_to_selected_list(bContext *C,
/* Sequencer's ID is scene :/ */
/* Try to recursively find an RNA_Sequence ancestor,
* to handle situations like T41062... */
if ((*r_path = RNA_path_resolve_from_type_to_property(ptr, prop, &RNA_Sequence)) != NULL) {
if ((*r_path = RNA_path_resolve_from_type_to_property(ptr, prop, &RNA_Sequence)) !=
nullptr) {
/* Special case when we do this for 'Sequence.lock'.
* (if the sequence is locked, it won't be in "selected_editable_sequences"). */
const char *prop_id = RNA_property_identifier(prop);
@ -975,7 +982,7 @@ bool UI_context_copy_to_selected_list(bContext *C,
ensure_list_items_contain_prop = true;
}
}
return (*r_path != NULL);
return (*r_path != nullptr);
}
else {
return false;
@ -1013,13 +1020,13 @@ bool UI_context_copy_to_selected_check(PointerRNA *ptr,
if (use_path_from_id) {
/* Path relative to ID. */
lprop = NULL;
lprop = nullptr;
RNA_id_pointer_create(ptr_link->owner_id, &idptr);
RNA_path_resolve_property(&idptr, path, &lptr, &lprop);
}
else if (path) {
/* Path relative to elements from list. */
lprop = NULL;
lprop = nullptr;
RNA_path_resolve_property(ptr_link, path, &lptr, &lprop);
}
else {
@ -1034,7 +1041,7 @@ bool UI_context_copy_to_selected_check(PointerRNA *ptr,
/* Skip non-existing properties on link. This was previously covered with the `lprop != prop`
* check but we are now more permissive when it comes to ID properties, see below. */
if (lprop == NULL) {
if (lprop == nullptr) {
return false;
}
@ -1105,13 +1112,13 @@ static bool copy_to_selected_button(bContext *C, bool all, bool poll)
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
/* if there is a valid property that is editable... */
if (ptr.data == NULL || prop == NULL) {
if (ptr.data == nullptr || prop == nullptr) {
return false;
}
char *path = NULL;
char *path = nullptr;
bool use_path_from_id;
ListBase lb = {NULL};
ListBase lb = {nullptr};
if (!UI_context_copy_to_selected_list(C, &ptr, prop, &lb, &use_path_from_id, &path)) {
return false;
@ -1198,7 +1205,7 @@ static bool jump_to_target_ptr(bContext *C, PointerRNA ptr, const bool poll)
/* Verify pointer type. */
char bone_name[MAXBONENAME];
const StructRNA *target_type = NULL;
const StructRNA *target_type = nullptr;
if (ELEM(ptr.type, &RNA_EditBone, &RNA_PoseBone, &RNA_Bone)) {
RNA_string_get(&ptr, "name", bone_name);
@ -1210,13 +1217,13 @@ static bool jump_to_target_ptr(bContext *C, PointerRNA ptr, const bool poll)
target_type = &RNA_Object;
}
if (target_type == NULL) {
if (target_type == nullptr) {
return false;
}
/* Find the containing Object. */
ViewLayer *view_layer = CTX_data_view_layer(C);
Base *base = NULL;
Base *base = nullptr;
const short id_type = GS(ptr.owner_id->name);
if (id_type == ID_OB) {
base = BKE_view_layer_base_find(view_layer, (Object *)ptr.owner_id);
@ -1226,7 +1233,7 @@ static bool jump_to_target_ptr(bContext *C, PointerRNA ptr, const bool poll)
}
bool ok = false;
if ((base == NULL) || ((target_type == &RNA_Bone) && (base->object->type != OB_ARMATURE))) {
if ((base == nullptr) || ((target_type == &RNA_Bone) && (base->object->type != OB_ARMATURE))) {
/* pass */
}
else if (poll) {
@ -1278,13 +1285,14 @@ static bool jump_to_target_button(bContext *C, bool poll)
if (type == PROP_STRING) {
const uiBut *but = UI_context_active_but_get(C);
const uiButSearch *search_but = (but->type == UI_BTYPE_SEARCH_MENU) ? (uiButSearch *)but :
NULL;
nullptr;
if (search_but && search_but->items_update_fn == ui_rna_collection_search_update_fn) {
uiRNACollectionSearch *coll_search = search_but->arg;
uiRNACollectionSearch *coll_search = static_cast<uiRNACollectionSearch *>(search_but->arg);
char str_buf[MAXBONENAME];
char *str_ptr = RNA_property_string_get_alloc(&ptr, prop, str_buf, sizeof(str_buf), NULL);
char *str_ptr = RNA_property_string_get_alloc(
&ptr, prop, str_buf, sizeof(str_buf), nullptr);
int found = RNA_property_collection_lookup_string(
&coll_search->search_ptr, coll_search->search_prop, str_ptr, &target_ptr);
@ -1342,39 +1350,39 @@ static void UI_OT_jump_to_target_button(wmOperatorType *ot)
/* EditSource Utility funcs and operator,
* NOTE: this includes utility functions and button matching checks. */
typedef struct uiEditSourceStore {
struct uiEditSourceStore {
uiBut but_orig;
GHash *hash;
} uiEditSourceStore;
};
typedef struct uiEditSourceButStore {
struct uiEditSourceButStore {
char py_dbg_fn[FILE_MAX];
int py_dbg_line_number;
} uiEditSourceButStore;
};
/* should only ever be set while the edit source operator is running */
static struct uiEditSourceStore *ui_editsource_info = NULL;
static uiEditSourceStore *ui_editsource_info = nullptr;
bool UI_editsource_enable_check(void)
{
return (ui_editsource_info != NULL);
return (ui_editsource_info != nullptr);
}
static void ui_editsource_active_but_set(uiBut *but)
{
BLI_assert(ui_editsource_info == NULL);
BLI_assert(ui_editsource_info == nullptr);
ui_editsource_info = MEM_callocN(sizeof(uiEditSourceStore), __func__);
ui_editsource_info = MEM_cnew<uiEditSourceStore>(__func__);
memcpy(&ui_editsource_info->but_orig, but, sizeof(uiBut));
ui_editsource_info->hash = BLI_ghash_ptr_new(__func__);
}
static void ui_editsource_active_but_clear(void)
static void ui_editsource_active_but_clear()
{
BLI_ghash_free(ui_editsource_info->hash, NULL, MEM_freeN);
BLI_ghash_free(ui_editsource_info->hash, nullptr, MEM_freeN);
MEM_freeN(ui_editsource_info);
ui_editsource_info = NULL;
ui_editsource_info = nullptr;
}
static bool ui_editsource_uibut_match(uiBut *but_a, uiBut *but_b)
@ -1395,11 +1403,14 @@ static bool ui_editsource_uibut_match(uiBut *but_a, uiBut *but_b)
return false;
}
extern "C" {
void PyC_FileAndNum_Safe(const char **r_filename, int *r_lineno);
}
void UI_editsource_active_but_test(uiBut *but)
{
extern void PyC_FileAndNum_Safe(const char **r_filename, int *r_lineno);
struct uiEditSourceButStore *but_store = MEM_callocN(sizeof(uiEditSourceButStore), __func__);
uiEditSourceButStore *but_store = MEM_cnew<uiEditSourceButStore>(__func__);
const char *fn;
int line_number = -1;
@ -1424,9 +1435,10 @@ void UI_editsource_active_but_test(uiBut *but)
void UI_editsource_but_replace(const uiBut *old_but, uiBut *new_but)
{
uiEditSourceButStore *but_store = BLI_ghash_lookup(ui_editsource_info->hash, old_but);
uiEditSourceButStore *but_store = static_cast<uiEditSourceButStore *>(
BLI_ghash_lookup(ui_editsource_info->hash, old_but));
if (but_store) {
BLI_ghash_remove(ui_editsource_info->hash, old_but, NULL, NULL);
BLI_ghash_remove(ui_editsource_info->hash, old_but, nullptr, nullptr);
BLI_ghash_insert(ui_editsource_info->hash, new_but, but_store);
}
}
@ -1436,8 +1448,8 @@ static int editsource_text_edit(bContext *C,
const char filepath[FILE_MAX],
const int line)
{
struct Main *bmain = CTX_data_main(C);
Text *text = NULL;
Main *bmain = CTX_data_main(C);
Text *text = nullptr;
/* Developers may wish to copy-paste to an external editor. */
printf("%s:%d\n", filepath, line);
@ -1449,11 +1461,11 @@ static int editsource_text_edit(bContext *C,
}
}
if (text == NULL) {
if (text == nullptr) {
text = BKE_text_load(bmain, filepath, BKE_main_blendfile_path(bmain));
}
if (text == NULL) {
if (text == nullptr) {
BKE_reportf(op->reports, RPT_WARNING, "File '%s' cannot be opened", filepath);
return OPERATOR_CANCELLED;
}
@ -1477,7 +1489,7 @@ static int editsource_exec(bContext *C, wmOperator *op)
if (but) {
GHashIterator ghi;
struct uiEditSourceButStore *but_store = NULL;
uiEditSourceButStore *but_store = nullptr;
ARegion *region = CTX_wm_region(C);
int ret;
@ -1496,9 +1508,9 @@ static int editsource_exec(bContext *C, wmOperator *op)
for (BLI_ghashIterator_init(&ghi, ui_editsource_info->hash);
BLI_ghashIterator_done(&ghi) == false;
BLI_ghashIterator_step(&ghi)) {
uiBut *but_key = BLI_ghashIterator_getKey(&ghi);
uiBut *but_key = static_cast<uiBut *>(BLI_ghashIterator_getKey(&ghi));
if (but_key && ui_editsource_uibut_match(&ui_editsource_info->but_orig, but_key)) {
but_store = BLI_ghashIterator_getValue(&ghi);
but_store = static_cast<uiEditSourceButStore *>(BLI_ghashIterator_getValue(&ghi));
break;
}
}
@ -1569,7 +1581,7 @@ static void edittranslation_find_po_file(const char *root,
/* Now try without the second iso code part (_ES in es_ES). */
{
const char *tc = NULL;
const char *tc = nullptr;
size_t szt = 0;
tstr[0] = '\0';
@ -1603,7 +1615,7 @@ static void edittranslation_find_po_file(const char *root,
static int edittranslation_exec(bContext *C, wmOperator *op)
{
uiBut *but = UI_context_active_but_get(C);
if (but == NULL) {
if (but == nullptr) {
BKE_report(op->reports, RPT_ERROR, "Active button not found");
return OPERATOR_CANCELLED;
}
@ -1614,16 +1626,16 @@ static int edittranslation_exec(bContext *C, wmOperator *op)
const char *root = U.i18ndir;
const char *uilng = BLT_lang_get();
uiStringInfo but_label = {BUT_GET_LABEL, NULL};
uiStringInfo rna_label = {BUT_GET_RNA_LABEL, NULL};
uiStringInfo enum_label = {BUT_GET_RNAENUM_LABEL, NULL};
uiStringInfo but_tip = {BUT_GET_TIP, NULL};
uiStringInfo rna_tip = {BUT_GET_RNA_TIP, NULL};
uiStringInfo enum_tip = {BUT_GET_RNAENUM_TIP, NULL};
uiStringInfo rna_struct = {BUT_GET_RNASTRUCT_IDENTIFIER, NULL};
uiStringInfo rna_prop = {BUT_GET_RNAPROP_IDENTIFIER, NULL};
uiStringInfo rna_enum = {BUT_GET_RNAENUM_IDENTIFIER, NULL};
uiStringInfo rna_ctxt = {BUT_GET_RNA_LABEL_CONTEXT, NULL};
uiStringInfo but_label = {BUT_GET_LABEL, nullptr};
uiStringInfo rna_label = {BUT_GET_RNA_LABEL, nullptr};
uiStringInfo enum_label = {BUT_GET_RNAENUM_LABEL, nullptr};
uiStringInfo but_tip = {BUT_GET_TIP, nullptr};
uiStringInfo rna_tip = {BUT_GET_RNA_TIP, nullptr};
uiStringInfo enum_tip = {BUT_GET_RNAENUM_TIP, nullptr};
uiStringInfo rna_struct = {BUT_GET_RNASTRUCT_IDENTIFIER, nullptr};
uiStringInfo rna_prop = {BUT_GET_RNAPROP_IDENTIFIER, nullptr};
uiStringInfo rna_enum = {BUT_GET_RNAENUM_IDENTIFIER, nullptr};
uiStringInfo rna_ctxt = {BUT_GET_RNA_LABEL_CONTEXT, nullptr};
if (!BLI_is_dir(root)) {
BKE_report(op->reports,
@ -1632,8 +1644,8 @@ static int edittranslation_exec(bContext *C, wmOperator *op)
"Directory' path to a valid directory");
return OPERATOR_CANCELLED;
}
ot = WM_operatortype_find(EDTSRC_I18N_OP_NAME, 0);
if (ot == NULL) {
ot = WM_operatortype_find(EDTSRC_I18N_OP_NAME, false);
if (ot == nullptr) {
BKE_reportf(op->reports,
RPT_ERROR,
"Could not find operator '%s'! Please enable ui_translate add-on "
@ -1662,7 +1674,7 @@ static int edittranslation_exec(bContext *C, wmOperator *op)
&rna_prop,
&rna_enum,
&rna_ctxt,
NULL);
nullptr);
WM_operator_properties_create_ptr(&ptr, ot);
RNA_string_set(&ptr, "lang", uilng);
@ -1677,7 +1689,7 @@ static int edittranslation_exec(bContext *C, wmOperator *op)
RNA_string_set(&ptr, "rna_prop", rna_prop.strinfo);
RNA_string_set(&ptr, "rna_enum", rna_enum.strinfo);
RNA_string_set(&ptr, "rna_ctxt", rna_ctxt.strinfo);
const int ret = WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr, NULL);
const int ret = WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr, nullptr);
/* Clean up */
if (but_label.strinfo) {
@ -1737,7 +1749,7 @@ static int reloadtranslation_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
{
BLT_lang_init();
BLF_cache_clear();
BLT_lang_set(NULL);
BLT_lang_set(nullptr);
UI_reinit_font();
return OPERATOR_FINISHED;
}
@ -1764,13 +1776,13 @@ static int ui_button_press_invoke(bContext *C, wmOperator *op, const wmEvent *ev
bScreen *screen = CTX_wm_screen(C);
const bool skip_depressed = RNA_boolean_get(op->ptr, "skip_depressed");
ARegion *region_prev = CTX_wm_region(C);
ARegion *region = screen ? BKE_screen_find_region_xy(screen, RGN_TYPE_ANY, event->xy) : NULL;
ARegion *region = screen ? BKE_screen_find_region_xy(screen, RGN_TYPE_ANY, event->xy) : nullptr;
if (region == NULL) {
if (region == nullptr) {
region = region_prev;
}
if (region == NULL) {
if (region == nullptr) {
return OPERATOR_PASS_THROUGH;
}
@ -1778,7 +1790,7 @@ static int ui_button_press_invoke(bContext *C, wmOperator *op, const wmEvent *ev
uiBut *but = UI_context_active_but_get(C);
CTX_wm_region_set(C, region_prev);
if (but == NULL) {
if (but == nullptr) {
return OPERATOR_PASS_THROUGH;
}
if (skip_depressed && (but->flag & (UI_SELECT | UI_SELECT_DRAW))) {
@ -1791,7 +1803,7 @@ static int ui_button_press_invoke(bContext *C, wmOperator *op, const wmEvent *ev
UI_but_execute(C, region, but);
but->optype = but_optype;
but->optype = static_cast<wmOperatorType *>(but_optype);
WM_event_add_mousemove(CTX_wm_window(C));
@ -1807,7 +1819,7 @@ static void UI_OT_button_execute(wmOperatorType *ot)
ot->invoke = ui_button_press_invoke;
ot->flag = OPTYPE_INTERNAL;
RNA_def_boolean(ot->srna, "skip_depressed", 0, "Skip Depressed", "");
RNA_def_boolean(ot->srna, "skip_depressed", false, "Skip Depressed", "");
}
/** \} */
@ -1853,21 +1865,21 @@ bool UI_drop_color_poll(struct bContext *C, wmDrag *drag, const wmEvent *UNUSED(
ARegion *region = CTX_wm_region(C);
if (UI_but_active_drop_color(C)) {
return 1;
return true;
}
if (sima && (sima->mode == SI_MODE_PAINT) && sima->image &&
(region && region->regiontype == RGN_TYPE_WINDOW)) {
return 1;
return true;
}
}
return 0;
return false;
}
void UI_drop_color_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
{
uiDragColorHandle *drag_info = drag->poin;
uiDragColorHandle *drag_info = static_cast<uiDragColorHandle *>(drag->poin);
RNA_float_set_array(drop->ptr, "color", drag_info->color);
RNA_boolean_set(drop->ptr, "gamma", drag_info->gamma_corrected);
@ -1876,7 +1888,7 @@ void UI_drop_color_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
static int drop_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
ARegion *region = CTX_wm_region(C);
uiBut *but = NULL;
uiBut *but = nullptr;
float color[4];
bool gamma;
@ -1933,8 +1945,10 @@ static void UI_OT_drop_color(wmOperatorType *ot)
ot->invoke = drop_color_invoke;
ot->flag = OPTYPE_INTERNAL;
RNA_def_float_color(ot->srna, "color", 3, NULL, 0.0, FLT_MAX, "Color", "Source color", 0.0, 1.0);
RNA_def_boolean(ot->srna, "gamma", 0, "Gamma Corrected", "The source color is gamma corrected");
RNA_def_float_color(
ot->srna, "color", 3, nullptr, 0.0, FLT_MAX, "Color", "Source color", 0.0, 1.0);
RNA_def_boolean(
ot->srna, "gamma", false, "Gamma Corrected", "The source color is gamma corrected");
}
/** \} */
@ -1964,7 +1978,7 @@ static bool drop_name_poll(bContext *C)
static int drop_name_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
uiBut *but = UI_but_active_drop_name_button(C);
char *str = RNA_string_get_alloc(op->ptr, "string", NULL, 0, NULL);
char *str = RNA_string_get_alloc(op->ptr, "string", nullptr, 0, nullptr);
if (str) {
ui_but_set_string_interactive(C, but, str);
@ -1985,7 +1999,7 @@ static void UI_OT_drop_name(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL;
RNA_def_string(
ot->srna, "string", NULL, 0, "String", "The string value to drop into the button");
ot->srna, "string", nullptr, 0, "String", "The string value to drop into the button");
}
/** \} */
@ -2003,7 +2017,7 @@ static bool ui_list_focused_poll(bContext *C)
const wmWindow *win = CTX_wm_window(C);
const uiList *list = UI_list_find_mouse_over(region, win->eventstate);
return list != NULL;
return list != nullptr;
}
/**
@ -2026,7 +2040,7 @@ static int ui_list_start_filter_invoke(bContext *C, wmOperator *UNUSED(op), cons
ARegion *region = CTX_wm_region(C);
uiList *list = UI_list_find_mouse_over(region, event);
/* Poll should check. */
BLI_assert(list != NULL);
BLI_assert(list != nullptr);
if (ui_list_unhide_filter_options(list)) {
ui_region_redraw_immediately(C, region);
@ -2061,7 +2075,7 @@ static bool ui_view_drop_poll(bContext *C)
const ARegion *region = CTX_wm_region(C);
const uiViewItemHandle *hovered_item = UI_region_views_find_item_at(region, win->eventstate->xy);
return hovered_item != NULL;
return hovered_item != nullptr;
}
static int ui_view_drop_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
@ -2073,7 +2087,8 @@ static int ui_view_drop_invoke(bContext *C, wmOperator *UNUSED(op), const wmEven
const ARegion *region = CTX_wm_region(C);
uiViewItemHandle *hovered_item = UI_region_views_find_item_at(region, event->xy);
if (!UI_view_item_drop_handle(C, hovered_item, event->customdata)) {
if (!UI_view_item_drop_handle(
C, hovered_item, static_cast<const ListBase *>(event->customdata))) {
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
}
@ -2107,7 +2122,7 @@ static bool ui_view_item_rename_poll(bContext *C)
{
const ARegion *region = CTX_wm_region(C);
const uiViewItemHandle *active_item = UI_region_views_find_active_item(region);
return active_item != NULL && UI_view_item_can_rename(active_item);
return active_item != nullptr && UI_view_item_can_rename(active_item);
}
static int ui_view_item_rename_exec(bContext *C, wmOperator *UNUSED(op))
@ -2144,8 +2159,8 @@ static void UI_OT_view_item_rename(wmOperatorType *ot)
static bool ui_drop_material_poll(bContext *C)
{
PointerRNA ptr = CTX_data_pointer_get_type(C, "object", &RNA_Object);
Object *ob = ptr.data;
if (ob == NULL) {
const Object *ob = static_cast<const Object *>(ptr.data);
if (ob == nullptr) {
return false;
}
@ -2163,12 +2178,12 @@ static int ui_drop_material_exec(bContext *C, wmOperator *op)
Material *ma = (Material *)WM_operator_properties_id_lookup_from_name_or_session_uuid(
bmain, op->ptr, ID_MA);
if (ma == NULL) {
if (ma == nullptr) {
return OPERATOR_CANCELLED;
}
PointerRNA ptr = CTX_data_pointer_get_type(C, "object", &RNA_Object);
Object *ob = ptr.data;
Object *ob = static_cast<Object *>(ptr.data);
BLI_assert(ob);
PointerRNA mat_slot = CTX_data_pointer_get_type(C, "material_slot", &RNA_MaterialSlot);
@ -2176,14 +2191,14 @@ static int ui_drop_material_exec(bContext *C, wmOperator *op)
const int target_slot = RNA_int_get(&mat_slot, "slot_index") + 1;
/* only drop grease pencil material on grease pencil objects */
if ((ma->gp_style != NULL) && (ob->type != OB_GPENCIL)) {
if ((ma->gp_style != nullptr) && (ob->type != OB_GPENCIL)) {
return OPERATOR_CANCELLED;
}
BKE_object_material_assign(bmain, ob, ma, target_slot, BKE_MAT_ASSIGN_USERPREF);
WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, ob);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, nullptr);
WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_LINKS, ma);
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);

View File

@ -8,10 +8,10 @@
/* a full doc with API notes can be found in
* bf-blender/trunk/blender/doc/guides/interface_API.txt */
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include "MEM_guardedalloc.h"
@ -57,7 +57,7 @@
#define ANIMATION_TIME 0.30
#define ANIMATION_INTERVAL 0.02
typedef enum uiPanelRuntimeFlag {
enum uiPanelRuntimeFlag {
PANEL_LAST_ADDED = (1 << 0),
PANEL_ACTIVE = (1 << 2),
PANEL_WAS_ACTIVE = (1 << 3),
@ -78,22 +78,22 @@ typedef enum uiPanelRuntimeFlag {
PANEL_IS_DRAG_DROP = (1 << 10),
/** Draw a border with the active color around the panel. */
PANEL_ACTIVE_BORDER = (1 << 11),
} uiPanelRuntimeFlag;
};
/* The state of the mouse position relative to the panel. */
typedef enum uiPanelMouseState {
enum uiPanelMouseState {
PANEL_MOUSE_OUTSIDE, /** Mouse is not in the panel. */
PANEL_MOUSE_INSIDE_CONTENT, /** Mouse is in the actual panel content. */
PANEL_MOUSE_INSIDE_HEADER, /** Mouse is in the panel header. */
} uiPanelMouseState;
};
typedef enum uiHandlePanelState {
enum uiHandlePanelState {
PANEL_STATE_DRAG,
PANEL_STATE_ANIMATION,
PANEL_STATE_EXIT,
} uiHandlePanelState;
};
typedef struct uiHandlePanelData {
struct uiHandlePanelData {
uiHandlePanelState state;
/* Animation. */
@ -104,17 +104,17 @@ typedef struct uiHandlePanelData {
int startx, starty;
int startofsx, startofsy;
float start_cur_xmin, start_cur_ymin;
} uiHandlePanelData;
};
typedef struct PanelSort {
struct PanelSort {
Panel *panel;
int new_offset_x;
int new_offset_y;
} PanelSort;
};
static void panel_set_expansion_from_list_data(const bContext *C, Panel *panel);
static int get_panel_real_size_y(const Panel *panel);
static void panel_activate_state(const bContext *C, Panel *panel, uiHandlePanelState state);
static void panel_activate_state(const bContext *C, Panel *panel, const uiHandlePanelState state);
static int compare_panel(const void *a, const void *b);
static bool panel_type_context_poll(ARegion *region,
const PanelType *panel_type,
@ -155,7 +155,7 @@ static bool panel_active_animation_changed(ListBase *lb,
/* Detect animation. */
if (panel->activedata) {
uiHandlePanelData *data = panel->activedata;
uiHandlePanelData *data = static_cast<uiHandlePanelData *>(panel->activedata);
if (data->state == PANEL_STATE_ANIMATION) {
*r_panel_animation = panel;
}
@ -178,7 +178,7 @@ static bool panel_active_animation_changed(ListBase *lb,
static bool properties_space_needs_realign(const ScrArea *area, const ARegion *region)
{
if (area->spacetype == SPACE_PROPERTIES && region->regiontype == RGN_TYPE_WINDOW) {
SpaceProperties *sbuts = area->spacedata.first;
const SpaceProperties *sbuts = static_cast<SpaceProperties *>(area->spacedata.first);
if (sbuts->mainbo != sbuts->mainb) {
return true;
@ -190,14 +190,14 @@ static bool properties_space_needs_realign(const ScrArea *area, const ARegion *r
static bool panels_need_realign(const ScrArea *area, ARegion *region, Panel **r_panel_animation)
{
*r_panel_animation = NULL;
*r_panel_animation = nullptr;
if (properties_space_needs_realign(area, region)) {
return true;
}
/* Detect if a panel was added or removed. */
Panel *panel_animation = NULL;
Panel *panel_animation = nullptr;
bool no_animation = false;
if (panel_active_animation_changed(&region->panels, &panel_animation, &no_animation)) {
return true;
@ -225,7 +225,7 @@ static Panel *panel_add_instanced(ARegion *region,
PanelType *panel_type,
PointerRNA *custom_data)
{
Panel *panel = MEM_callocN(sizeof(Panel), __func__);
Panel *panel = MEM_cnew<Panel>(__func__);
panel->type = panel_type;
BLI_strncpy(panel->panelname, panel_type->idname, sizeof(panel->panelname));
@ -235,7 +235,7 @@ static Panel *panel_add_instanced(ARegion *region,
/* Add the panel's children too. Although they aren't instanced panels, we can still use this
* function to create them, as UI_panel_begin does other things we don't need to do. */
LISTBASE_FOREACH (LinkData *, child, &panel_type->children) {
PanelType *child_type = child->data;
PanelType *child_type = static_cast<PanelType *>(child->data);
panel_add_instanced(region, &panel->children, child_type, custom_data);
}
@ -265,12 +265,12 @@ Panel *UI_panel_add_instanced(const bContext *C,
{
ARegionType *region_type = region->type;
PanelType *panel_type = BLI_findstring(
&region_type->paneltypes, panel_idname, offsetof(PanelType, idname));
PanelType *panel_type = static_cast<PanelType *>(
BLI_findstring(&region_type->paneltypes, panel_idname, offsetof(PanelType, idname)));
if (panel_type == NULL) {
if (panel_type == nullptr) {
printf("Panel type '%s' not found.\n", panel_idname);
return NULL;
return nullptr;
}
Panel *new_panel = panel_add_instanced(region, panels, panel_type, custom_data);
@ -314,14 +314,14 @@ void UI_panels_free_instanced(const bContext *C, ARegion *region)
{
/* Delete panels with the instanced flag. */
LISTBASE_FOREACH_MUTABLE (Panel *, panel, &region->panels) {
if ((panel->type != NULL) && (panel->type->flag & PANEL_TYPE_INSTANCED)) {
if ((panel->type != nullptr) && (panel->type->flag & PANEL_TYPE_INSTANCED)) {
/* Make sure the panel's handler is removed before deleting it. */
if (C != NULL && panel->activedata != NULL) {
if (C != nullptr && panel->activedata != nullptr) {
panel_activate_state(C, panel, PANEL_STATE_EXIT);
}
/* Free panel's custom data. */
if (panel->runtime.custom_data_ptr != NULL) {
if (panel->runtime.custom_data_ptr != nullptr) {
MEM_freeN(panel->runtime.custom_data_ptr);
}
@ -335,28 +335,28 @@ bool UI_panel_list_matches_data(ARegion *region,
ListBase *data,
uiListPanelIDFromDataFunc panel_idname_func)
{
/* Check for NULL data. */
/* Check for nullptr data. */
int data_len = 0;
Link *data_link = NULL;
if (data == NULL) {
Link *data_link = nullptr;
if (data == nullptr) {
data_len = 0;
data_link = NULL;
data_link = nullptr;
}
else {
data_len = BLI_listbase_count(data);
data_link = data->first;
data_link = static_cast<Link *>(data->first);
}
int i = 0;
LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->type != NULL && panel->type->flag & PANEL_TYPE_INSTANCED) {
if (panel->type != nullptr && panel->type->flag & PANEL_TYPE_INSTANCED) {
/* The panels were reordered by drag and drop. */
if (panel->flag & PNL_INSTANCED_LIST_ORDER_CHANGED) {
return false;
}
/* We reached the last data item before the last instanced panel. */
if (data_link == NULL) {
if (data_link == nullptr) {
return false;
}
@ -383,15 +383,15 @@ bool UI_panel_list_matches_data(ARegion *region,
static void reorder_instanced_panel_list(bContext *C, ARegion *region, Panel *drag_panel)
{
/* Without a type we cannot access the reorder callback. */
if (drag_panel->type == NULL) {
if (drag_panel->type == nullptr) {
return;
}
/* Don't reorder if this instanced panel doesn't support drag and drop reordering. */
if (drag_panel->type->reorder == NULL) {
if (drag_panel->type->reorder == nullptr) {
return;
}
char *context = NULL;
char *context = nullptr;
if (!UI_panel_category_is_visible(region)) {
context = drag_panel->type->context;
}
@ -415,7 +415,8 @@ static void reorder_instanced_panel_list(bContext *C, ARegion *region, Panel *dr
BLI_assert(start_index != -1); /* The drag panel should definitely be in the list. */
/* Sort the matching instanced panels by their display order. */
PanelSort *panel_sort = MEM_callocN(list_panels_len * sizeof(*panel_sort), __func__);
PanelSort *panel_sort = static_cast<PanelSort *>(
MEM_callocN(list_panels_len * sizeof(*panel_sort), __func__));
PanelSort *sort_index = panel_sort;
LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->type) {
@ -452,7 +453,7 @@ static void reorder_instanced_panel_list(bContext *C, ARegion *region, Panel *dr
/* Finally, move this panel's list item to the new index in its list. */
drag_panel->type->reorder(C, drag_panel, move_to_index);
CTX_store_set(C, NULL);
CTX_store_set(C, nullptr);
}
/**
@ -480,9 +481,9 @@ static bool panel_set_expand_from_list_data_recursive(Panel *panel, short flag,
*/
static void panel_set_expansion_from_list_data(const bContext *C, Panel *panel)
{
BLI_assert(panel->type != NULL);
BLI_assert(panel->type != nullptr);
BLI_assert(panel->type->flag & PANEL_TYPE_INSTANCED);
if (panel->type->get_list_data_expand_flag == NULL) {
if (panel->type->get_list_data_expand_flag == nullptr) {
/* Instanced panel doesn't support loading expansion. */
return;
}
@ -504,7 +505,7 @@ static void region_panels_set_expansion_from_list_data(const bContext *C, ARegio
LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->runtime_flag & PANEL_ACTIVE) {
PanelType *panel_type = panel->type;
if (panel_type != NULL && panel->type->flag & PANEL_TYPE_INSTANCED) {
if (panel_type != nullptr && panel->type->flag & PANEL_TYPE_INSTANCED) {
panel_set_expansion_from_list_data(C, panel);
}
}
@ -537,7 +538,7 @@ static void set_panels_list_data_expand_flag(const bContext *C, const ARegion *r
{
LISTBASE_FOREACH (Panel *, panel, &region->panels) {
PanelType *panel_type = panel->type;
if (panel_type == NULL) {
if (panel_type == nullptr) {
continue;
}
@ -563,11 +564,11 @@ static bool panel_custom_data_active_get(const Panel *panel)
{
/* The caller should make sure the panel is active and has a type. */
BLI_assert(UI_panel_is_active(panel));
BLI_assert(panel->type != NULL);
BLI_assert(panel->type != nullptr);
if (panel->type->active_property[0] != '\0') {
PointerRNA *ptr = UI_panel_custom_data_get(panel);
if (ptr != NULL && !RNA_pointer_is_null(ptr)) {
if (ptr != nullptr && !RNA_pointer_is_null(ptr)) {
return RNA_boolean_get(ptr, panel->type->active_property);
}
}
@ -579,12 +580,12 @@ static void panel_custom_data_active_set(Panel *panel)
{
/* Since the panel is interacted with, it should be active and have a type. */
BLI_assert(UI_panel_is_active(panel));
BLI_assert(panel->type != NULL);
BLI_assert(panel->type != nullptr);
if (panel->type->active_property[0] != '\0') {
PointerRNA *ptr = UI_panel_custom_data_get(panel);
BLI_assert(RNA_struct_find_property(ptr, panel->type->active_property) != NULL);
if (ptr != NULL && !RNA_pointer_is_null(ptr)) {
BLI_assert(RNA_struct_find_property(ptr, panel->type->active_property) != nullptr);
if (ptr != nullptr && !RNA_pointer_is_null(ptr)) {
RNA_boolean_set(ptr, panel->type->active_property, true);
}
}
@ -617,7 +618,7 @@ static void panel_set_runtime_flag_recursive(Panel *panel, short flag, bool valu
static void panels_collapse_all(ARegion *region, const Panel *from_panel)
{
const bool has_category_tabs = UI_panel_category_is_visible(region);
const char *category = has_category_tabs ? UI_panel_category_active_get(region, false) : NULL;
const char *category = has_category_tabs ? UI_panel_category_active_get(region, false) : nullptr;
const PanelType *from_pt = from_panel->type;
LISTBASE_FOREACH (Panel *, panel, &region->panels) {
@ -659,7 +660,7 @@ Panel *UI_panel_find_by_type(ListBase *lb, const PanelType *pt)
return panel;
}
}
return NULL;
return nullptr;
}
Panel *UI_panel_begin(
@ -668,10 +669,10 @@ Panel *UI_panel_begin(
Panel *panel_last;
const char *drawname = CTX_IFACE_(pt->translation_context, pt->label);
const char *idname = pt->idname;
const bool newpanel = (panel == NULL);
const bool newpanel = (panel == nullptr);
if (newpanel) {
panel = MEM_callocN(sizeof(Panel), __func__);
panel = MEM_cnew<Panel>(__func__);
panel->type = pt;
BLI_strncpy(panel->panelname, idname, sizeof(panel->panelname));
@ -701,7 +702,7 @@ Panel *UI_panel_begin(
/* If a new panel is added, we insert it right after the panel that was last added.
* This way new panels are inserted in the right place between versions. */
for (panel_last = lb->first; panel_last; panel_last = panel_last->next) {
for (panel_last = static_cast<Panel *>(lb->first); panel_last; panel_last = panel_last->next) {
if (panel_last->runtime_flag & PANEL_LAST_ADDED) {
BLI_remlink(lb, panel);
BLI_insertlinkafter(lb, panel_last, panel);
@ -755,7 +756,7 @@ void UI_panel_header_buttons_end(Panel *panel)
/* A button group should always be created in #UI_panel_header_buttons_begin. */
BLI_assert(!BLI_listbase_is_empty(&block->button_groups));
uiButtonGroup *button_group = block->button_groups.last;
uiButtonGroup *button_group = static_cast<uiButtonGroup *>(block->button_groups.last);
button_group->flag &= ~UI_BUTTON_GROUP_LOCK;
@ -770,7 +771,7 @@ void UI_panel_header_buttons_end(Panel *panel)
/* Always add a new button group. Although this may result in many empty groups, without it,
* new buttons in the panel body not protected with a #ui_block_new_button_group call would
* end up in the panel header group. */
ui_block_new_button_group(block, 0);
ui_block_new_button_group(block, (uiButtonGroupFlag)0);
}
}
@ -867,7 +868,7 @@ void ui_panel_tag_search_filter_match(Panel *panel)
static void panel_matches_search_filter_recursive(const Panel *panel, bool *filter_matches)
{
*filter_matches |= panel->runtime_flag & PANEL_SEARCH_FILTER_MATCH;
*filter_matches |= bool(panel->runtime_flag & PANEL_SEARCH_FILTER_MATCH);
/* If the panel has no match we need to make sure that its children are too. */
if (!*filter_matches) {
@ -893,7 +894,7 @@ static void panel_set_expansion_from_search_filter_recursive(const bContext *C,
{
/* This has to run on inactive panels that may not have a type,
* but we can prevent running on header-less panels in some cases. */
if (panel->type == NULL || !(panel->type->flag & PANEL_TYPE_NO_HEADER)) {
if (panel->type == nullptr || !(panel->type->flag & PANEL_TYPE_NO_HEADER)) {
SET_FLAG_FROM_TEST(panel->runtime_flag, use_search_closed, PANEL_USE_CLOSED_FROM_SEARCH);
}
@ -926,9 +927,9 @@ static void region_panels_set_expansion_from_search_filter(const bContext *C,
static void panel_remove_invisible_layouts_recursive(Panel *panel, const Panel *parent_panel)
{
uiBlock *block = panel->runtime.block;
BLI_assert(block != NULL);
BLI_assert(block != nullptr);
BLI_assert(block->active);
if (parent_panel != NULL && UI_panel_is_closed(parent_panel)) {
if (parent_panel != nullptr && UI_panel_is_closed(parent_panel)) {
/* The parent panel is closed, so this panel can be completely removed. */
UI_block_set_search_only(block, true);
LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
@ -944,7 +945,7 @@ static void panel_remove_invisible_layouts_recursive(Panel *panel, const Panel *
continue;
}
LISTBASE_FOREACH (LinkData *, link, &button_group->buttons) {
uiBut *but = link->data;
uiBut *but = static_cast<uiBut *>(link->data);
but->flag |= UI_HIDDEN;
}
}
@ -952,7 +953,7 @@ static void panel_remove_invisible_layouts_recursive(Panel *panel, const Panel *
LISTBASE_FOREACH (Panel *, child_panel, &panel->children) {
if (child_panel->runtime_flag & PANEL_ACTIVE) {
BLI_assert(child_panel->runtime.block != NULL);
BLI_assert(child_panel->runtime.block != nullptr);
panel_remove_invisible_layouts_recursive(child_panel, panel);
}
}
@ -962,8 +963,8 @@ static void region_panels_remove_invisible_layouts(ARegion *region)
{
LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->runtime_flag & PANEL_ACTIVE) {
BLI_assert(panel->runtime.block != NULL);
panel_remove_invisible_layouts_recursive(panel, NULL);
BLI_assert(panel->runtime.block != nullptr);
panel_remove_invisible_layouts_recursive(panel, nullptr);
}
}
}
@ -1054,7 +1055,7 @@ static void panel_draw_highlight_border(const Panel *panel,
const rcti *rect,
const rcti *header_rect)
{
const bool is_subpanel = panel->type->parent != NULL;
const bool is_subpanel = panel->type->parent != nullptr;
if (is_subpanel) {
return;
}
@ -1064,18 +1065,15 @@ static void panel_draw_highlight_border(const Panel *panel,
const float radius = (btheme->tui.panel_roundness * U.widget_unit * 0.5f) / aspect;
UI_draw_roundbox_corner_set(UI_CNR_ALL);
rctf box_rect;
box_rect.xmin = rect->xmin;
box_rect.xmax = rect->xmax;
box_rect.ymin = UI_panel_is_closed(panel) ? header_rect->ymin : rect->ymin;
box_rect.ymax = header_rect->ymax;
float color[4];
UI_GetThemeColor4fv(TH_SELECT_ACTIVE, color);
UI_draw_roundbox_4fv(
&(const rctf){
.xmin = rect->xmin,
.xmax = rect->xmax,
.ymin = UI_panel_is_closed(panel) ? header_rect->ymin : rect->ymin,
.ymax = header_rect->ymax,
},
false,
radius,
color);
UI_draw_roundbox_4fv(&box_rect, false, radius, color);
}
static void panel_draw_aligned_widgets(const uiStyle *style,
@ -1086,19 +1084,18 @@ static void panel_draw_aligned_widgets(const uiStyle *style,
const bool show_background,
const bool region_search_filter_active)
{
const bool is_subpanel = panel->type->parent != NULL;
const bool is_subpanel = panel->type->parent != nullptr;
const uiFontStyle *fontstyle = (is_subpanel) ? &style->widgetlabel : &style->paneltitle;
const int header_height = BLI_rcti_size_y(header_rect);
const int scaled_unit = round_fl_to_int(UI_UNIT_X / aspect);
/* Offset triangle and text to the right for subpanels. */
const rcti widget_rect = {
.xmin = header_rect->xmin + (is_subpanel ? scaled_unit * 0.7f : 0),
.xmax = header_rect->xmax,
.ymin = header_rect->ymin,
.ymax = header_rect->ymax,
};
rcti widget_rect;
widget_rect.xmin = header_rect->xmin + (is_subpanel ? scaled_unit * 0.7f : 0);
widget_rect.xmax = header_rect->xmax;
widget_rect.ymin = header_rect->ymin;
widget_rect.ymax = header_rect->ymax;
uchar title_color[4];
panel_title_color_get(panel, show_background, region_search_filter_active, title_color);
@ -1121,20 +1118,16 @@ static void panel_draw_aligned_widgets(const uiStyle *style,
/* Draw text label. */
if (panel->drawname[0] != '\0') {
const rcti title_rect = {
.xmin = widget_rect.xmin + (panel->labelofs / aspect) + scaled_unit * 1.1f,
.xmax = widget_rect.xmax,
.ymin = widget_rect.ymin - 2.0f / aspect,
.ymax = widget_rect.ymax,
};
UI_fontstyle_draw(fontstyle,
&title_rect,
panel->drawname,
sizeof(panel->drawname),
title_color,
&(struct uiFontStyleDraw_Params){
.align = UI_STYLE_TEXT_LEFT,
});
rcti title_rect;
title_rect.xmin = widget_rect.xmin + (panel->labelofs / aspect) + scaled_unit * 1.1f;
title_rect.xmax = widget_rect.xmax;
title_rect.ymin = widget_rect.ymin - 2.0f / aspect;
title_rect.ymax = widget_rect.ymax;
uiFontStyleDraw_Params params{};
params.align = UI_STYLE_TEXT_LEFT;
UI_fontstyle_draw(
fontstyle, &title_rect, panel->drawname, sizeof(panel->drawname), title_color, &params);
}
/* Draw the pin icon. */
@ -1177,7 +1170,7 @@ static void panel_draw_aligned_backdrop(const Panel *panel,
const rcti *rect,
const rcti *header_rect)
{
const bool is_subpanel = panel->type->parent != NULL;
const bool is_subpanel = panel->type->parent != nullptr;
const bool is_open = !UI_panel_is_closed(panel);
if (is_subpanel && !is_open) {
@ -1197,16 +1190,12 @@ static void panel_draw_aligned_backdrop(const Panel *panel,
UI_draw_roundbox_corner_set(is_open ? UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT : UI_CNR_ALL);
UI_GetThemeColor4fv((is_subpanel ? TH_PANEL_SUB_BACK : TH_PANEL_BACK), panel_backcolor);
UI_draw_roundbox_4fv(
&(const rctf){
.xmin = rect->xmin,
.xmax = rect->xmax,
.ymin = rect->ymin,
.ymax = rect->ymax,
},
true,
radius,
panel_backcolor);
rctf box_rect;
box_rect.xmin = rect->xmin;
box_rect.xmax = rect->xmax;
box_rect.ymin = rect->ymin;
box_rect.ymax = rect->ymax;
UI_draw_roundbox_4fv(&box_rect, true, radius, panel_backcolor);
}
/* Panel header backdrops for non sub-panels. */
@ -1217,16 +1206,12 @@ static void panel_draw_aligned_backdrop(const Panel *panel,
UI_draw_roundbox_corner_set(is_open ? UI_CNR_TOP_RIGHT | UI_CNR_TOP_LEFT : UI_CNR_ALL);
/* Change the width a little bit to line up with the sides. */
UI_draw_roundbox_4fv(
&(const rctf){
.xmin = rect->xmin,
.xmax = rect->xmax,
.ymin = header_rect->ymin,
.ymax = header_rect->ymax,
},
true,
radius,
panel_headercolor);
rctf box_rect;
box_rect.xmin = rect->xmin;
box_rect.xmax = rect->xmax;
box_rect.ymin = header_rect->ymin;
box_rect.ymax = header_rect->ymax;
UI_draw_roundbox_4fv(&box_rect, true, radius, panel_headercolor);
}
GPU_blend(GPU_BLEND_NONE);
@ -1247,7 +1232,7 @@ void ui_draw_aligned_panel(const uiStyle *style,
rect->xmin,
rect->xmax,
rect->ymax,
rect->ymax + floor(PNL_HEADER / block->aspect + 0.001f),
rect->ymax + (int)floor(PNL_HEADER / block->aspect + 0.001f),
};
if (show_background) {
@ -1300,7 +1285,7 @@ bool UI_panel_should_show_background(const ARegion *region, const PanelType *pan
void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
{
// #define USE_FLAT_INACTIVE
const bool is_left = RGN_ALIGN_ENUM_FROM_MASK(region->alignment != RGN_ALIGN_RIGHT);
const bool is_left = (bool)RGN_ALIGN_ENUM_FROM_MASK(region->alignment != RGN_ALIGN_RIGHT);
View2D *v2d = &region->v2d;
const uiStyle *style = UI_style_get();
const uiFontStyle *fstyle = &style->widget;
@ -1463,26 +1448,17 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
{
/* Draw filled rectangle and outline for tab. */
UI_draw_roundbox_corner_set(roundboxtype);
UI_draw_roundbox_4fv(
&(const rctf){
.xmin = rct->xmin,
.xmax = rct->xmax,
.ymin = rct->ymin,
.ymax = rct->ymax,
},
true,
tab_curve_radius,
is_active ? theme_col_tab_active : theme_col_tab_inactive);
UI_draw_roundbox_4fv(
&(const rctf){
.xmin = rct->xmin,
.xmax = rct->xmax,
.ymin = rct->ymin,
.ymax = rct->ymax,
},
false,
tab_curve_radius,
theme_col_tab_outline);
rctf box_rect;
box_rect.xmin = rct->xmin;
box_rect.xmax = rct->xmax;
box_rect.ymin = rct->ymin;
box_rect.ymax = rct->ymax;
UI_draw_roundbox_4fv(&box_rect,
true,
tab_curve_radius,
is_active ? theme_col_tab_active : theme_col_tab_inactive);
UI_draw_roundbox_4fv(&box_rect, false, tab_curve_radius, theme_col_tab_outline);
/* Disguise the outline on one side to join the tab to the panel. */
pos = GPU_vertformat_attr_add(
@ -1502,7 +1478,7 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
if (do_scaletabs) {
category_draw_len = BLF_width_to_strlen(
fontid, category_id_draw, category_draw_len, category_width, NULL);
fontid, category_id_draw, category_draw_len, category_width, nullptr);
}
BLF_position(fontid, rct->xmax - text_v_ofs, rct->ymin + tab_v_pad_text, 0.0f);
@ -1660,7 +1636,7 @@ static bool uiAlignPanelStep(ARegion *region, const float factor, const bool dra
LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->runtime_flag & PANEL_ACTIVE) {
/* These panels should have types since they are currently displayed to the user. */
BLI_assert(panel->type != NULL);
BLI_assert(panel->type != nullptr);
active_panels_len++;
}
}
@ -1669,7 +1645,8 @@ static bool uiAlignPanelStep(ARegion *region, const float factor, const bool dra
}
/* Sort panels. */
PanelSort *panel_sort = MEM_mallocN(sizeof(PanelSort) * active_panels_len, __func__);
PanelSort *panel_sort = static_cast<PanelSort *>(
MEM_mallocN(sizeof(PanelSort) * active_panels_len, __func__));
{
PanelSort *ps = panel_sort;
LISTBASE_FOREACH (Panel *, panel, &region->panels) {
@ -1791,7 +1768,7 @@ static void ui_panels_size(ARegion *region, int *r_x, int *r_y)
static void ui_do_animate(bContext *C, Panel *panel)
{
uiHandlePanelData *data = panel->activedata;
uiHandlePanelData *data = static_cast<uiHandlePanelData *>(panel->activedata);
ARegion *region = CTX_wm_region(C);
float fac = (PIL_check_seconds_timer() - data->starttime) / ANIMATION_TIME;
@ -1856,7 +1833,7 @@ void UI_panels_end(const bContext *C, ARegion *region, int *r_x, int *r_y)
LISTBASE_FOREACH (Panel *, panel, &region->panels) {
if (panel->runtime_flag & PANEL_ACTIVE) {
BLI_assert(panel->runtime.block != NULL);
BLI_assert(panel->runtime.block != nullptr);
panel_calculate_size_recursive(region, panel);
}
}
@ -1892,7 +1869,7 @@ void UI_panels_end(const bContext *C, ARegion *region, int *r_x, int *r_y)
#define DRAG_REGION_PAD (PNL_HEADER * 0.5)
static void ui_do_drag(const bContext *C, const wmEvent *event, Panel *panel)
{
uiHandlePanelData *data = panel->activedata;
uiHandlePanelData *data = static_cast<uiHandlePanelData *>(panel->activedata);
ARegion *region = CTX_wm_region(C);
/* Keep the drag position in the region with a small pad to keep the panel visible. */
@ -1942,14 +1919,14 @@ static uiPanelMouseState ui_panel_mouse_state_get(const uiBlock *block,
return PANEL_MOUSE_OUTSIDE;
}
typedef struct uiPanelDragCollapseHandle {
struct uiPanelDragCollapseHandle {
bool was_first_open;
int xy_init[2];
} uiPanelDragCollapseHandle;
};
static void ui_panel_drag_collapse_handler_remove(bContext *UNUSED(C), void *userdata)
{
uiPanelDragCollapseHandle *dragcol_data = userdata;
uiPanelDragCollapseHandle *dragcol_data = static_cast<uiPanelDragCollapseHandle *>(userdata);
MEM_freeN(dragcol_data);
}
@ -1960,11 +1937,11 @@ static void ui_panel_drag_collapse(const bContext *C,
ARegion *region = CTX_wm_region(C);
LISTBASE_FOREACH (uiBlock *, block, &region->uiblocks) {
float xy_a_block[2] = {UNPACK2(dragcol_data->xy_init)};
float xy_b_block[2] = {UNPACK2(xy_dst)};
float xy_a_block[2] = {(float)dragcol_data->xy_init[0], (float)dragcol_data->xy_init[1]};
float xy_b_block[2] = {(float)xy_dst[0], (float)xy_dst[1]};
Panel *panel = block->panel;
if (panel == NULL || (panel->type && (panel->type->flag & PANEL_TYPE_NO_HEADER))) {
if (panel == nullptr || (panel->type && (panel->type->flag & PANEL_TYPE_NO_HEADER))) {
continue;
}
const int oldflag = panel->flag;
@ -2006,7 +1983,7 @@ static void ui_panel_drag_collapse(const bContext *C,
static int ui_panel_drag_collapse_handler(bContext *C, const wmEvent *event, void *userdata)
{
wmWindow *win = CTX_wm_window(C);
uiPanelDragCollapseHandle *dragcol_data = userdata;
uiPanelDragCollapseHandle *dragcol_data = static_cast<uiPanelDragCollapseHandle *>(userdata);
short retval = WM_UI_HANDLER_CONTINUE;
switch (event->type) {
@ -2037,7 +2014,7 @@ static void ui_panel_drag_collapse_handler_add(const bContext *C, const bool was
{
wmWindow *win = CTX_wm_window(C);
const wmEvent *event = win->eventstate;
uiPanelDragCollapseHandle *dragcol_data = MEM_mallocN(sizeof(*dragcol_data), __func__);
uiPanelDragCollapseHandle *dragcol_data = MEM_new<uiPanelDragCollapseHandle>(__func__);
dragcol_data->was_first_open = was_open;
copy_v2_v2_int(dragcol_data->xy_init, event->xy);
@ -2066,10 +2043,10 @@ static void ui_handle_panel_header(const bContext *C,
Panel *panel = block->panel;
ARegion *region = CTX_wm_region(C);
BLI_assert(panel->type != NULL);
BLI_assert(panel->type != nullptr);
BLI_assert(!(panel->type->flag & PANEL_TYPE_NO_HEADER));
const bool is_subpanel = (panel->type->parent != NULL);
const bool is_subpanel = (panel->type->parent != nullptr);
const bool use_pin = UI_panel_category_is_visible(region) && UI_panel_can_be_pinned(panel);
const bool show_pin = use_pin && (panel->flag & PNL_PIN);
const bool show_drag = !is_subpanel;
@ -2102,8 +2079,8 @@ static void ui_handle_panel_header(const bContext *C,
else {
/* If a panel has sub-panels and it's open, toggle the expansion
* of the sub-panels (based on the expansion of the first sub-panel). */
Panel *first_child = panel->children.first;
BLI_assert(first_child != NULL);
Panel *first_child = static_cast<Panel *>(panel->children.first);
BLI_assert(first_child != nullptr);
panel_set_flag_recursive(panel, PNL_CLOSED, !UI_panel_is_closed(first_child));
panel->flag |= PNL_CLOSED;
}
@ -2157,13 +2134,14 @@ bool UI_panel_category_is_visible(const ARegion *region)
PanelCategoryDyn *UI_panel_category_find(const ARegion *region, const char *idname)
{
return BLI_findstring(&region->panels_category, idname, offsetof(PanelCategoryDyn, idname));
return static_cast<PanelCategoryDyn *>(
BLI_findstring(&region->panels_category, idname, offsetof(PanelCategoryDyn, idname)));
}
PanelCategoryStack *UI_panel_category_active_find(ARegion *region, const char *idname)
{
return BLI_findstring(
&region->panels_category_active, idname, offsetof(PanelCategoryStack, idname));
return static_cast<PanelCategoryStack *>(BLI_findstring(
&region->panels_category_active, idname, offsetof(PanelCategoryStack, idname)));
}
static void ui_panel_category_active_set(ARegion *region, const char *idname, bool fallback)
@ -2175,7 +2153,7 @@ static void ui_panel_category_active_set(ARegion *region, const char *idname, bo
BLI_remlink(lb, pc_act);
}
else {
pc_act = MEM_callocN(sizeof(PanelCategoryStack), __func__);
pc_act = MEM_cnew<PanelCategoryStack>(__func__);
BLI_strncpy(pc_act->idname, idname, sizeof(pc_act->idname));
}
@ -2226,14 +2204,14 @@ const char *UI_panel_category_active_get(ARegion *region, bool set_fallback)
}
if (set_fallback) {
PanelCategoryDyn *pc_dyn = region->panels_category.first;
PanelCategoryDyn *pc_dyn = static_cast<PanelCategoryDyn *>(region->panels_category.first);
if (pc_dyn) {
ui_panel_category_active_set(region, pc_dyn->idname, true);
return pc_dyn->idname;
}
}
return NULL;
return nullptr;
}
static PanelCategoryDyn *panel_categories_find_mouse_over(ARegion *region, const wmEvent *event)
@ -2244,12 +2222,12 @@ static PanelCategoryDyn *panel_categories_find_mouse_over(ARegion *region, const
}
}
return NULL;
return nullptr;
}
void UI_panel_category_add(ARegion *region, const char *name)
{
PanelCategoryDyn *pc_dyn = MEM_callocN(sizeof(*pc_dyn), __func__);
PanelCategoryDyn *pc_dyn = MEM_cnew<PanelCategoryDyn>(__func__);
BLI_addtail(&region->panels_category, pc_dyn);
BLI_strncpy(pc_dyn->idname, name, sizeof(pc_dyn->idname));
@ -2294,7 +2272,8 @@ static int ui_handle_panel_category_cycling(const wmEvent *event,
pc_dyn = backwards ? pc_dyn->prev : pc_dyn->next;
if (!pc_dyn) {
/* Proper cyclic behavior, back to first/last category (only used for ctrl+tab). */
pc_dyn = backwards ? region->panels_category.last : region->panels_category.first;
pc_dyn = backwards ? static_cast<PanelCategoryDyn *>(region->panels_category.last) :
static_cast<PanelCategoryDyn *>(region->panels_category.first);
}
}
@ -2359,11 +2338,11 @@ int ui_handler_panel_region(bContext *C,
return retval;
}
const bool region_has_active_button = (ui_region_find_active_but(region) != NULL);
const bool region_has_active_button = (ui_region_find_active_but(region) != nullptr);
LISTBASE_FOREACH (uiBlock *, block, &region->uiblocks) {
Panel *panel = block->panel;
if (panel == NULL || panel->type == NULL) {
if (panel == nullptr || panel->type == nullptr) {
continue;
}
/* We can't expand or collapse panels without headers, they would disappear. */
@ -2434,10 +2413,10 @@ void UI_panel_context_pointer_set(Panel *panel, const char *name, PointerRNA *pt
void UI_panel_custom_data_set(Panel *panel, PointerRNA *custom_data)
{
BLI_assert(panel->type != NULL);
BLI_assert(panel->type != nullptr);
/* Free the old custom data, which should be shared among all of the panel's sub-panels. */
if (panel->runtime.custom_data_ptr != NULL) {
if (panel->runtime.custom_data_ptr != nullptr) {
MEM_freeN(panel->runtime.custom_data_ptr);
}
@ -2455,7 +2434,7 @@ PointerRNA *UI_region_panel_custom_data_under_cursor(const bContext *C, const wm
LISTBASE_FOREACH (uiBlock *, block, &region->uiblocks) {
Panel *panel = block->panel;
if (panel == NULL) {
if (panel == nullptr) {
continue;
}
@ -2468,12 +2447,12 @@ PointerRNA *UI_region_panel_custom_data_under_cursor(const bContext *C, const wm
}
}
return NULL;
return nullptr;
}
bool UI_panel_can_be_pinned(const Panel *panel)
{
return (panel->type->parent == NULL) && !(panel->type->flag & PANEL_TYPE_INSTANCED);
return (panel->type->parent == nullptr) && !(panel->type->flag & PANEL_TYPE_INSTANCED);
}
/** \} */
@ -2485,8 +2464,8 @@ bool UI_panel_can_be_pinned(const Panel *panel)
/* NOTE: this is modal handler and should not swallow events for animation. */
static int ui_handler_panel(bContext *C, const wmEvent *event, void *userdata)
{
Panel *panel = userdata;
uiHandlePanelData *data = panel->activedata;
Panel *panel = static_cast<Panel *>(userdata);
uiHandlePanelData *data = static_cast<uiHandlePanelData *>(panel->activedata);
/* Verify if we can stop. */
if (event->type == LEFTMOUSE && event->val == KM_RELEASE) {
@ -2506,7 +2485,7 @@ static int ui_handler_panel(bContext *C, const wmEvent *event, void *userdata)
}
}
data = panel->activedata;
data = static_cast<uiHandlePanelData *>(panel->activedata);
if (data && data->state == PANEL_STATE_ANIMATION) {
return WM_UI_HANDLER_CONTINUE;
@ -2516,7 +2495,7 @@ static int ui_handler_panel(bContext *C, const wmEvent *event, void *userdata)
static void ui_handler_remove_panel(bContext *C, void *userdata)
{
Panel *panel = userdata;
Panel *panel = static_cast<Panel *>(userdata);
panel_activate_state(C, panel, PANEL_STATE_EXIT);
}
@ -2527,13 +2506,13 @@ static void panel_handle_data_ensure(const bContext *C,
Panel *panel,
const uiHandlePanelState state)
{
if (panel->activedata == NULL) {
if (panel->activedata == nullptr) {
panel->activedata = MEM_callocN(sizeof(uiHandlePanelData), __func__);
WM_event_add_ui_handler(
C, &win->modalhandlers, ui_handler_panel, ui_handler_remove_panel, panel, 0);
}
uiHandlePanelData *data = panel->activedata;
uiHandlePanelData *data = static_cast<uiHandlePanelData *>(panel->activedata);
data->animtimer = WM_event_add_timer(CTX_wm_manager(C), win, TIMER, ANIMATION_INTERVAL);
@ -2554,11 +2533,11 @@ static void panel_handle_data_ensure(const bContext *C,
*/
static void panel_activate_state(const bContext *C, Panel *panel, const uiHandlePanelState state)
{
uiHandlePanelData *data = panel->activedata;
uiHandlePanelData *data = static_cast<uiHandlePanelData *>(panel->activedata);
wmWindow *win = CTX_wm_window(C);
ARegion *region = CTX_wm_region(C);
if (data != NULL && data->state == state) {
if (data != nullptr && data->state == state) {
return;
}
@ -2582,15 +2561,15 @@ static void panel_activate_state(const bContext *C, Panel *panel, const uiHandle
else if (state == PANEL_STATE_EXIT) {
panel_set_runtime_flag_recursive(panel, PANEL_IS_DRAG_DROP, false);
BLI_assert(data != NULL);
BLI_assert(data != nullptr);
if (data->animtimer) {
WM_event_remove_timer(CTX_wm_manager(C), win, data->animtimer);
data->animtimer = NULL;
data->animtimer = nullptr;
}
MEM_freeN(data);
panel->activedata = NULL;
panel->activedata = nullptr;
WM_event_remove_ui_handler(
&win->modalhandlers, ui_handler_panel, ui_handler_remove_panel, panel, false);

View File

@ -7,14 +7,15 @@
* accessed via the #WM_OT_search_operator operator.
*/
#include <string.h>
#include <cstring>
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_texture_types.h"
#include "BLI_alloca.h"
#include "BLI_array.hh"
#include "BLI_ghash.h"
#include "BLI_math_vec_types.hh"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@ -35,10 +36,10 @@
static void operator_search_exec_fn(bContext *C, void *UNUSED(arg1), void *arg2)
{
wmOperatorType *ot = arg2;
wmOperatorType *ot = static_cast<wmOperatorType *>(arg2);
if (ot) {
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, NULL, NULL);
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, nullptr, nullptr);
}
}
@ -53,19 +54,20 @@ static void operator_search_update_fn(const bContext *C,
/* Prepare BLI_string_all_words_matched. */
const size_t str_len = strlen(str);
const int words_max = BLI_string_max_possible_word_count(str_len);
int(*words)[2] = BLI_array_alloca(words, words_max);
const int words_len = BLI_string_find_split_words(str, str_len, ' ', words, words_max);
blender::Array<blender::int2> words(words_max);
const int words_len = BLI_string_find_split_words(
str, str_len, ' ', (int(*)[2])words.data(), words_max);
for (WM_operatortype_iter(&iter); !BLI_ghashIterator_done(&iter);
BLI_ghashIterator_step(&iter)) {
wmOperatorType *ot = BLI_ghashIterator_getValue(&iter);
wmOperatorType *ot = static_cast<wmOperatorType *>(BLI_ghashIterator_getValue(&iter));
const char *ot_ui_name = CTX_IFACE_(ot->translation_context, ot->name);
if ((ot->flag & OPTYPE_INTERNAL) && (G.debug & G_DEBUG_WM) == 0) {
continue;
}
if (BLI_string_all_words_matched(ot_ui_name, str, words, words_len)) {
if (BLI_string_all_words_matched(ot_ui_name, str, (int(*)[2])words.data(), words_len)) {
if (WM_operator_poll((bContext *)C, ot)) {
char name[256];
const int len = strlen(ot_ui_name);
@ -78,7 +80,7 @@ static void operator_search_update_fn(const bContext *C,
if (WM_key_event_operator_string(C,
ot->idname,
WM_OP_EXEC_DEFAULT,
NULL,
nullptr,
true,
&name[len + 1],
sizeof(name) - len - 1)) {
@ -105,11 +107,11 @@ void UI_but_func_operator_search(uiBut *but)
UI_but_func_search_set(but,
ui_searchbox_create_operator,
operator_search_update_fn,
NULL,
nullptr,
false,
NULL,
nullptr,
operator_search_exec_fn,
NULL);
nullptr);
}
void uiTemplateOperatorSearch(uiLayout *layout)

View File

@ -7,7 +7,7 @@
* Undo stack to use for UI widgets that manage their own editing state.
*/
#include <string.h>
#include <cstring>
#include "BLI_listbase.h"
@ -21,39 +21,39 @@
/** \name Text Field Undo Stack
* \{ */
typedef struct uiUndoStack_Text_State {
struct uiUndoStack_Text_State {
struct uiUndoStack_Text_State *next, *prev;
int cursor_index;
char text[0];
} uiUndoStack_Text_State;
};
typedef struct uiUndoStack_Text {
struct uiUndoStack_Text {
ListBase states;
uiUndoStack_Text_State *current;
} uiUndoStack_Text;
};
static const char *ui_textedit_undo_impl(uiUndoStack_Text *stack, int *r_cursor_index)
{
/* Don't undo if no data has been pushed yet. */
if (stack->current == NULL) {
return NULL;
if (stack->current == nullptr) {
return nullptr;
}
/* Travel backwards in the stack and copy information to the caller. */
if (stack->current->prev != NULL) {
if (stack->current->prev != nullptr) {
stack->current = stack->current->prev;
*r_cursor_index = stack->current->cursor_index;
return stack->current->text;
}
return NULL;
return nullptr;
}
static const char *ui_textedit_redo_impl(uiUndoStack_Text *stack, int *r_cursor_index)
{
/* Don't redo if no data has been pushed yet. */
if (stack->current == NULL) {
return NULL;
if (stack->current == nullptr) {
return nullptr;
}
/* Only redo if new data has not been entered since the last undo. */
@ -63,7 +63,7 @@ static const char *ui_textedit_redo_impl(uiUndoStack_Text *stack, int *r_cursor_
*r_cursor_index = stack->current->cursor_index;
return stack->current->text;
}
return NULL;
return nullptr;
}
const char *ui_textedit_undo(uiUndoStack_Text *stack, int direction, int *r_cursor_index)
@ -78,7 +78,7 @@ const char *ui_textedit_undo(uiUndoStack_Text *stack, int direction, int *r_curs
void ui_textedit_undo_push(uiUndoStack_Text *stack, const char *text, int cursor_index)
{
/* Clear all redo actions from the current state. */
if (stack->current != NULL) {
if (stack->current != nullptr) {
while (stack->current->next) {
uiUndoStack_Text_State *state = stack->current->next;
BLI_remlink(&stack->states, state);
@ -88,7 +88,8 @@ void ui_textedit_undo_push(uiUndoStack_Text *stack, const char *text, int cursor
/* Create the new state. */
const int text_size = strlen(text) + 1;
stack->current = MEM_mallocN(sizeof(uiUndoStack_Text_State) + text_size, __func__);
stack->current = static_cast<uiUndoStack_Text_State *>(
MEM_mallocN(sizeof(uiUndoStack_Text_State) + text_size, __func__));
stack->current->cursor_index = cursor_index;
memcpy(stack->current->text, text, text_size);
BLI_addtail(&stack->states, stack->current);
@ -96,8 +97,8 @@ void ui_textedit_undo_push(uiUndoStack_Text *stack, const char *text, int cursor
uiUndoStack_Text *ui_textedit_undo_stack_create(void)
{
uiUndoStack_Text *stack = MEM_mallocN(sizeof(uiUndoStack_Text), __func__);
stack->current = NULL;
uiUndoStack_Text *stack = MEM_new<uiUndoStack_Text>(__func__);
stack->current = nullptr;
BLI_listbase_clear(&stack->states);
return stack;

View File

@ -1223,12 +1223,12 @@ static VertSeam *find_adjacent_seam(const ProjPaintState *ps,
/* Circulate through the (sorted) vert seam array, in the direction of the seam normal,
* until we find the first opposing seam, matching in UV space. */
if (seam->normal_cw) {
LISTBASE_CIRCULAR_BACKWARD_BEGIN (vert_seams, adjacent, seam) {
LISTBASE_CIRCULAR_BACKWARD_BEGIN (VertSeam *, vert_seams, adjacent, seam) {
if ((adjacent->normal_cw != seam->normal_cw) && cmp_uv(adjacent->uv, seam->uv)) {
break;
}
}
LISTBASE_CIRCULAR_BACKWARD_END(vert_seams, adjacent, seam);
LISTBASE_CIRCULAR_BACKWARD_END(VertSeam *, vert_seams, adjacent, seam);
}
else {
LISTBASE_CIRCULAR_FORWARD_BEGIN (vert_seams, adjacent, seam) {