2020-06-05 10:41:03 -04:00
|
|
|
/* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \ingroup modifiers
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "BLI_listbase.h"
|
2020-10-19 09:17:41 -05:00
|
|
|
#include "BLI_string.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_modifier.h"
|
|
|
|
#include "BKE_object.h"
|
|
|
|
#include "BKE_screen.h"
|
|
|
|
|
|
|
|
#include "DNA_object_force_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_particle_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
|
|
|
#include "ED_object.h"
|
|
|
|
|
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "MOD_modifiertypes.h"
|
|
|
|
#include "MOD_ui_common.h" /* Self include */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Poll function so these modifier panels don't show for other object types with modifiers (only
|
|
|
|
* grease pencil currently).
|
|
|
|
*/
|
|
|
|
static bool modifier_ui_poll(const bContext *C, PanelType *UNUSED(pt))
|
|
|
|
{
|
2020-07-03 11:58:43 -04:00
|
|
|
Object *ob = ED_object_active_context(C);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
return (ob != NULL) && (ob->type != OB_GPENCIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Panel Drag and Drop, Expansion Saving
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move a modifier to the index it's moved to after a drag and drop.
|
|
|
|
*/
|
|
|
|
static void modifier_reorder(bContext *C, Panel *panel, int new_index)
|
|
|
|
{
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *md_ptr = UI_panel_custom_data_get(panel);
|
|
|
|
ModifierData *md = (ModifierData *)md_ptr->data;
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
PointerRNA props_ptr;
|
|
|
|
wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_modifier_move_to_index", false);
|
|
|
|
WM_operator_properties_create_ptr(&props_ptr, ot);
|
|
|
|
RNA_string_set(&props_ptr, "modifier", md->name);
|
|
|
|
RNA_int_set(&props_ptr, "index", new_index);
|
|
|
|
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr);
|
|
|
|
WM_operator_properties_free(&props_ptr);
|
|
|
|
}
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
static short get_modifier_expand_flag(const bContext *UNUSED(C), Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *md_ptr = UI_panel_custom_data_get(panel);
|
|
|
|
ModifierData *md = (ModifierData *)md_ptr->data;
|
2020-06-05 10:41:03 -04:00
|
|
|
return md->ui_expand_flag;
|
|
|
|
}
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
static void set_modifier_expand_flag(const bContext *UNUSED(C), Panel *panel, short expand_flag)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *md_ptr = UI_panel_custom_data_get(panel);
|
|
|
|
ModifierData *md = (ModifierData *)md_ptr->data;
|
2020-06-05 10:41:03 -04:00
|
|
|
md->ui_expand_flag = expand_flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Modifier Panel Layouts
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw modifier error message.
|
|
|
|
*/
|
|
|
|
void modifier_panel_end(uiLayout *layout, PointerRNA *ptr)
|
|
|
|
{
|
|
|
|
ModifierData *md = ptr->data;
|
|
|
|
if (md->error) {
|
|
|
|
uiLayout *row = uiLayoutRow(layout, false);
|
|
|
|
uiItemL(row, IFACE_(md->error), ICON_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets RNA pointers for the active object and the panel's modifier data. Also locks
|
2020-06-25 23:13:02 +10:00
|
|
|
* the layout if the modifier is from a linked object, and sets the context pointer.
|
2020-09-02 14:13:26 -05:00
|
|
|
*
|
|
|
|
* \note The modifier #PointerRNA is owned by the panel so we only need a pointer to it.
|
2020-06-05 10:41:03 -04:00
|
|
|
*/
|
|
|
|
#define ERROR_LIBDATA_MESSAGE TIP_("External library data")
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *ptr = UI_panel_custom_data_get(panel);
|
|
|
|
BLI_assert(!RNA_pointer_is_null(ptr));
|
|
|
|
BLI_assert(RNA_struct_is_a(ptr->type, &RNA_Modifier));
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
if (r_ob_ptr != NULL) {
|
2020-09-02 14:13:26 -05:00
|
|
|
RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id, r_ob_ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uiBlock *block = uiLayoutGetBlock(panel->layout);
|
2020-09-02 14:13:26 -05:00
|
|
|
UI_block_lock_set(block, ID_IS_LINKED((Object *)ptr->owner_id), ERROR_LIBDATA_MESSAGE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
uiLayoutSetContextPointer(panel->layout, "modifier", ptr);
|
|
|
|
|
|
|
|
return ptr;
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for modifier layouts to draw vertex group settings.
|
|
|
|
*/
|
|
|
|
void modifier_vgroup_ui(uiLayout *layout,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PointerRNA *ob_ptr,
|
|
|
|
const char *vgroup_prop,
|
|
|
|
const char *invert_vgroup_prop,
|
|
|
|
const char *text)
|
|
|
|
{
|
|
|
|
bool has_vertex_group = RNA_string_length(ptr, vgroup_prop) != 0;
|
|
|
|
|
|
|
|
uiLayout *row = uiLayoutRow(layout, true);
|
|
|
|
uiItemPointerR(row, ptr, vgroup_prop, ob_ptr, "vertex_groups", text, ICON_NONE);
|
|
|
|
if (invert_vgroup_prop != NULL) {
|
|
|
|
uiLayout *sub = uiLayoutRow(row, true);
|
|
|
|
uiLayoutSetActive(sub, has_vertex_group);
|
|
|
|
uiLayoutSetPropDecorate(sub, false);
|
|
|
|
uiItemR(sub, ptr, invert_vgroup_prop, 0, "", ICON_ARROW_LEFTRIGHT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether Modifier is a simulation or not. Used for switching to the
|
|
|
|
* physics/particles context tab.
|
|
|
|
*/
|
|
|
|
static int modifier_is_simulation(ModifierData *md)
|
|
|
|
{
|
|
|
|
/* Physic Tab */
|
|
|
|
if (ELEM(md->type,
|
|
|
|
eModifierType_Cloth,
|
|
|
|
eModifierType_Collision,
|
|
|
|
eModifierType_Fluidsim,
|
|
|
|
eModifierType_Fluid,
|
|
|
|
eModifierType_Softbody,
|
|
|
|
eModifierType_Surface,
|
|
|
|
eModifierType_DynamicPaint)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* Particle Tab */
|
2020-08-07 12:40:29 +02:00
|
|
|
if (md->type == eModifierType_ParticleSystem) {
|
2020-06-05 10:41:03 -04:00
|
|
|
return 2;
|
|
|
|
}
|
2020-08-07 12:40:29 +02:00
|
|
|
|
|
|
|
return 0;
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool modifier_can_delete(ModifierData *md)
|
|
|
|
{
|
|
|
|
/* fluid particle modifier can't be deleted here */
|
|
|
|
if (md->type == eModifierType_ParticleSystem) {
|
|
|
|
short particle_type = ((ParticleSystemModifierData *)md)->psys->part->type;
|
|
|
|
if (ELEM(particle_type,
|
|
|
|
PART_FLUID,
|
|
|
|
PART_FLUID_FLIP,
|
|
|
|
PART_FLUID_FOAM,
|
|
|
|
PART_FLUID_SPRAY,
|
|
|
|
PART_FLUID_BUBBLE,
|
|
|
|
PART_FLUID_TRACER,
|
|
|
|
PART_FLUID_SPRAYFOAM,
|
|
|
|
PART_FLUID_SPRAYBUBBLE,
|
|
|
|
PART_FLUID_FOAMBUBBLE,
|
|
|
|
PART_FLUID_SPRAYFOAMBUBBLE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-17 14:09:17 -04:00
|
|
|
static void modifier_ops_extra_draw(bContext *C, uiLayout *layout, void *md_v)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
2020-06-17 14:09:17 -04:00
|
|
|
PointerRNA op_ptr;
|
|
|
|
uiLayout *row;
|
2020-06-05 10:41:03 -04:00
|
|
|
ModifierData *md = (ModifierData *)md_v;
|
|
|
|
|
2020-06-17 14:09:17 -04:00
|
|
|
PointerRNA ptr;
|
2020-07-03 11:58:43 -04:00
|
|
|
Object *ob = ED_object_active_context(C);
|
2020-06-17 14:09:17 -04:00
|
|
|
RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr);
|
|
|
|
uiLayoutSetContextPointer(layout, "modifier", &ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
|
|
|
|
|
2020-06-17 14:09:17 -04:00
|
|
|
uiLayoutSetUnitsX(layout, 4.0f);
|
|
|
|
|
|
|
|
/* Apply. */
|
2020-07-02 08:26:59 -04:00
|
|
|
uiItemO(layout,
|
|
|
|
CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Apply"),
|
|
|
|
ICON_CHECKMARK,
|
|
|
|
"OBJECT_OT_modifier_apply");
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-06-17 14:09:17 -04:00
|
|
|
/* Apply as shapekey. */
|
2020-06-05 10:41:03 -04:00
|
|
|
if (BKE_modifier_is_same_topology(md) && !BKE_modifier_is_non_geometrical(md)) {
|
2020-07-01 17:38:07 +03:00
|
|
|
uiItemBooleanO(layout,
|
2020-10-24 11:42:17 -07:00
|
|
|
CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Apply as Shape Key"),
|
2020-07-01 17:38:07 +03:00
|
|
|
ICON_SHAPEKEY_DATA,
|
|
|
|
"OBJECT_OT_modifier_apply_as_shapekey",
|
|
|
|
"keep_modifier",
|
|
|
|
false);
|
|
|
|
|
|
|
|
uiItemBooleanO(layout,
|
2020-10-24 11:42:17 -07:00
|
|
|
CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Save as Shape Key"),
|
2020-07-01 17:38:07 +03:00
|
|
|
ICON_SHAPEKEY_DATA,
|
|
|
|
"OBJECT_OT_modifier_apply_as_shapekey",
|
|
|
|
"keep_modifier",
|
|
|
|
true);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
2020-06-17 14:09:17 -04:00
|
|
|
/* Duplicate. */
|
2020-06-05 10:41:03 -04:00
|
|
|
if (!ELEM(md->type,
|
|
|
|
eModifierType_Fluidsim,
|
|
|
|
eModifierType_Softbody,
|
|
|
|
eModifierType_ParticleSystem,
|
|
|
|
eModifierType_Cloth,
|
|
|
|
eModifierType_Fluid)) {
|
|
|
|
uiItemO(layout,
|
|
|
|
CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Duplicate"),
|
|
|
|
ICON_DUPLICATE,
|
|
|
|
"OBJECT_OT_modifier_copy");
|
|
|
|
}
|
2020-06-17 14:09:17 -04:00
|
|
|
|
2020-12-28 11:17:49 -06:00
|
|
|
uiItemO(layout,
|
|
|
|
CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Copy to Selected"),
|
|
|
|
0,
|
|
|
|
"OBJECT_OT_modifier_copy_to_selected");
|
|
|
|
|
2020-06-17 14:09:17 -04:00
|
|
|
uiItemS(layout);
|
|
|
|
|
|
|
|
/* Move to first. */
|
|
|
|
row = uiLayoutColumn(layout, false);
|
|
|
|
uiItemFullO(row,
|
|
|
|
"OBJECT_OT_modifier_move_to_index",
|
|
|
|
IFACE_("Move to First"),
|
|
|
|
ICON_TRIA_UP,
|
|
|
|
NULL,
|
2020-06-17 14:43:48 -04:00
|
|
|
WM_OP_INVOKE_DEFAULT,
|
2020-06-17 14:09:17 -04:00
|
|
|
0,
|
|
|
|
&op_ptr);
|
|
|
|
RNA_int_set(&op_ptr, "index", 0);
|
|
|
|
if (!md->prev) {
|
|
|
|
uiLayoutSetEnabled(row, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to last. */
|
|
|
|
row = uiLayoutColumn(layout, false);
|
|
|
|
uiItemFullO(row,
|
|
|
|
"OBJECT_OT_modifier_move_to_index",
|
|
|
|
IFACE_("Move to Last"),
|
|
|
|
ICON_TRIA_DOWN,
|
|
|
|
NULL,
|
2020-06-17 14:43:48 -04:00
|
|
|
WM_OP_INVOKE_DEFAULT,
|
2020-06-17 14:09:17 -04:00
|
|
|
0,
|
|
|
|
&op_ptr);
|
|
|
|
RNA_int_set(&op_ptr, "index", BLI_listbase_count(&ob->modifiers) - 1);
|
|
|
|
if (!md->next) {
|
|
|
|
uiLayoutSetEnabled(row, false);
|
|
|
|
}
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void modifier_panel_header(const bContext *C, Panel *panel)
|
|
|
|
{
|
2020-06-17 13:51:33 -04:00
|
|
|
uiLayout *row, *sub, *name_row;
|
2020-06-05 10:41:03 -04:00
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
|
|
/* Don't use #modifier_panel_get_property_pointers, we don't want to lock the header. */
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *ptr = UI_panel_custom_data_get(panel);
|
|
|
|
ModifierData *md = (ModifierData *)ptr->data;
|
|
|
|
Object *ob = (Object *)ptr->owner_id;
|
|
|
|
|
|
|
|
uiLayoutSetContextPointer(panel->layout, "modifier", ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2020-09-02 14:13:26 -05:00
|
|
|
int index = BLI_findindex(&ob->modifiers, md);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
/* Modifier Icon. */
|
2020-06-17 13:51:33 -04:00
|
|
|
sub = uiLayoutRow(layout, true);
|
2020-12-13 23:49:14 -06:00
|
|
|
uiLayoutSetEmboss(sub, UI_EMBOSS_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
if (mti->isDisabled && mti->isDisabled(scene, md, 0)) {
|
2020-06-17 13:51:33 -04:00
|
|
|
uiLayoutSetRedAlert(sub, true);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
2020-12-13 23:49:14 -06:00
|
|
|
uiItemStringO(sub,
|
|
|
|
"",
|
|
|
|
RNA_struct_ui_icon(ptr->type),
|
|
|
|
"OBJECT_OT_modifier_set_active",
|
|
|
|
"modifier",
|
|
|
|
md->name);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-06-17 13:51:33 -04:00
|
|
|
row = uiLayoutRow(layout, true);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-06-17 13:51:33 -04:00
|
|
|
/* Modifier Name.
|
|
|
|
* Count how many buttons are added to the header to check if there is enough space. */
|
|
|
|
int buttons_number = 0;
|
|
|
|
name_row = uiLayoutRow(row, true);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-06-17 13:51:33 -04:00
|
|
|
/* Display mode switching buttons. */
|
2020-06-05 10:41:03 -04:00
|
|
|
if (ob->type == OB_MESH) {
|
|
|
|
int last_cage_index;
|
|
|
|
int cage_index = BKE_modifiers_get_cage_index(scene, ob, &last_cage_index, 0);
|
|
|
|
if (BKE_modifier_supports_cage(scene, md) && (index <= last_cage_index)) {
|
|
|
|
sub = uiLayoutRow(row, true);
|
|
|
|
if (index < cage_index || !BKE_modifier_couldbe_cage(scene, md)) {
|
|
|
|
uiLayoutSetActive(sub, false);
|
|
|
|
}
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(sub, ptr, "show_on_cage", 0, "", ICON_NONE);
|
2020-06-17 13:51:33 -04:00
|
|
|
buttons_number++;
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
} /* Tessellation point for curve-typed objects. */
|
|
|
|
else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
|
2021-04-20 13:46:31 +02:00
|
|
|
/* Some modifiers can work with pre-tessellated curves only. */
|
|
|
|
if (ELEM(md->type, eModifierType_Hook, eModifierType_Softbody, eModifierType_MeshDeform)) {
|
|
|
|
/* Add button (appearing to be ON) and add tip why this cant be changed. */
|
|
|
|
sub = uiLayoutRow(row, true);
|
|
|
|
uiBlock *block = uiLayoutGetBlock(sub);
|
|
|
|
static int apply_on_spline_always_on_hack = eModifierMode_ApplyOnSpline;
|
|
|
|
uiBut *but = uiDefIconButBitI(block,
|
|
|
|
UI_BTYPE_TOGGLE,
|
|
|
|
eModifierMode_ApplyOnSpline,
|
|
|
|
0,
|
|
|
|
ICON_SURFACE_DATA,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
UI_UNIT_X - 2,
|
|
|
|
UI_UNIT_Y,
|
|
|
|
&apply_on_spline_always_on_hack,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
TIP_("Apply on Spline"));
|
|
|
|
UI_but_disable(
|
|
|
|
but, TIP_("This modifier can only deform control points, not the filled curve/surface"));
|
|
|
|
buttons_number++;
|
|
|
|
}
|
|
|
|
else if (mti->type != eModifierTypeType_Constructive) {
|
2020-06-05 10:41:03 -04:00
|
|
|
/* Constructive modifiers tessellates curve before applying. */
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(row, ptr, "use_apply_on_spline", 0, "", ICON_NONE);
|
2020-06-17 13:51:33 -04:00
|
|
|
buttons_number++;
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Collision and Surface are always enabled, hide buttons. */
|
2021-04-11 14:43:05 +10:00
|
|
|
if (!ELEM(md->type, eModifierType_Collision, eModifierType_Surface)) {
|
2020-06-05 10:41:03 -04:00
|
|
|
if (mti->flags & eModifierTypeFlag_SupportsEditmode) {
|
|
|
|
sub = uiLayoutRow(row, true);
|
|
|
|
uiLayoutSetActive(sub, (md->mode & eModifierMode_Realtime));
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(sub, ptr, "show_in_editmode", 0, "", ICON_NONE);
|
2020-06-17 13:51:33 -04:00
|
|
|
buttons_number++;
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(row, ptr, "show_viewport", 0, "", ICON_NONE);
|
|
|
|
uiItemR(row, ptr, "show_render", 0, "", ICON_NONE);
|
2020-06-17 13:51:33 -04:00
|
|
|
buttons_number += 2;
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
2020-06-17 13:51:33 -04:00
|
|
|
/* Extra operators menu. */
|
2020-06-05 10:41:03 -04:00
|
|
|
uiItemMenuF(row, "", ICON_DOWNARROW_HLT, modifier_ops_extra_draw, md);
|
|
|
|
|
2020-06-17 13:51:33 -04:00
|
|
|
/* Delete button. */
|
|
|
|
if (modifier_can_delete(md) && !modifier_is_simulation(md)) {
|
|
|
|
sub = uiLayoutRow(row, false);
|
|
|
|
uiLayoutSetEmboss(sub, UI_EMBOSS_NONE);
|
2020-06-29 15:06:13 -04:00
|
|
|
uiItemO(sub, "", ICON_X, "OBJECT_OT_modifier_remove");
|
2020-06-17 13:51:33 -04:00
|
|
|
buttons_number++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Switch context buttons. */
|
|
|
|
if (modifier_is_simulation(md) == 1) {
|
|
|
|
uiItemStringO(
|
|
|
|
row, "", ICON_PROPERTIES, "WM_OT_properties_context_change", "context", "PHYSICS");
|
|
|
|
buttons_number++;
|
|
|
|
}
|
|
|
|
else if (modifier_is_simulation(md) == 2) {
|
|
|
|
uiItemStringO(
|
|
|
|
row, "", ICON_PROPERTIES, "WM_OT_properties_context_change", "context", "PARTICLES");
|
|
|
|
buttons_number++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool display_name = (panel->sizex / UI_UNIT_X - buttons_number > 5) || (panel->sizex == 0);
|
|
|
|
if (display_name) {
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(name_row, ptr, "name", 0, "", ICON_NONE);
|
2020-06-17 13:51:33 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extra padding for delete button. */
|
2020-06-05 10:41:03 -04:00
|
|
|
uiItemS(layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Modifier Registration Helpers
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a panel in the context's region
|
|
|
|
*/
|
|
|
|
PanelType *modifier_panel_register(ARegionType *region_type, ModifierType type, PanelDrawFn draw)
|
|
|
|
{
|
2021-03-09 13:31:51 -05:00
|
|
|
PanelType *panel_type = MEM_callocN(sizeof(PanelType), __func__);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2021-03-09 13:31:51 -05:00
|
|
|
BKE_modifier_type_panel_id(type, panel_type->idname);
|
2020-10-19 09:17:41 -05:00
|
|
|
BLI_strncpy(panel_type->label, "", BKE_ST_MAXNAME);
|
|
|
|
BLI_strncpy(panel_type->context, "modifier", BKE_ST_MAXNAME);
|
|
|
|
BLI_strncpy(panel_type->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA, BKE_ST_MAXNAME);
|
2020-11-30 17:43:14 -05:00
|
|
|
BLI_strncpy(panel_type->active_property, "is_active", BKE_ST_MAXNAME);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
panel_type->draw_header = modifier_panel_header;
|
|
|
|
panel_type->draw = draw;
|
|
|
|
panel_type->poll = modifier_ui_poll;
|
|
|
|
|
|
|
|
/* Give the panel the special flag that says it was built here and corresponds to a
|
2020-06-30 20:54:31 +10:00
|
|
|
* modifier rather than a #PanelType. */
|
2020-11-13 13:56:55 -05:00
|
|
|
panel_type->flag = PANEL_TYPE_HEADER_EXPAND | PANEL_TYPE_DRAW_BOX | PANEL_TYPE_INSTANCED;
|
2020-06-05 10:41:03 -04:00
|
|
|
panel_type->reorder = modifier_reorder;
|
|
|
|
panel_type->get_list_data_expand_flag = get_modifier_expand_flag;
|
|
|
|
panel_type->set_list_data_expand_flag = set_modifier_expand_flag;
|
|
|
|
|
|
|
|
BLI_addtail(®ion_type->paneltypes, panel_type);
|
|
|
|
|
|
|
|
return panel_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-19 16:11:15 -04:00
|
|
|
* Add a child panel to the parent.
|
2020-06-05 10:41:03 -04:00
|
|
|
*
|
|
|
|
* \note To create the panel type's idname, it appends the \a name argument to the \a parent's
|
|
|
|
* idname.
|
|
|
|
*/
|
|
|
|
PanelType *modifier_subpanel_register(ARegionType *region_type,
|
|
|
|
const char *name,
|
|
|
|
const char *label,
|
|
|
|
PanelDrawFn draw_header,
|
|
|
|
PanelDrawFn draw,
|
|
|
|
PanelType *parent)
|
|
|
|
{
|
2021-03-09 13:31:51 -05:00
|
|
|
PanelType *panel_type = MEM_callocN(sizeof(PanelType), __func__);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2021-03-09 13:31:51 -05:00
|
|
|
BLI_snprintf(panel_type->idname, BKE_ST_MAXNAME, "%s_%s", parent->idname, name);
|
2020-10-19 09:17:41 -05:00
|
|
|
BLI_strncpy(panel_type->label, label, BKE_ST_MAXNAME);
|
|
|
|
BLI_strncpy(panel_type->context, "modifier", BKE_ST_MAXNAME);
|
|
|
|
BLI_strncpy(panel_type->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA, BKE_ST_MAXNAME);
|
2021-01-22 11:08:58 -06:00
|
|
|
BLI_strncpy(panel_type->active_property, "is_active", BKE_ST_MAXNAME);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
panel_type->draw_header = draw_header;
|
|
|
|
panel_type->draw = draw;
|
|
|
|
panel_type->poll = modifier_ui_poll;
|
2020-11-13 13:56:55 -05:00
|
|
|
panel_type->flag = (PANEL_TYPE_DEFAULT_CLOSED | PANEL_TYPE_DRAW_BOX);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
BLI_assert(parent != NULL);
|
2020-10-19 09:17:41 -05:00
|
|
|
BLI_strncpy(panel_type->parent_id, parent->idname, BKE_ST_MAXNAME);
|
2020-06-05 10:41:03 -04:00
|
|
|
panel_type->parent = parent;
|
|
|
|
BLI_addtail(&parent->children, BLI_genericNodeN(panel_type));
|
|
|
|
BLI_addtail(®ion_type->paneltypes, panel_type);
|
|
|
|
|
|
|
|
return panel_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|