Files
test2/source/blender/editors/interface/templates/interface_template_modifiers.cc
Jonas Holzman 8a855f9cbd UI: Refactor templates into individual files
This PR refactors each UI template into its own `interface_template_*.cc`
file.

* Added `interface_templates_intern.hh` which exposes shared utility
  functions and macros.
* Doxygen comment sections that were redundant of the file name were
  removed. If they contained additional description, they were added
  to the file Doxygen `\file` header.
* Short templates that were closely related were kept together in single
  files (e.g `uiTemplateHistogram`, `uiTemplateWaveform` and
  `uiTemplateVectorScope` are all in `interface_template_scopes.cc`).
  In this case, Doxygen comment section were preserved.

The only things remaining in `interface_templates.cc` are:
* Common utility function exposed by `interface_templates_intern.hh`
* Small independent templates (`uiTemplatePathBuilder`,
  `uiTemplateNodeSocket` and `uiTemplateFileSelectPath`)

Ref: https://projects.blender.org/blender/blender/issues/117604
Pull Request: https://projects.blender.org/blender/blender/pulls/132468
2025-01-07 16:21:07 +01:00

81 lines
2.4 KiB
C++

/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup edinterface
*
* Template for building the panel layout for the active object's modifiers.
*/
#include "BKE_context.hh"
#include "BKE_modifier.hh"
#include "BKE_screen.hh"
#include "BLI_listbase.h"
#include "ED_object.hh"
#include "RNA_access.hh"
#include "RNA_prototypes.hh"
#include "UI_interface.hh"
static void modifier_panel_id(void *md_link, char *r_name)
{
ModifierData *md = (ModifierData *)md_link;
BKE_modifier_type_panel_id(ModifierType(md->type), r_name);
}
void uiTemplateModifiers(uiLayout * /*layout*/, bContext *C)
{
ARegion *region = CTX_wm_region(C);
Object *ob = blender::ed::object::context_active_object(C);
ListBase *modifiers = &ob->modifiers;
const bool panels_match = UI_panel_list_matches_data(region, modifiers, modifier_panel_id);
if (!panels_match) {
UI_panels_free_instanced(C, region);
LISTBASE_FOREACH (ModifierData *, md, modifiers) {
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
if (mti->panel_register == nullptr) {
continue;
}
char panel_idname[MAX_NAME];
modifier_panel_id(md, panel_idname);
/* Create custom data RNA pointer. */
PointerRNA *md_ptr = MEM_new<PointerRNA>(__func__);
*md_ptr = RNA_pointer_create(&ob->id, &RNA_Modifier, md);
UI_panel_add_instanced(C, region, &region->panels, panel_idname, md_ptr);
}
}
else {
/* Assuming there's only one group of instanced panels, update the custom data pointers. */
Panel *panel = static_cast<Panel *>(region->panels.first);
LISTBASE_FOREACH (ModifierData *, md, modifiers) {
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
if (mti->panel_register == nullptr) {
continue;
}
/* Move to the next instanced panel corresponding to the next modifier. */
while ((panel->type == nullptr) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) {
panel = panel->next;
BLI_assert(panel !=
nullptr); /* There shouldn't be fewer panels than modifiers with UIs. */
}
PointerRNA *md_ptr = MEM_new<PointerRNA>(__func__);
*md_ptr = RNA_pointer_create(&ob->id, &RNA_Modifier, md);
UI_panel_custom_data_set(panel, md_ptr);
panel = panel->next;
}
}
}