diff options
Diffstat (limited to 'source/blender/editors')
388 files changed, 18253 insertions, 12580 deletions
diff --git a/source/blender/editors/animation/CMakeLists.txt b/source/blender/editors/animation/CMakeLists.txt index b67298a6df6..978bd772b6f 100644 --- a/source/blender/editors/animation/CMakeLists.txt +++ b/source/blender/editors/animation/CMakeLists.txt @@ -26,8 +26,8 @@ set(INC ../../makesrna ../../windowmanager ../../../../intern/clog - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index 78c17ac7015..6d1ee08d5e9 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -222,7 +222,8 @@ static void acf_generic_channel_color(bAnimContext *ac, bAnimListElem *ale, floa rgb_uchar_to_float(r_color, cp); } else { - // FIXME: what happens when the indention is 1 greater than what it should be (due to grouping)? + /* FIXME: what happens when the indention is 1 greater than what it should be + * (due to grouping)? */ int colOfs = 10 - 10 * indent; UI_GetThemeColorShade3fv(TH_SHADE2, colOfs, r_color); } @@ -298,8 +299,9 @@ static short acf_generic_indention_flexible(bAnimContext *UNUSED(ac), bAnimListE FCurve *fcu = (FCurve *)ale->data; // TODO: we need some way of specifying that the indention color should be one less... - if (fcu->grp) + if (fcu->grp) { indent++; + } } /* no indention */ @@ -311,10 +313,12 @@ static short acf_generic_basic_offset(bAnimContext *ac, bAnimListElem *ale) { const bAnimChannelType *acf = ANIM_channel_get_typeinfo(ale); - if (acf && acf->get_indent_level) + if (acf && acf->get_indent_level) { return acf->get_indent_level(ac, ale) * INDENT_STEP_SIZE; - else + } + else { return 0; + } } /* offset based on nodetree type */ @@ -353,12 +357,15 @@ static short acf_generic_group_offset(bAnimContext *ac, bAnimListElem *ale) offset += U.widget_unit; } /* materials and particles animdata */ - else if (ELEM(GS(ale->id->name), ID_MA, ID_PA)) + else if (ELEM(GS(ale->id->name), ID_MA, ID_PA)) { offset += (short)(0.7f * U.widget_unit); - /* if not in Action Editor mode, action-groups (and their children) must carry some offset too... */ - else if (ac->datatype != ANIMCONT_ACTION) + /* If not in Action Editor mode, action-groups (and their children) + * must carry some offset too. */ + } + else if (ac->datatype != ANIMCONT_ACTION) { offset += (short)(0.7f * U.widget_unit); + } /* nodetree animdata */ if (GS(ale->id->name) == ID_NT) { @@ -378,8 +385,9 @@ static void acf_generic_idblock_name(bAnimListElem *ale, char *name) ID *id = (ID *)ale->data; /* data pointed to should be an ID block */ /* just copy the name... */ - if (id && name) + if (id && name) { BLI_strncpy(name, id->name + 2, ANIM_CHAN_NAME_SIZE); + } } /* name property for ID block entries */ @@ -405,7 +413,9 @@ static bool acf_generic_idfill_name_prop(bAnimListElem *ale, PointerRNA *ptr, Pr #if 0 /* channel type has no settings */ -static bool acf_generic_none_setting_valid(bAnimContext *ac, bAnimListElem *ale, eAnimChannel_Settings setting) +static bool acf_generic_none_setting_valid(bAnimContext *ac, + bAnimListElem *ale, + eAnimChannel_Settings setting) { return false; } @@ -474,8 +484,9 @@ static void acf_summary_backdrop(bAnimContext *ac, bAnimListElem *ale, float ymi /* name for summary entries */ static void acf_summary_name(bAnimListElem *UNUSED(ale), char *name) { - if (name) + if (name) { BLI_strncpy(name, IFACE_("Dope Sheet Summary"), ANIM_CHAN_NAME_SIZE); + } } // FIXME: this is really a temp icon I think @@ -633,8 +644,9 @@ static void *acf_scene_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set case ACHANNEL_SETTING_MUTE: /* mute (only in NLA) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (scene->adt) + if (scene->adt) { return GET_ACF_FLAG_PTR(scene->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -708,8 +720,9 @@ static void acf_object_name(bAnimListElem *ale, char *name) Object *ob = base->object; /* just copy the name... */ - if (ob && name) + if (ob && name) { BLI_strncpy(name, ob->id.name + 2, ANIM_CHAN_NAME_SIZE); + } } /* name property for object */ @@ -801,8 +814,9 @@ static void *acf_object_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings se case ACHANNEL_SETTING_MUTE: /* mute (only in NLA) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ case ACHANNEL_SETTING_ALWAYS_VISIBLE: - if (ob->adt) + if (ob->adt) { return GET_ACF_FLAG_PTR(ob->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -841,20 +855,24 @@ static void acf_group_color(bAnimContext *ac, bAnimListElem *ale, float r_color[ unsigned char cp[3]; /* highlight only for active */ - if (ale->flag & AGRP_ACTIVE) + if (ale->flag & AGRP_ACTIVE) { copy_v3_v3_char((char *)cp, agrp->cs.select); - else + } + else { copy_v3_v3_char((char *)cp, agrp->cs.solid); + } /* copy the colors over, transforming from bytes to floats */ rgb_uchar_to_float(r_color, cp); } else { /* highlight only for active */ - if (ale->flag & AGRP_ACTIVE) + if (ale->flag & AGRP_ACTIVE) { UI_GetThemeColor3fv(TH_GROUP_ACTIVE, r_color); - else + } + else { UI_GetThemeColor3fv(TH_GROUP, r_color); + } } } @@ -882,8 +900,9 @@ static void acf_group_name(bAnimListElem *ale, char *name) bActionGroup *agrp = (bActionGroup *)ale->data; /* just copy the name... */ - if (agrp && name) + if (agrp && name) { BLI_strncpy(name, agrp->name, ANIM_CHAN_NAME_SIZE); + } } /* name property for group entries */ @@ -1036,10 +1055,12 @@ static bool acf_fcurve_setting_valid(bAnimContext *ac, /* conditionally available */ case ACHANNEL_SETTING_PROTECT: /* Protection is only valid when there's keyframes */ - if (fcu->bezt) + if (fcu->bezt) { return true; - else + } + else { return false; // NOTE: in this special case, we need to draw ICON_ZOOMOUT + } case ACHANNEL_SETTING_VISIBLE: /* Only available in Graph Editor */ return (ac->spacetype == SPACE_GRAPH); @@ -1489,8 +1510,9 @@ static void *acf_dsmat_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (ma->adt) + if (ma->adt) { return GET_ACF_FLAG_PTR(ma->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -1569,8 +1591,9 @@ static void *acf_dslight_setting_ptr(bAnimListElem *ale, case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (la->adt) + if (la->adt) { return GET_ACF_FLAG_PTR(la->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -1654,8 +1677,9 @@ static void *acf_dstex_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (tex->adt) + if (tex->adt) { return GET_ACF_FLAG_PTR(tex->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -1819,8 +1843,9 @@ static void *acf_dscam_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ case ACHANNEL_SETTING_ALWAYS_VISIBLE: - if (ca->adt) + if (ca->adt) { return GET_ACF_FLAG_PTR(ca->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -1907,8 +1932,9 @@ static void *acf_dscur_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (cu->adt) + if (cu->adt) { return GET_ACF_FLAG_PTR(cu->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -1985,8 +2011,9 @@ static void *acf_dsskey_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings se case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (key->adt) + if (key->adt) { return GET_ACF_FLAG_PTR(key->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -2063,8 +2090,9 @@ static void *acf_dswor_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (wo->adt) + if (wo->adt) { return GET_ACF_FLAG_PTR(wo->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -2141,8 +2169,9 @@ static void *acf_dspart_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings se case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (part->adt) + if (part->adt) { return GET_ACF_FLAG_PTR(part->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -2221,8 +2250,9 @@ static void *acf_dsmball_setting_ptr(bAnimListElem *ale, case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (mb->adt) + if (mb->adt) { return GET_ACF_FLAG_PTR(mb->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -2299,8 +2329,9 @@ static void *acf_dsarm_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (arm->adt) + if (arm->adt) { return GET_ACF_FLAG_PTR(arm->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -2390,8 +2421,9 @@ static void *acf_dsntree_setting_ptr(bAnimListElem *ale, case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (ntree->adt) + if (ntree->adt) { return GET_ACF_FLAG_PTR(ntree->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -2470,8 +2502,9 @@ static void *acf_dslinestyle_setting_ptr(bAnimListElem *ale, case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (linestyle->adt) + if (linestyle->adt) { return GET_ACF_FLAG_PTR(linestyle->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -2548,8 +2581,9 @@ static void *acf_dsmesh_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings se case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (me->adt) + if (me->adt) { return GET_ACF_FLAG_PTR(me->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -2627,8 +2661,9 @@ static void *acf_dslat_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (lt->adt) + if (lt->adt) { return GET_ACF_FLAG_PTR(lt->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -2706,8 +2741,9 @@ static void *acf_dsspk_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings set case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (spk->adt) + if (spk->adt) { return GET_ACF_FLAG_PTR(spk->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -2786,8 +2822,9 @@ static void *acf_dsgpencil_setting_ptr(bAnimListElem *ale, case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (gpd->adt) + if (gpd->adt) { return GET_ACF_FLAG_PTR(gpd->adt->flag, type); + } return NULL; default: /* unsupported */ @@ -2905,10 +2942,12 @@ static void acf_shapekey_name(bAnimListElem *ale, char *name) /* just copy the name... */ if (kb && name) { /* if the KeyBlock had a name, use it, otherwise use the index */ - if (kb->name[0]) + if (kb->name[0]) { BLI_strncpy(name, kb->name, ANIM_CHAN_NAME_SIZE); - else + } + else { BLI_snprintf(name, ANIM_CHAN_NAME_SIZE, IFACE_("Key %d"), ale->index); + } } } @@ -3095,8 +3134,9 @@ static void acf_gpl_name(bAnimListElem *ale, char *name) { bGPDlayer *gpl = (bGPDlayer *)ale->data; - if (gpl && name) + if (gpl && name) { BLI_strncpy(name, gpl->info, ANIM_CHAN_NAME_SIZE); + } } /* name property for grease pencil layer entries */ @@ -3273,8 +3313,9 @@ static void acf_masklay_name(bAnimListElem *ale, char *name) { MaskLayer *masklay = (MaskLayer *)ale->data; - if (masklay && name) + if (masklay && name) { BLI_strncpy(name, masklay->name, ANIM_CHAN_NAME_SIZE); + } } /* name property for grease pencil layer entries */ @@ -3384,8 +3425,9 @@ static void acf_nlatrack_name(bAnimListElem *ale, char *name) { NlaTrack *nlt = (NlaTrack *)ale->data; - if (nlt && name) + if (nlt && name) { BLI_strncpy(name, nlt->name, ANIM_CHAN_NAME_SIZE); + } } /* name property for nla track entries */ @@ -3556,10 +3598,12 @@ static void acf_nlaaction_backdrop(bAnimContext *ac, bAnimListElem *ale, float y */ nla_action_get_color(adt, (bAction *)ale->data, color); - if (adt && (adt->flag & ADT_NLA_EDIT_ON)) + if (adt && (adt->flag & ADT_NLA_EDIT_ON)) { color[3] = 1.0f; - else + } + else { color[3] = (adt && (adt->flag & ADT_NLA_SOLO_TRACK)) ? 0.3f : 1.0f; + } /* only on top left corner, to show that this channel sits on top of the preceding ones * while still linking into the action line strip to the right @@ -3665,7 +3709,7 @@ static bAnimChannelType ACF_NLAACTION = { ACHANNEL_ROLE_CHANNEL, /* role */ acf_nlaaction_color, /* backdrop color (NOTE: the backdrop handles this too, - * since it needs special hacks) */ + * since it needs special hacks). */ acf_nlaaction_backdrop, /* backdrop */ acf_generic_indention_flexible, /* indent level */ acf_generic_group_offset, @@ -3752,17 +3796,20 @@ static void ANIM_init_channel_typeinfo_data(void) const bAnimChannelType *ANIM_channel_get_typeinfo(bAnimListElem *ale) { /* santiy checks */ - if (ale == NULL) + if (ale == NULL) { return NULL; + } /* init the typeinfo if not available yet... */ ANIM_init_channel_typeinfo_data(); /* check if type is in bounds... */ - if ((ale->type >= 0) && (ale->type < ANIMTYPE_NUM_TYPES)) + if ((ale->type >= 0) && (ale->type < ANIMTYPE_NUM_TYPES)) { return animchannelTypeInfo[ale->type]; - else + } + else { return NULL; + } } /* --------------------------- */ @@ -3773,26 +3820,31 @@ void ANIM_channel_debug_print_info(bAnimListElem *ale, short indent_level) const bAnimChannelType *acf = ANIM_channel_get_typeinfo(ale); /* print indents */ - for (; indent_level > 0; indent_level--) + for (; indent_level > 0; indent_level--) { printf(" "); + } /* print info */ if (acf) { char name[ANIM_CHAN_NAME_SIZE]; /* hopefully this will be enough! */ /* get UI name */ - if (acf->name) + if (acf->name) { acf->name(ale, name); - else + } + else { BLI_strncpy(name, "<No name>", sizeof(name)); + } /* print type name + ui name */ printf("ChanType: <%s> Name: \"%s\"\n", acf->channel_type_name, name); } - else if (ale) + else if (ale) { printf("ChanType: <Unknown - %d>\n", ale->type); - else + } + else { printf("<Invalid channel - NULL>\n"); + } } /* --------------------------- */ @@ -3822,28 +3874,34 @@ short ANIM_channel_setting_get(bAnimContext *ac, bAnimListElem *ale, eAnimChanne { const int *val = (int *)ptr; - if (negflag) + if (negflag) { return ((*val) & flag) == 0; - else + } + else { return ((*val) & flag) != 0; + } } case sizeof(short): /* short pointer for setting */ { const short *val = (short *)ptr; - if (negflag) + if (negflag) { return ((*val) & flag) == 0; - else + } + else { return ((*val) & flag) != 0; + } } case sizeof(char): /* char pointer for setting */ { const char *val = (char *)ptr; - if (negflag) + if (negflag) { return ((*val) & flag) == 0; - else + } + else { return ((*val) & flag) != 0; + } } } } @@ -3853,7 +3911,8 @@ short ANIM_channel_setting_get(bAnimContext *ac, bAnimListElem *ale, eAnimChanne return -1; } -/* quick macro for use in ANIM_channel_setting_set - set flag for setting according the mode given */ +/* Quick macro for use in ANIM_channel_setting_set - + * set flag for setting according the mode given. */ #define ACF_SETTING_SET(sval, sflag, smode) \ { \ if (negflag) { \ @@ -3958,14 +4017,17 @@ void ANIM_channel_draw( float y, ymid, ytext; /* sanity checks - don't draw anything */ - if (ELEM(NULL, acf, ale)) + if (ELEM(NULL, acf, ale)) { return; + } /* get initial offset */ - if (acf->get_offset) + if (acf->get_offset) { offset = acf->get_offset(ac, ale); - else + } + else { offset = 0; + } /* calculate appropriate y-coordinates for icon buttons */ y = (ymaxc - yminc) / 2 + yminc; @@ -3974,10 +4036,12 @@ void ANIM_channel_draw( ytext = y - 0.2f * U.widget_unit; /* check if channel is selected */ - if (acf->has_setting(ac, ale, ACHANNEL_SETTING_SELECT)) + if (acf->has_setting(ac, ale, ACHANNEL_SETTING_SELECT)) { selected = ANIM_channel_setting_get(ac, ale, ACHANNEL_SETTING_SELECT); - else + } + else { selected = 0; + } /* set blending again, as may not be set in previous step */ GPU_blend_set_func_separate( @@ -3985,8 +4049,9 @@ void ANIM_channel_draw( GPU_blend(true); /* step 1) draw backdrop ........................................... */ - if (acf->draw_backdrop) + if (acf->draw_backdrop) { acf->draw_backdrop(ac, ale, yminc, ymaxc); + } /* step 2) draw expand widget ....................................... */ if (acf->has_setting(ac, ale, ACHANNEL_SETTING_EXPAND)) { @@ -4020,8 +4085,8 @@ void ANIM_channel_draw( immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - /* F-Curve channels need to have a special 'color code' box drawn, which is colored with whatever - * color the curve has stored + /* F-Curve channels need to have a special 'color code' box drawn, + * which is colored with whatever color the curve has stored. */ immUniformColor3fv(fcu->color); @@ -4059,10 +4124,12 @@ void ANIM_channel_draw( /* set text color */ /* XXX: if active, highlight differently? */ - if (selected) + if (selected) { UI_GetThemeColor4ubv(TH_TEXT_HI, col); - else + } + else { UI_GetThemeColor4ubv(TH_TEXT, col); + } /* get name */ acf->name(ale, name); @@ -4128,39 +4195,47 @@ void ANIM_channel_draw( /* check if there's enough space for the toggles if the sliders are drawn too */ if (!(draw_sliders) || (BLI_rcti_size_x(&v2d->mask) > ACHANNEL_BUTTON_WIDTH / 2)) { /* protect... */ - if (acf->has_setting(ac, ale, ACHANNEL_SETTING_PROTECT)) + if (acf->has_setting(ac, ale, ACHANNEL_SETTING_PROTECT)) { offset += ICON_WIDTH; + } /* mute... */ - if (acf->has_setting(ac, ale, ACHANNEL_SETTING_MUTE)) + if (acf->has_setting(ac, ale, ACHANNEL_SETTING_MUTE)) { offset += ICON_WIDTH; - if (ale->type == ANIMTYPE_GPLAYER) + } + if (ale->type == ANIMTYPE_GPLAYER) { offset += ICON_WIDTH; + } /* pinned... */ - if (acf->has_setting(ac, ale, ACHANNEL_SETTING_PINNED)) + if (acf->has_setting(ac, ale, ACHANNEL_SETTING_PINNED)) { offset += ICON_WIDTH; + } - /* NOTE: technically, NLA Action "pushdown" should be here too, but there are no sliders there */ + /* NOTE: technically, NLA Action "pushdown" should be here too, + * but there are no sliders there. */ /* NLA action channels have slightly different spacing requirements... */ - if (ale->type == ANIMTYPE_NLAACTION) + if (ale->type == ANIMTYPE_NLAACTION) { ymin_ofs = NLACHANNEL_SKIP; + } } - /* draw slider - * - even if we can draw sliders for this view, we must also check that the channel-type supports them - * (only only F-Curves really can support them for now) - * - slider should start before the toggles (if they're visible) to keep a clean line down the side + /* Draw slider: + * - Even if we can draw sliders for this view, + * we must also check that the channel-type supports them + * (only only F-Curves really can support them for now). + * - Slider should start before the toggles (if they're visible) + * to keep a clean line down the side. */ if ((draw_sliders) && ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE, ANIMTYPE_SHAPEKEY)) { /* adjust offset */ offset += SLIDER_WIDTH; } - /* finally draw a backdrop rect behind these - * - starts from the point where the first toggle/slider starts, - * - ends past the space that might be reserved for a scroller + /* Finally draw a backdrop rect behind these: + * - Starts from the point where the first toggle/slider starts. + * - Ends past the space that might be reserved for a scroller. */ immRectf(pos, v2d->cur.xmax - (float)offset, @@ -4219,8 +4294,9 @@ static void achannel_setting_flush_widget_cb(bContext *C, void *ale_npoin, void } /* verify animation context */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return; + } /* check if the setting is on... */ on = ANIM_channel_setting_get(&ac, ale_setting, setting); @@ -4297,8 +4373,9 @@ static void achannel_setting_slider_cb(bContext *C, void *id_poin, void *fcu_poi /* try to resolve the path stored in the F-Curve */ if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) { /* set the special 'replace' flag if on a keyframe */ - if (fcurve_frame_has_keyframe(fcu, cfra, 0)) + if (fcurve_frame_has_keyframe(fcu, cfra, 0)) { flag |= INSERTKEY_REPLACE; + } /* insert a keyframe for this F-Curve */ done = insert_keyframe_direct( @@ -4356,20 +4433,23 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi FCurve *fcu = verify_fcurve(bmain, act, NULL, &ptr, rna_path, 0, 1); /* set the special 'replace' flag if on a keyframe */ - if (fcurve_frame_has_keyframe(fcu, cfra, 0)) + if (fcurve_frame_has_keyframe(fcu, cfra, 0)) { flag |= INSERTKEY_REPLACE; + } /* insert a keyframe for this F-Curve */ done = insert_keyframe_direct( depsgraph, reports, ptr, prop, fcu, cfra, ts->keyframe_type, nla_context, flag); - if (done) + if (done) { WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL); + } } /* free the path */ - if (rna_path) + if (rna_path) { MEM_freeN(rna_path); + } BKE_animsys_free_nla_keyframing_context_cache(&nla_cache); } @@ -4400,20 +4480,23 @@ static void achannel_setting_slider_nla_curve_cb(bContext *C, /* get flags for keyframing */ flag = ANIM_get_keyframing_flags(scene, 1); - /* get pointer and property from the slider - this should all match up with the NlaStrip required... */ + /* Get pointer and property from the slider - + * this should all match up with the NlaStrip required. */ UI_context_active_but_prop_get(C, &ptr, &prop, &index); if (fcu && prop) { /* set the special 'replace' flag if on a keyframe */ - if (fcurve_frame_has_keyframe(fcu, cfra, 0)) + if (fcurve_frame_has_keyframe(fcu, cfra, 0)) { flag |= INSERTKEY_REPLACE; + } /* insert a keyframe for this F-Curve */ done = insert_keyframe_direct( depsgraph, reports, ptr, prop, fcu, cfra, ts->keyframe_type, NULL, flag); - if (done) + if (done) { WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL); + } } } @@ -4443,15 +4526,18 @@ static void draw_setting_widget(bAnimContext *ac, /* get the base icon for the setting */ switch (setting) { case ACHANNEL_SETTING_VISIBLE: /* visibility eyes */ - //icon = ((enabled) ? ICON_VISIBLE_IPO_ON : ICON_VISIBLE_IPO_OFF); + // icon = ((enabled) ? ICON_VISIBLE_IPO_ON : ICON_VISIBLE_IPO_OFF); icon = ICON_VISIBLE_IPO_OFF; - if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) + if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) { tooltip = TIP_("F-Curve is visible in Graph Editor for editing"); - else if (ale->type == ANIMTYPE_GPLAYER) + } + else if (ale->type == ANIMTYPE_GPLAYER) { tooltip = TIP_("Grease Pencil layer is visible in the viewport"); - else + } + else { tooltip = TIP_("Channels are visible in Graph Editor for editing"); + } break; case ACHANNEL_SETTING_ALWAYS_VISIBLE: @@ -4465,13 +4551,13 @@ static void draw_setting_widget(bAnimContext *ac, break; case ACHANNEL_SETTING_EXPAND: /* expanded triangle */ - //icon = ((enabled) ? ICON_TRIA_DOWN : ICON_TRIA_RIGHT); + // icon = ((enabled) ? ICON_TRIA_DOWN : ICON_TRIA_RIGHT); icon = ICON_TRIA_RIGHT; tooltip = TIP_("Make channels grouped under this channel visible"); break; case ACHANNEL_SETTING_SOLO: /* NLA Tracks only */ - //icon = ((enabled) ? ICON_SOLO_OFF : ICON_SOLO_ON); + // icon = ((enabled) ? ICON_SOLO_OFF : ICON_SOLO_ON); icon = ICON_SOLO_OFF; tooltip = TIP_( "NLA Track is the only one evaluated in this animation data-block, with all others " @@ -4482,13 +4568,15 @@ static void draw_setting_widget(bAnimContext *ac, case ACHANNEL_SETTING_PROTECT: /* protected lock */ // TODO: what about when there's no protect needed? - //icon = ((enabled) ? ICON_LOCKED : ICON_UNLOCKED); + // icon = ((enabled) ? ICON_LOCKED : ICON_UNLOCKED); icon = ICON_UNLOCKED; - if (ale->datatype != ALE_NLASTRIP) + if (ale->datatype != ALE_NLASTRIP) { tooltip = TIP_("Editability of keyframes for this channel"); - else + } + else { tooltip = TIP_("Editability of NLA Strips in this track"); + } break; case ACHANNEL_SETTING_MUTE: /* muted speaker */ @@ -4511,7 +4599,7 @@ static void draw_setting_widget(bAnimContext *ac, break; case ACHANNEL_SETTING_PINNED: /* pin icon */ - //icon = ((enabled) ? ICON_PINNED : ICON_UNPINNED); + // icon = ((enabled) ? ICON_PINNED : ICON_UNPINNED); icon = ICON_UNPINNED; if (ale->type == ANIMTYPE_NLAACTION) { @@ -4531,16 +4619,20 @@ static void draw_setting_widget(bAnimContext *ac, /* type of button */ if (usetoggle) { - if (negflag) + if (negflag) { butType = UI_BTYPE_ICON_TOGGLE_N; - else + } + else { butType = UI_BTYPE_ICON_TOGGLE; + } } else { - if (negflag) + if (negflag) { butType = UI_BTYPE_TOGGLE_N; - else + } + else { butType = UI_BTYPE_TOGGLE; + } } /* draw button for setting */ if (ptr && flag) { @@ -4628,12 +4720,14 @@ static void draw_setting_widget(bAnimContext *ac, UI_but_func_set(but, achannel_setting_widget_cb, NULL, NULL); break; } - } - } - if ((ale->fcurve_owner_id != NULL && ID_IS_LINKED(ale->fcurve_owner_id)) || - (ale->id != NULL && ID_IS_LINKED(ale->id))) { - UI_but_flag_enable(but, UI_BUT_DISABLED); + if ((ale->fcurve_owner_id != NULL && ID_IS_LINKED(ale->fcurve_owner_id)) || + (ale->id != NULL && ID_IS_LINKED(ale->id))) { + if (setting != ACHANNEL_SETTING_EXPAND) { + UI_but_flag_enable(but, UI_BUT_DISABLED); + } + } + } } } @@ -4652,8 +4746,9 @@ void ANIM_channel_draw_widgets(const bContext *C, const bool is_being_renamed = achannel_is_being_renamed(ac, acf, channel_index); /* sanity checks - don't draw anything */ - if (ELEM(NULL, acf, ale, block)) + if (ELEM(NULL, acf, ale, block)) { return; + } /* get initial offset */ short offset = rect->xmin; @@ -4715,15 +4810,43 @@ void ANIM_channel_draw_widgets(const bContext *C, RNA_pointer_create(ale->id, &RNA_GPencilLayer, ale->data, &ptr); UI_block_align_begin(block); - UI_block_emboss_set(block, RNA_boolean_get(&ptr, "is_stroke_visible") ? UI_EMBOSS : UI_EMBOSS_NONE); - uiDefButR(block, UI_BTYPE_COLOR, 1, "", offset, yminc, w, ICON_WIDTH, - &ptr, "color", -1, - 0, 0, 0, 0, gpl->info); - - UI_block_emboss_set(block, RNA_boolean_get(&ptr, "is_fill_visible") ? UI_EMBOSS : UI_EMBOSS_NONE); - uiDefButR(block, UI_BTYPE_COLOR, 1, "", offset + w, yminc, w, ICON_WIDTH, - &ptr, "fill_color", -1, - 0, 0, 0, 0, gpl->info); + UI_block_emboss_set(block, + RNA_boolean_get(&ptr, "is_stroke_visible") ? UI_EMBOSS : UI_EMBOSS_NONE); + uiDefButR(block, + UI_BTYPE_COLOR, + 1, + "", + offset, + yminc, + w, + ICON_WIDTH, + &ptr, + "color", + -1, + 0, + 0, + 0, + 0, + gpl->info); + + UI_block_emboss_set(block, + RNA_boolean_get(&ptr, "is_fill_visible") ? UI_EMBOSS : UI_EMBOSS_NONE); + uiDefButR(block, + UI_BTYPE_COLOR, + 1, + "", + offset + w, + yminc, + w, + ICON_WIDTH, + &ptr, + "fill_color", + -1, + 0, + 0, + 0, + 0, + gpl->info); UI_block_emboss_set(block, UI_EMBOSS_NONE); UI_block_align_end(block); @@ -4821,7 +4944,8 @@ void ANIM_channel_draw_widgets(const bContext *C, draw_setting_widget(ac, ale, acf, block, offset, ymid, ACHANNEL_SETTING_MUTE); } if (ale->type == ANIMTYPE_GPLAYER) { - /* Not technically "mute" (in terms of anim channels, but this sets layer visibility instead) */ + /* Not technically "mute" + * (in terms of anim channels, but this sets layer visibility instead). */ offset -= ICON_WIDTH; draw_setting_widget(ac, ale, acf, block, offset, ymid, ACHANNEL_SETTING_VISIBLE); } @@ -4868,17 +4992,20 @@ void ANIM_channel_draw_widgets(const bContext *C, } } - /* draw slider - * - even if we can draw sliders for this view, we must also check that the channel-type supports them - * (only only F-Curves really can support them for now) - * - to make things easier, we use RNA-autobuts for this so that changes are reflected immediately, - * wherever they occurred. BUT, we don't use the layout engine, otherwise we'd get wrong alignment, - * and wouldn't be able to auto-keyframe... - * - slider should start before the toggles (if they're visible) to keep a clean line down the side + /* Draw slider: + * - Even if we can draw sliders for this view, we must also check that the channel-type + * supports them (only only F-Curves really can support them for now). + * - To make things easier, we use RNA-autobuts for this so that changes are + * reflected immediately, wherever they occurred. + * BUT, we don't use the layout engine, otherwise we'd get wrong alignment, + * and wouldn't be able to auto-keyframe. + * - Slider should start before the toggles (if they're visible) + * to keep a clean line down the side. */ if ((draw_sliders) && ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE, ANIMTYPE_SHAPEKEY)) { /* adjust offset */ - // TODO: make slider width dynamic, so that they can be easier to use when the view is wide enough + /* TODO: make slider width dynamic, + * so that they can be easier to use when the view is wide enough. */ offset -= SLIDER_WIDTH; /* need backdrop behind sliders... */ @@ -4899,7 +5026,8 @@ void ANIM_channel_draw_widgets(const bContext *C, if (prop) { uiBut *but; - /* create the slider button, and assign relevant callback to ensure keyframes are inserted... */ + /* Create the slider button, + * and assign relevant callback to ensure keyframes are inserted. */ but = uiDefAutoButR(block, &ptr, prop, @@ -4945,7 +5073,8 @@ void ANIM_channel_draw_widgets(const bContext *C, if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop)) { uiBut *but; - /* create the slider button, and assign relevant callback to ensure keyframes are inserted... */ + /* Create the slider button, + * and assign relevant callback to ensure keyframes are inserted. */ but = uiDefAutoButR(block, &ptr, prop, @@ -4958,15 +5087,18 @@ void ANIM_channel_draw_widgets(const bContext *C, channel_height); /* assign keyframing function according to slider type */ - if (ale->type == ANIMTYPE_SHAPEKEY) + if (ale->type == ANIMTYPE_SHAPEKEY) { UI_but_func_set(but, achannel_setting_slider_shapekey_cb, ale->id, ale->data); - else + } + else { UI_but_func_set(but, achannel_setting_slider_cb, ale->id, ale->data); + } } /* free the path if necessary */ - if (free_path) + if (free_path) { MEM_freeN(rna_path); + } } } else { /* Special Slider for stuff without RNA Access ---------- */ diff --git a/source/blender/editors/animation/anim_channels_edit.c b/source/blender/editors/animation/anim_channels_edit.c index c2878a64e97..6e0277d5fff 100644 --- a/source/blender/editors/animation/anim_channels_edit.c +++ b/source/blender/editors/animation/anim_channels_edit.c @@ -85,14 +85,16 @@ void ANIM_set_active_channel(bAnimContext *ac, /* try to build list of filtered items */ ANIM_animdata_filter(ac, &anim_data, filter, data, datatype); - if (BLI_listbase_is_empty(&anim_data)) + if (BLI_listbase_is_empty(&anim_data)) { return; + } /* only clear the 'active' flag for the channels of the same type */ for (ale = anim_data.first; ale; ale = ale->next) { /* skip if types don't match */ - if (channel_type != ale->type) + if (channel_type != ale->type) { continue; + } /* flag to set depends on type */ switch (ale->type) { @@ -263,13 +265,15 @@ void ANIM_deselect_anim_channels( /* See if we should be selecting or deselecting */ if (test) { for (ale = anim_data.first; ale; ale = ale->next) { - if (sel == 0) + if (sel == 0) { break; + } switch (ale->type) { case ANIMTYPE_SCENE: - if (ale->flag & SCE_DS_SELECTED) + if (ale->flag & SCE_DS_SELECTED) { sel = ACHANNEL_SETFLAG_CLEAR; + } break; case ANIMTYPE_OBJECT: #if 0 /* for now, do not take object selection into account, since it gets too annoying */ @@ -278,21 +282,25 @@ void ANIM_deselect_anim_channels( #endif break; case ANIMTYPE_GROUP: - if (ale->flag & AGRP_SELECTED) + if (ale->flag & AGRP_SELECTED) { sel = ACHANNEL_SETFLAG_CLEAR; + } break; case ANIMTYPE_FCURVE: case ANIMTYPE_NLACURVE: - if (ale->flag & FCURVE_SELECTED) + if (ale->flag & FCURVE_SELECTED) { sel = ACHANNEL_SETFLAG_CLEAR; + } break; case ANIMTYPE_SHAPEKEY: - if (ale->flag & KEYBLOCK_SEL) + if (ale->flag & KEYBLOCK_SEL) { sel = ACHANNEL_SETFLAG_CLEAR; + } break; case ANIMTYPE_NLATRACK: - if (ale->flag & NLATRACK_SELECTED) + if (ale->flag & NLATRACK_SELECTED) { sel = ACHANNEL_SETFLAG_CLEAR; + } break; case ANIMTYPE_FILLACTD: /* Action Expander */ @@ -314,17 +322,20 @@ void ANIM_deselect_anim_channels( case ANIMTYPE_DSSPK: case ANIMTYPE_DSGPENCIL: case ANIMTYPE_DSMCLIP: { - if ((ale->adt) && (ale->adt->flag & ADT_UI_SELECTED)) + if ((ale->adt) && (ale->adt->flag & ADT_UI_SELECTED)) { sel = ACHANNEL_SETFLAG_CLEAR; + } break; } case ANIMTYPE_GPLAYER: - if (ale->flag & GP_LAYER_SELECT) + if (ale->flag & GP_LAYER_SELECT) { sel = ACHANNEL_SETFLAG_CLEAR; + } break; case ANIMTYPE_MASKLAYER: - if (ale->flag & MASK_LAYERFLAG_SELECT) + if (ale->flag & MASK_LAYERFLAG_SELECT) { sel = ACHANNEL_SETFLAG_CLEAR; + } break; } } @@ -451,8 +462,9 @@ void ANIM_flush_setting_anim_channels(bAnimContext *ac, int prevLevel = 0, matchLevel = 0; /* sanity check */ - if (ELEM(NULL, anim_data, anim_data->first)) + if (ELEM(NULL, anim_data, anim_data->first)) { return; + } if (setting == ACHANNEL_SETTING_ALWAYS_VISIBLE) { return; @@ -462,7 +474,8 @@ void ANIM_flush_setting_anim_channels(bAnimContext *ac, for (ale = anim_data->first; ale; ale = ale->next) { /* compare data, and type as main way of identifying the channel */ if ((ale->data == ale_setting->data) && (ale->type == ale_setting->type)) { - /* we also have to check the ID, this is assigned to, since a block may have multiple users */ + /* We also have to check the ID, this is assigned to, + * since a block may have multiple users. */ /* TODO: is the owner-data more revealing? */ if (ale->id == ale_setting->id) { match = ale; @@ -501,14 +514,16 @@ void ANIM_flush_setting_anim_channels(bAnimContext *ac, */ if (((setting == ACHANNEL_SETTING_VISIBLE) && (mode != ACHANNEL_SETFLAG_CLEAR)) || ((setting != ACHANNEL_SETTING_VISIBLE) && (mode == ACHANNEL_SETFLAG_CLEAR))) { - /* go backwards in the list, until the highest-ranking element (by indention has been covered) */ + /* Go backwards in the list, until the highest-ranking element + * (by indention has been covered). */ for (ale = match->prev; ale; ale = ale->prev) { const bAnimChannelType *acf = ANIM_channel_get_typeinfo(ale); int level; /* if no channel info was found, skip, since this type might not have any useful info */ - if (acf == NULL) + if (acf == NULL) { continue; + } /* get the level of the current channel traversed * - we define the level as simply being the offset for the start of the channel @@ -517,8 +532,8 @@ void ANIM_flush_setting_anim_channels(bAnimContext *ac, /* if the level is 'less than' (i.e. more important) the level we're matching * but also 'less than' the level just tried (i.e. only the 1st group above grouped F-Curves, - * when toggling visibility of F-Curves, gets flushed, which should happen if we don't let prevLevel - * get updated below once the first 1st group is found)... + * when toggling visibility of F-Curves, gets flushed, which should happen if we don't let + * prevLevel get updated below once the first 1st group is found). */ if (level < prevLevel) { /* flush the new status... */ @@ -532,13 +547,15 @@ void ANIM_flush_setting_anim_channels(bAnimContext *ac, /* if previous level was a base-level (i.e. 0 offset / root of one hierarchy), * stop here */ - if (prevLevel == 0) + if (prevLevel == 0) { break; - /* otherwise, this level weaves into another sibling hierarchy to the previous one just - * finished, so skip until we get to the parent of this level - */ - else + /* otherwise, this level weaves into another sibling hierarchy to the previous one just + * finished, so skip until we get to the parent of this level + */ + } + else { continue; + } } } } @@ -551,8 +568,9 @@ void ANIM_flush_setting_anim_channels(bAnimContext *ac, int level; /* if no channel info was found, skip, since this type might not have any useful info */ - if (acf == NULL) + if (acf == NULL) { continue; + } /* get the level of the current channel traversed * - we define the level as simply being the offset for the start of the channel @@ -562,14 +580,17 @@ void ANIM_flush_setting_anim_channels(bAnimContext *ac, /* if the level is 'greater than' (i.e. less important) the channel that was changed, * flush the new status... */ - if (level > matchLevel) + if (level > matchLevel) { ANIM_channel_setting_set(ac, ale, setting, mode); - /* however, if the level is 'less than or equal to' the channel that was changed, - * (i.e. the current channel is as important if not more important than the changed channel) - * then we should stop, since we've found the last one of the children we should flush - */ - else + /* however, if the level is 'less than or equal to' the channel that was changed, + * (i.e. the current channel is as important if not more important than the changed + * channel) then we should stop, since we've found the last one of the children we should + * flush + */ + } + else { break; + } /* store this level as the 'old' level now */ // prevLevel = level; // XXX: prevLevel is unused @@ -586,8 +607,9 @@ void ANIM_fcurve_delete_from_animdata(bAnimContext *ac, AnimData *adt, FCurve *f * (this doesn't guarantee that the F-Curve is in there, but at least we tried * - if no F-Curve, there is nothing to remove */ - if (ELEM(NULL, adt, fcu)) + if (ELEM(NULL, adt, fcu)) { return; + } /* remove from whatever list it came from * - Action Group @@ -627,14 +649,28 @@ void ANIM_fcurve_delete_from_animdata(bAnimContext *ac, AnimData *adt, FCurve *f * channel list that are empty, and linger around long after the data they * are for has disappeared (and probably won't come back). */ + ANIM_remove_empty_action_from_animdata(adt); + } + + /* free the F-Curve itself */ + free_fcurve(fcu); +} + +/* If the action has no F-Curves, unlink it from AnimData if it did not + * come from a NLA Strip being tweaked. */ +bool ANIM_remove_empty_action_from_animdata(struct AnimData *adt) +{ + if (adt->action != NULL) { + bAction *act = adt->action; + if (BLI_listbase_is_empty(&act->curves) && (adt->flag & ADT_NLA_EDIT_ON) == 0) { id_us_min(&act->id); adt->action = NULL; + return true; } } - /* free the F-Curve itself */ - free_fcurve(fcu); + return false; } /* ************************************************************************** */ @@ -649,11 +685,13 @@ static bool animedit_poll_channels_active(bContext *C) /* channels region test */ /* TODO: could enhance with actually testing if channels region? */ - if (ELEM(NULL, sa, CTX_wm_region(C))) + if (ELEM(NULL, sa, CTX_wm_region(C))) { return 0; + } /* animation editor test */ - if (ELEM(sa->spacetype, SPACE_ACTION, SPACE_GRAPH, SPACE_NLA) == 0) + if (ELEM(sa->spacetype, SPACE_ACTION, SPACE_GRAPH, SPACE_NLA) == 0) { return 0; + } return 1; } @@ -666,16 +704,19 @@ static bool animedit_poll_channels_nla_tweakmode_off(bContext *C) /* channels region test */ /* TODO: could enhance with actually testing if channels region? */ - if (ELEM(NULL, sa, CTX_wm_region(C))) + if (ELEM(NULL, sa, CTX_wm_region(C))) { return 0; + } /* animation editor test */ - if (ELEM(sa->spacetype, SPACE_ACTION, SPACE_GRAPH, SPACE_NLA) == 0) + if (ELEM(sa->spacetype, SPACE_ACTION, SPACE_GRAPH, SPACE_NLA) == 0) { return 0; + } /* NLA TweakMode test */ if (sa->spacetype == SPACE_NLA) { - if ((scene == NULL) || (scene->flag & SCE_NLA_EDIT_ON)) + if ((scene == NULL) || (scene->flag & SCE_NLA_EDIT_ON)) { return 0; + } } return 1; @@ -724,8 +765,9 @@ typedef enum eReorderIslandFlag { static bool rearrange_island_ok(tReorderChannelIsland *island) { /* island must not be untouchable */ - if (island->flag & REORDER_ISLAND_UNTOUCHABLE) + if (island->flag & REORDER_ISLAND_UNTOUCHABLE) { return 0; + } /* island should be selected to be moved */ return (island->flag & REORDER_ISLAND_SELECTED) && !(island->flag & REORDER_ISLAND_MOVED); @@ -907,7 +949,8 @@ static void rearrange_animchannel_add_to_islands(ListBase *islands, (island == NULL) || /* 2) unselected islands have single channels only - to allow up/down movement */ ((island->flag & REORDER_ISLAND_SELECTED) == 0) || - /* 3) if channel is unselected, stop existing island (it was either wrong sel status, or full already) */ + /* 3) if channel is unselected, stop existing island + * (it was either wrong sel status, or full already) */ (is_sel == 0) || /* 4) hidden status changes */ ((island->flag & REORDER_ISLAND_HIDDEN) != is_hidden)) { @@ -915,12 +958,15 @@ static void rearrange_animchannel_add_to_islands(ListBase *islands, island = MEM_callocN(sizeof(tReorderChannelIsland), "tReorderChannelIsland"); BLI_addtail(islands, island); - if (is_sel) + if (is_sel) { island->flag |= REORDER_ISLAND_SELECTED; - if (is_untouchable) + } + if (is_untouchable) { island->flag |= REORDER_ISLAND_UNTOUCHABLE; - if (is_hidden) + } + if (is_hidden) { island->flag |= REORDER_ISLAND_HIDDEN; + } } /* add channel to island - need to remove it from its existing list first though */ @@ -985,8 +1031,9 @@ static bool rearrange_animchannel_islands(ListBase *list, bool done = false; /* don't waste effort on an empty list */ - if (BLI_listbase_is_empty(list)) + if (BLI_listbase_is_empty(list)) { return 0; + } /* group channels into islands */ for (channel = list->first; channel; channel = chanNext) { @@ -997,9 +1044,12 @@ static bool rearrange_animchannel_islands(ListBase *list, rearrange_animchannel_add_to_islands(&islands, list, channel, type, is_hidden); } - /* perform moving of selected islands now, but only if there is more than one of 'em so that something will happen - * - scanning of the list is performed in the opposite direction to the direction we're moving things, so that we - * shouldn't need to encounter items we've moved already + /* Perform moving of selected islands now, but only if there is more than one of them + * so that something will happen: + * + * - Scanning of the list is performed in the opposite direction + * to the direction we're moving things, + * so that we shouldn't need to encounter items we've moved already. */ if (islands.first != islands.last) { tReorderChannelIsland *first = (mode > 0) ? islands.last : islands.first; @@ -1039,8 +1089,9 @@ static void rearrange_nla_channels(bAnimContext *ac, AnimData *adt, eRearrangeAn /* get rearranging function */ rearrange_func = rearrange_get_mode_func(mode); - if (rearrange_func == NULL) + if (rearrange_func == NULL) { return; + } /* Filter visible data. */ rearrange_animchannels_filter_visible(&anim_data_visible, ac, ANIMTYPE_NLATRACK); @@ -1066,12 +1117,14 @@ static void rearrange_driver_channels(bAnimContext *ac, AnimChanRearrangeFp rearrange_func = rearrange_get_mode_func(mode); ListBase anim_data_visible = {NULL, NULL}; - if (rearrange_func == NULL) + if (rearrange_func == NULL) { return; + } /* only consider drivers if they're accessible */ - if (EXPANDED_DRVD(adt) == 0) + if (EXPANDED_DRVD(adt) == 0) { return; + } /* Filter visible data. */ rearrange_animchannels_filter_visible(&anim_data_visible, ac, ANIMTYPE_FCURVE); @@ -1092,8 +1145,9 @@ static void split_groups_action_temp(bAction *act, bActionGroup *tgrp) bActionGroup *agrp; FCurve *fcu; - if (act == NULL) + if (act == NULL) { return; + } /* Separate F-Curves into lists per group */ for (agrp = act->groups.first; agrp; agrp = agrp->next) { @@ -1185,8 +1239,9 @@ static void rearrange_action_channels(bAnimContext *ac, bAction *act, eRearrange /* get rearranging function */ AnimChanRearrangeFp rearrange_func = rearrange_get_mode_func(mode); - if (rearrange_func == NULL) + if (rearrange_func == NULL) { return; + } /* make sure we're only operating with groups (vs a mixture of groups+curves) */ split_groups_action_temp(act, &tgrp); @@ -1194,9 +1249,10 @@ static void rearrange_action_channels(bAnimContext *ac, bAction *act, eRearrange /* Filter visible data. */ rearrange_animchannels_filter_visible(&anim_data_visible, ac, ANIMTYPE_GROUP); - /* rearrange groups first - * - the group's channels will only get considered if nothing happened when rearranging the groups - * i.e. the rearrange function returned 0 + /* Rearrange groups first: + * - The group's channels will only get considered + * if nothing happened when rearranging the groups + * i.e. the rearrange function returned 0. */ do_channels = (rearrange_animchannel_islands( &act->groups, rearrange_func, mode, ANIMTYPE_GROUP, &anim_data_visible) == 0); @@ -1240,12 +1296,14 @@ static void rearrange_nla_control_channels(bAnimContext *ac, /* get rearranging function */ AnimChanRearrangeFp rearrange_func = rearrange_get_mode_func(mode); - if (rearrange_func == NULL) + if (rearrange_func == NULL) { return; + } /* skip if these curves aren't being shown */ - if (adt->flag & ADT_NLA_SKEYS_COLLAPSED) + if (adt->flag & ADT_NLA_SKEYS_COLLAPSED) { return; + } /* Filter visible data. */ rearrange_animchannels_filter_visible(&anim_data_visible, ac, ANIMTYPE_NLACURVE); @@ -1273,8 +1331,9 @@ static void rearrange_gpencil_channels(bAnimContext *ac, eRearrangeAnimChan_Mode /* get rearranging function */ AnimChanRearrangeFp rearrange_func = rearrange_get_mode_func(mode); - if (rearrange_func == NULL) + if (rearrange_func == NULL) { return; + } /* get Grease Pencil datablocks */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_ANIMDATA); @@ -1286,8 +1345,9 @@ static void rearrange_gpencil_channels(bAnimContext *ac, eRearrangeAnimChan_Mode /* only consider layers if this datablock is open */ BLI_assert(ale->type == ANIMTYPE_GPDATABLOCK); - if ((gpd->flag & GP_DATA_EXPAND) == 0) + if ((gpd->flag & GP_DATA_EXPAND) == 0) { continue; + } /* Filter visible data. */ rearrange_animchannels_filter_visible(&anim_data_visible, ac, ANIMTYPE_GPLAYER); @@ -1312,8 +1372,9 @@ static int animchannels_rearrange_exec(bContext *C, wmOperator *op) eRearrangeAnimChan_Mode mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get mode */ mode = RNA_enum_get(op->ptr, "direction"); @@ -1356,24 +1417,29 @@ static int animchannels_rearrange_exec(bContext *C, wmOperator *op) case ANIMCONT_ACTION: /* Single Action only... */ case ANIMCONT_SHAPEKEY: // DOUBLE CHECK ME... { - if (adt->action) + if (adt->action) { rearrange_action_channels(&ac, adt->action, mode); - else if (G.debug & G_DEBUG) + } + else if (G.debug & G_DEBUG) { printf("Animdata has no action\n"); + } break; } default: /* DopeSheet/Graph Editor - Some Actions + NLA Control Curves */ { /* NLA Control Curves */ - if (adt->nla_tracks.first) + if (adt->nla_tracks.first) { rearrange_nla_control_channels(&ac, adt, mode); + } /* Action */ - if (adt->action) + if (adt->action) { rearrange_action_channels(&ac, adt->action, mode); - else if (G.debug & G_DEBUG) + } + else if (G.debug & G_DEBUG) { printf("Animdata has no action\n"); + } break; } } @@ -1421,8 +1487,9 @@ static bool animchannels_grouping_poll(bContext *C) /* channels region test */ /* TODO: could enhance with actually testing if channels region? */ - if (ELEM(NULL, sa, CTX_wm_region(C))) + if (ELEM(NULL, sa, CTX_wm_region(C))) { return 0; + } /* animation editor test - must be suitable modes only */ sl = CTX_wm_space_data(C); @@ -1433,8 +1500,9 @@ static bool animchannels_grouping_poll(bContext *C) SpaceAction *saction = (SpaceAction *)sl; /* dopesheet and action only - all others are for other datatypes or have no groups */ - if (ELEM(saction->mode, SACTCONT_ACTION, SACTCONT_DOPESHEET) == 0) + if (ELEM(saction->mode, SACTCONT_ACTION, SACTCONT_DOPESHEET) == 0) { return 0; + } break; } @@ -1442,8 +1510,9 @@ static bool animchannels_grouping_poll(bContext *C) SpaceGraph *sipo = (SpaceGraph *)sl; /* drivers can't have groups... */ - if (sipo->mode != SIPO_MODE_ANIMATION) + if (sipo->mode != SIPO_MODE_ANIMATION) { return 0; + } break; } @@ -1508,8 +1577,9 @@ static int animchannels_group_exec(bContext *C, wmOperator *op) char name[MAX_NAME]; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get name for new group */ RNA_string_get(op->ptr, "name", name); @@ -1576,8 +1646,9 @@ static int animchannels_ungroup_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* just selected F-Curves... */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_SEL | @@ -1661,12 +1732,14 @@ static int animchannels_delete_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* cannot delete in shapekey */ - if (ac.datatype == ANIMCONT_SHAPEKEY) + if (ac.datatype == ANIMCONT_SHAPEKEY) { return OPERATOR_CANCELLED; + } /* do groups only first (unless in Drivers mode, where there are none) */ if (ac.datatype != ANIMCONT_DRIVERS) { @@ -1684,8 +1757,9 @@ static int animchannels_delete_exec(bContext *C, wmOperator *UNUSED(op)) FCurve *fcu, *fcn; /* skip this group if no AnimData available, as we can't safely remove the F-Curves */ - if (adt == NULL) + if (adt == NULL) { continue; + } /* delete all of the Group's F-Curves, but no others */ for (fcu = agrp->channels.first; fcu && fcu->grp == agrp; fcu = fcn) { @@ -1701,8 +1775,9 @@ static int animchannels_delete_exec(bContext *C, wmOperator *UNUSED(op)) BLI_freelinkN(&adt->action->groups, agrp); DEG_id_tag_update_ex(CTX_data_main(C), &adt->action->id, ID_RECALC_ANIMATION); } - else + else { MEM_freeN(agrp); + } } } @@ -1862,8 +1937,9 @@ static void setflag_anim_channels(bAnimContext *ac, filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS | ANIMFILTER_NODUPLIS); } - if (onlysel) + if (onlysel) { filter |= ANIMFILTER_SEL; + } ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* if toggling, check if disable or enable */ @@ -1884,15 +1960,17 @@ static void setflag_anim_channels(bAnimContext *ac, /* apply the setting */ for (ale = anim_data.first; ale; ale = ale->next) { /* skip channel if setting is not available */ - if (ANIM_channel_setting_get(ac, ale, setting) == -1) + if (ANIM_channel_setting_get(ac, ale, setting) == -1) { continue; + } /* set the setting in the appropriate way */ ANIM_channel_setting_set(ac, ale, setting, mode); /* if flush status... */ - if (flush) + if (flush) { ANIM_flush_setting_anim_channels(ac, &all_data, ale, setting, mode); + } } ANIM_animdata_freelist(&anim_data); @@ -1909,16 +1987,18 @@ static int animchannels_setflag_exec(bContext *C, wmOperator *op) bool flush = true; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* mode (eAnimChannels_SetFlag), setting (eAnimChannel_Settings) */ mode = RNA_enum_get(op->ptr, "mode"); setting = RNA_enum_get(op->ptr, "type"); /* check if setting is flushable */ - if (setting == ACHANNEL_SETTING_EXPAND) + if (setting == ACHANNEL_SETTING_EXPAND) { flush = false; + } /* modify setting * - only selected channels are affected @@ -2044,12 +2124,14 @@ static int animchannels_expand_exec(bContext *C, wmOperator *op) bool onlysel = true; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* only affect selected channels? */ - if (RNA_boolean_get(op->ptr, "all")) + if (RNA_boolean_get(op->ptr, "all")) { onlysel = false; + } /* modify setting */ setflag_anim_channels(&ac, ACHANNEL_SETTING_EXPAND, ACHANNEL_SETFLAG_ADD, onlysel, false); @@ -2087,12 +2169,14 @@ static int animchannels_collapse_exec(bContext *C, wmOperator *op) bool onlysel = true; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* only affect selected channels? */ - if (RNA_boolean_get(op->ptr, "all")) + if (RNA_boolean_get(op->ptr, "all")) { onlysel = false; + } /* modify setting */ setflag_anim_channels(&ac, ACHANNEL_SETTING_EXPAND, ACHANNEL_SETFLAG_CLEAR, onlysel, false); @@ -2143,8 +2227,9 @@ static int animchannels_clean_empty_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get animdata blocks */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_ANIMDATA); @@ -2236,12 +2321,14 @@ static bool animchannels_enable_poll(bContext *C) /* channels region test */ /* TODO: could enhance with actually testing if channels region? */ - if (ELEM(NULL, sa, CTX_wm_region(C))) + if (ELEM(NULL, sa, CTX_wm_region(C))) { return 0; + } /* animation editor test - Action/Dopesheet/etc. and Graph only */ - if (ELEM(sa->spacetype, SPACE_ACTION, SPACE_GRAPH) == 0) + if (ELEM(sa->spacetype, SPACE_ACTION, SPACE_GRAPH) == 0) { return 0; + } return 1; } @@ -2255,8 +2342,9 @@ static int animchannels_enable_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_NODUPLIS); @@ -2270,8 +2358,9 @@ static int animchannels_enable_exec(bContext *C, wmOperator *UNUSED(op)) fcu->flag &= ~FCURVE_DISABLED; /* for drivers, let's do the same too */ - if (fcu->driver) + if (fcu->driver) { fcu->driver->flag &= ~DRIVER_FLAG_INVALID; + } /* tag everything for updates - in particular, this is needed to get drivers working again */ ale->update |= ANIM_UPDATE_DEPS; @@ -2308,8 +2397,9 @@ static bool animchannels_find_poll(bContext *C) { ScrArea *sa = CTX_wm_area(C); - if (sa == NULL) + if (sa == NULL) { return 0; + } /* animation editor with dopesheet */ return ELEM(sa->spacetype, SPACE_ACTION, SPACE_GRAPH, SPACE_NLA); @@ -2321,8 +2411,9 @@ static int animchannels_find_invoke(bContext *C, wmOperator *op, const wmEvent * bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* set initial filter text, and enable filter */ RNA_string_set(op->ptr, "query", ac.ads->searchstr); @@ -2337,8 +2428,9 @@ static int animchannels_find_exec(bContext *C, wmOperator *op) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* update filter text */ RNA_string_get(op->ptr, "query", ac.ads->searchstr); @@ -2380,8 +2472,9 @@ static int animchannels_deselectall_exec(bContext *C, wmOperator *op) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* 'standard' behavior - check if selected, then apply relevant selection */ const int action = RNA_enum_get(op->ptr, "action"); @@ -2460,10 +2553,12 @@ static void box_select_anim_channels(bAnimContext *ac, rcti *rect, short selectm /* loop over data, doing box select */ for (ale = anim_data.first; ale; ale = ale->next) { - if (ac->datatype == ANIMCONT_NLA) + if (ac->datatype == ANIMCONT_NLA) { ymin = ymax - NLACHANNEL_STEP(snla); - else + } + else { ymin = ymax - ACHANNEL_STEP(ac); + } /* if channel is within border-select region, alter it */ if (!((ymax < rectf.ymin) || (ymin > rectf.ymax))) { @@ -2510,8 +2605,9 @@ static int animchannels_box_select_exec(bContext *C, wmOperator *op) const bool extend = RNA_boolean_get(op->ptr, "extend"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get settings from operator */ WM_operator_properties_border_to_rcti(op, &rect); @@ -2578,14 +2674,22 @@ static bool rename_anim_channels(bAnimContext *ac, int channel_index) ale = BLI_findlink(&anim_data, channel_index); if (ale == NULL) { /* channel not found */ - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: animation channel (index = %d) not found in rename_anim_channels()\n", channel_index); + } ANIM_animdata_freelist(&anim_data); return false; } + /* don't allow renaming linked channels */ + if ((ale->fcurve_owner_id != NULL && ID_IS_LINKED(ale->fcurve_owner_id)) || + (ale->id != NULL && ID_IS_LINKED(ale->id))) { + ANIM_animdata_freelist(&anim_data); + return false; + } + /* check that channel can be renamed */ acf = ANIM_channel_get_typeinfo(ale); if (acf && acf->name_prop) { @@ -2625,10 +2729,11 @@ static int animchannels_channel_get(bAnimContext *ac, const int mval[2]) ar = ac->ar; v2d = &ar->v2d; - /* figure out which channel user clicked in - * Note: although channels technically start at (y = ACHANNEL_FIRST), we need to adjust by half a channel's height - * so that the tops of channels get caught ok. Since ACHANNEL_FIRST is really ACHANNEL_HEIGHT, we simply use - * ACHANNEL_HEIGHT_HALF. + /* Figure out which channel user clicked in. + * + * Note: although channels technically start at (y = ACHANNEL_FIRST), + * we need to adjust by half a channel's height so that the tops of channels get caught ok. + * Since ACHANNEL_FIRST is really ACHANNEL_HEIGHT, we simply use ACHANNEL_HEIGHT_HALF. */ UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y); @@ -2665,17 +2770,20 @@ static int animchannels_rename_invoke(bContext *C, wmOperator *UNUSED(op), const int channel_index; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } channel_index = animchannels_channel_get(&ac, event->mval); /* handle click */ - if (rename_anim_channels(&ac, channel_index)) + if (rename_anim_channels(&ac, channel_index)) { return OPERATOR_FINISHED; - else + } + else { /* allow event to be handled by selectall operator */ return OPERATOR_PASS_THROUGH; + } } static void ANIM_OT_channels_rename(wmOperatorType *ot) @@ -2709,15 +2817,17 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index, ale = BLI_findlink(&anim_data, channel_index); if (ale == NULL) { /* channel not found */ - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: animation channel (index = %d) not found in mouse_anim_channels()\n", channel_index); + } ANIM_animdata_freelist(&anim_data); return 0; } - /* selectmode -1 is a special case for ActionGroups only, which selects all of the channels underneath it only... */ + /* selectmode -1 is a special case for ActionGroups only, + * which selects all of the channels underneath it only. */ /* TODO: should this feature be extended to work with other channel types too? */ if ((selectmode == -1) && (ale->type != ANIMTYPE_GROUP)) { /* normal channels should not behave normally in this case */ @@ -2736,13 +2846,15 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index, if (selectmode == SELECT_INVERT) { /* swap select */ sce->flag ^= SCE_DS_SELECTED; - if (adt) + if (adt) { adt->flag ^= ADT_UI_SELECTED; + } } else { sce->flag |= SCE_DS_SELECTED; - if (adt) + if (adt) { adt->flag |= ADT_UI_SELECTED; + } } notifierFlags |= (ND_ANIMCHAN | NA_SELECTED); @@ -2763,10 +2875,10 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index, if (selectmode == SELECT_INVERT) { /* swap select */ ED_object_base_select(base, BA_INVERT); - BKE_scene_object_base_flag_sync_from_base(base); - if (adt) + if (adt) { adt->flag ^= ADT_UI_SELECTED; + } } else { Base *b; @@ -2775,25 +2887,27 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index, /* TODO: should this deselect all other types of channels too? */ for (b = view_layer->object_bases.first; b; b = b->next) { ED_object_base_select(b, BA_DESELECT); - BKE_scene_object_base_flag_sync_from_base(b); - if (b->object->adt) + if (b->object->adt) { b->object->adt->flag &= ~(ADT_UI_SELECTED | ADT_UI_ACTIVE); + } } /* select object now */ ED_object_base_select(base, BA_SELECT); - BKE_scene_object_base_flag_sync_from_base(base); - if (adt) + if (adt) { adt->flag |= ADT_UI_SELECTED; + } } /* change active object - regardless of whether it is now selected [T37883] */ ED_object_base_activate(C, base); /* adds notifier */ - if ((adt) && (adt->flag & ADT_UI_SELECTED)) + if ((adt) && (adt->flag & ADT_UI_SELECTED)) { adt->flag |= ADT_UI_ACTIVE; + } - /* ensure we exit editmode on whatever object was active before to avoid getting stuck there - T48747 */ + /* Ensure we exit editmode on whatever object was active before + * to avoid getting stuck there - T48747. */ if (ob != CTX_data_edit_object(C)) { ED_object_editmode_exit(C, EM_FREEDATA); } @@ -2835,8 +2949,9 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index, } /* set active? */ - if ((ale->adt) && (ale->adt->flag & ADT_UI_SELECTED)) + if ((ale->adt) && (ale->adt->flag & ADT_UI_SELECTED)) { ale->adt->flag |= ADT_UI_ACTIVE; + } } notifierFlags |= (ND_ANIMCHAN | NA_SELECTED); @@ -2884,19 +2999,22 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index, /* deselect all other channels */ ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, false, ACHANNEL_SETFLAG_CLEAR); - if (pchan) + if (pchan) { ED_pose_deselect_all(ob, SEL_DESELECT, false); + } /* only select channels in group and group itself */ - for (fcu = agrp->channels.first; fcu && fcu->grp == agrp; fcu = fcu->next) + for (fcu = agrp->channels.first; fcu && fcu->grp == agrp; fcu = fcu->next) { fcu->flag |= FCURVE_SELECTED; + } agrp->flag |= AGRP_SELECTED; } else { /* select group by itself */ ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, false, ACHANNEL_SETFLAG_CLEAR); - if (pchan) + if (pchan) { ED_pose_deselect_all(ob, SEL_DESELECT, false); + } agrp->flag |= AGRP_SELECTED; } @@ -2904,13 +3022,15 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index, /* if group is selected now, make group the 'active' one in the visible list */ if (agrp->flag & AGRP_SELECTED) { ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, agrp, ANIMTYPE_GROUP); - if (pchan) + if (pchan) { ED_pose_bone_select(ob, pchan, true); + } } else { ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, NULL, ANIMTYPE_GROUP); - if (pchan) + if (pchan) { ED_pose_bone_select(ob, pchan, false); + } } notifierFlags |= (ND_ANIMCHAN | NA_SELECTED); @@ -2932,8 +3052,9 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index, } /* if F-Curve is selected now, make F-Curve the 'active' one in the visible list */ - if (fcu->flag & FCURVE_SELECTED) + if (fcu->flag & FCURVE_SELECTED) { ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, fcu, ale->type); + } notifierFlags |= (ND_ANIMCHAN | NA_SELECTED); break; @@ -2958,9 +3079,10 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index, case ANIMTYPE_NLACONTROLS: { AnimData *adt = (AnimData *)ale->data; - /* toggle expand - * - Although the triangle widget already allows this, since there's nothing else that can be done here now, - * let's just use it for easier expand/collapse for now + /* Toggle expand: + * - Although the triangle widget already allows this, + * since there's nothing else that can be done here now, + * let's just use it for easier expand/collapse for now. */ adt->flag ^= ADT_NLA_SKEYS_COLLAPSED; @@ -2970,8 +3092,9 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index, case ANIMTYPE_GPDATABLOCK: { bGPdata *gpd = (bGPdata *)ale->data; - /* toggle expand - * - although the triangle widget already allows this, the whole channel can also be used for this purpose + /* Toggle expand: + * - Although the triangle widget already allows this, + * the whole channel can also be used for this purpose. */ gpd->flag ^= GP_DATA_EXPAND; @@ -3008,8 +3131,9 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index, case ANIMTYPE_MASKDATABLOCK: { Mask *mask = (Mask *)ale->data; - /* toggle expand - * - although the triangle widget already allows this, the whole channel can also be used for this purpose + /* Toggle expand + * - Although the triangle widget already allows this, + * the whole channel can also be used for this purpose. */ mask->flag ^= MASK_ANIMF_EXPAND; @@ -3034,8 +3158,9 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index, break; } default: - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: Invalid channel type in mouse_anim_channels()\n"); + } break; } @@ -3060,8 +3185,9 @@ static int animchannels_mouseclick_invoke(bContext *C, wmOperator *op, const wmE float x, y; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get useful pointers from animation context data */ ar = ac.ar; @@ -3151,9 +3277,10 @@ static bool select_anim_channel_keys(bAnimContext *ac, int channel_index, bool e ale = BLI_findlink(&anim_data, channel_index); if (ale == NULL) { /* channel not found */ - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: animation channel (index = %d) not found in rename_anim_channels()\n", channel_index); + } ANIM_animdata_freelist(&anim_data); return false; @@ -3203,8 +3330,9 @@ static int animchannels_channel_select_keys_invoke(bContext *C, bool extend = RNA_boolean_get(op->ptr, "extend"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } channel_index = animchannels_channel_get(&ac, event->mval); @@ -3213,9 +3341,10 @@ static int animchannels_channel_select_keys_invoke(bContext *C, WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); return OPERATOR_FINISHED; } - else + else { /* allow event to be handled by selectall operator */ return OPERATOR_PASS_THROUGH; + } } static void ANIM_OT_channel_select_keys(wmOperatorType *ot) diff --git a/source/blender/editors/animation/anim_deps.c b/source/blender/editors/animation/anim_deps.c index 53fec2e1ef7..5c9f0707aa9 100644 --- a/source/blender/editors/animation/anim_deps.c +++ b/source/blender/editors/animation/anim_deps.c @@ -63,8 +63,9 @@ void ANIM_list_elem_update(Main *bmain, Scene *scene, bAnimListElem *ale) AnimData *adt; id = ale->id; - if (!id) + if (!id) { return; + } /* tag AnimData for refresh so that other views will update in realtime with these changes */ adt = BKE_animdata_from_id(id); @@ -97,8 +98,9 @@ void ANIM_list_elem_update(Main *bmain, Scene *scene, bAnimListElem *ale) RNA_id_pointer_create(id, &id_ptr); - if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) + if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) { RNA_property_update_main(bmain, scene, &ptr, prop); + } } else { /* in other case we do standard depsgraph update, ideally @@ -141,15 +143,17 @@ static void animchan_sync_group(bAnimContext *ac, bAnimListElem *ale, bActionGro /* major priority is selection status * so we need both a group and an owner */ - if (ELEM(NULL, agrp, owner_id)) + if (ELEM(NULL, agrp, owner_id)) { return; + } /* for standard Objects, check if group is the name of some bone */ if (GS(owner_id->name) == ID_OB) { Object *ob = (Object *)owner_id; /* check if there are bones, and whether the name matches any - * NOTE: this feature will only really work if groups by default contain the F-Curves for a single bone + * NOTE: this feature will only really work if groups by default contain the F-Curves + * for a single bone. */ if (ob->pose) { bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, agrp->name); @@ -159,10 +163,12 @@ static void animchan_sync_group(bAnimContext *ac, bAnimListElem *ale, bActionGro bActionGroup *bgrp; /* if one matches, sync the selection status */ - if ((pchan->bone) && (pchan->bone->flag & BONE_SELECTED)) + if ((pchan->bone) && (pchan->bone->flag & BONE_SELECTED)) { agrp->flag |= AGRP_SELECTED; - else + } + else { agrp->flag &= ~AGRP_SELECTED; + } /* also sync active group status */ if ((ob == ac->obact) && (pchan->bone == arm->act_bone)) { @@ -203,8 +209,9 @@ static void animchan_sync_fcurve(bAnimContext *UNUSED(ac), /* major priority is selection status, so refer to the checks done in anim_filter.c * skip_fcurve_selected_data() for reference about what's going on here... */ - if (ELEM(NULL, fcu, fcu->rna_path, owner_id)) + if (ELEM(NULL, fcu, fcu->rna_path, owner_id)) { return; + } if (GS(owner_id->name) == ID_SCE) { Scene *scene = (Scene *)owner_id; @@ -218,15 +225,18 @@ static void animchan_sync_fcurve(bAnimContext *UNUSED(ac), /* get strip name, and check if this strip is selected */ seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all["); seq = BKE_sequence_get_by_name(ed->seqbasep, seq_name, false); - if (seq_name) + if (seq_name) { MEM_freeN(seq_name); + } /* update selection status */ if (seq) { - if (seq->flag & SELECT) + if (seq->flag & SELECT) { fcu->flag |= FCURVE_SELECTED; - else + } + else { fcu->flag &= ~FCURVE_SELECTED; + } } } } @@ -241,16 +251,19 @@ static void animchan_sync_fcurve(bAnimContext *UNUSED(ac), /* get strip name, and check if this strip is selected */ node_name = BLI_str_quoted_substrN(fcu->rna_path, "nodes["); node = nodeFindNodebyName(ntree, node_name); - if (node_name) + if (node_name) { MEM_freeN(node_name); + } /* update selection/active status */ if (node) { /* update selection status */ - if (node->flag & NODE_SELECT) + if (node->flag & NODE_SELECT) { fcu->flag |= FCURVE_SELECTED; - else + } + else { fcu->flag &= ~FCURVE_SELECTED; + } /* update active status */ /* XXX: this may interfere with setting bones as active if both exist at once; @@ -310,12 +323,15 @@ void ANIM_sync_animchannels_to_data(const bContext *C) FCurve *active_fcurve = NULL; /* get animation context info for filtering the channels */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return; + } /* filter data */ - /* NOTE: we want all channels, since we want to be able to set selection status on some of them even when collapsed - * However, don't include duplicates so that selection statuses don't override each other + + /* NOTE: we want all channels, since we want to be able to set selection status on some of them + * even when collapsed... however, + * don't include duplicates so that selection statuses don't override each other. */ filter = ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_CHANNELS | ANIMFILTER_NODUPLIS; ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); @@ -361,7 +377,7 @@ void ANIM_animdata_update(bAnimContext *ac, ListBase *anim_data) if (ale->update & ANIM_UPDATE_ORDER) { ale->update &= ~ANIM_UPDATE_ORDER; if (gpl) { - //gpencil_sort_frames(gpl); + // gpencil_sort_frames(gpl); } } @@ -379,14 +395,16 @@ void ANIM_animdata_update(bAnimContext *ac, ListBase *anim_data) if (ale->update & ANIM_UPDATE_ORDER) { ale->update &= ~ANIM_UPDATE_ORDER; - if (fcu) + if (fcu) { sort_time_fcurve(fcu); + } } if (ale->update & ANIM_UPDATE_HANDLES) { ale->update &= ~ANIM_UPDATE_HANDLES; - if (fcu) + if (fcu) { calchandles_fcurve(fcu); + } } if (ale->update & ANIM_UPDATE_DEPS) { @@ -408,7 +426,10 @@ void ANIM_animdata_update(bAnimContext *ac, ListBase *anim_data) #if 0 if (G.debug & G_DEBUG) { printf("%s: Unhandled animchannel updates (%d) for type=%d (%p)\n", - __func__, ale->update, ale->type, ale->data); + __func__, + ale->update, + ale->type, + ale->data); } #endif /* Prevent crashes in cases where it can't be handled */ diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c index 11c768a8efd..61bf7f95340 100644 --- a/source/blender/editors/animation/anim_draw.c +++ b/source/blender/editors/animation/anim_draw.c @@ -169,7 +169,7 @@ void ANIM_draw_previewrange(const bContext *C, View2D *v2d, int end_frame_width) immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); immUniformThemeColorShadeAlpha(TH_ANIM_PREVIEW_RANGE, -25, -30); /* XXX: Fix this hardcoded color (anim_active) */ - //immUniformColor4f(0.8f, 0.44f, 0.1f, 0.2f); + // immUniformColor4f(0.8f, 0.44f, 0.1f, 0.2f); /* only draw two separate 'curtains' if there's no overlap between them */ if (PSFRA < PEFRA + end_frame_width) { @@ -237,12 +237,14 @@ void ANIM_draw_framerange(Scene *scene, View2D *v2d) AnimData *ANIM_nla_mapping_get(bAnimContext *ac, bAnimListElem *ale) { /* sanity checks */ - if (ac == NULL) + if (ac == NULL) { return NULL; + } /* abort if rendering - we may get some race condition issues... */ - if (G.is_rendering) + if (G.is_rendering) { return NULL; + } /* apart from strictly keyframe-related contexts, this shouldn't even happen */ // XXX: nla and channel here may not be necessary... @@ -255,9 +257,11 @@ AnimData *ANIM_nla_mapping_get(bAnimContext *ac, bAnimListElem *ale) ANIMCONT_CHANNEL)) { /* handling depends on the type of animation-context we've got */ if (ale) { - /* NLA Control Curves occur on NLA strips, and shouldn't be subjected to this kind of mapping */ - if (ale->type != ANIMTYPE_NLACURVE) + /* NLA Control Curves occur on NLA strips, + * and shouldn't be subjected to this kind of mapping. */ + if (ale->type != ANIMTYPE_NLACURVE) { return ale->adt; + } } } @@ -267,7 +271,8 @@ AnimData *ANIM_nla_mapping_get(bAnimContext *ac, bAnimListElem *ale) /* ------------------- */ -/* helper function for ANIM_nla_mapping_apply_fcurve() -> "restore", i.e. mapping points back to action-time */ +/* Helper function for ANIM_nla_mapping_apply_fcurve() -> "restore", + * i.e. mapping points back to action-time. */ static short bezt_nlamapping_restore(KeyframeEditData *ked, BezTriple *bezt) { /* AnimData block providing scaling is stored in 'data', only_keys option is stored in i1 */ @@ -321,10 +326,12 @@ void ANIM_nla_mapping_apply_fcurve(AnimData *adt, FCurve *fcu, bool restore, boo ked.i1 = (int)only_keys; /* get editing callback */ - if (restore) + if (restore) { map_cb = bezt_nlamapping_restore; - else + } + else { map_cb = bezt_nlamapping_apply; + } /* apply to F-Curve */ ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, map_cb, NULL); @@ -353,15 +360,17 @@ static float normalization_factor_get(Scene *scene, FCurve *fcu, short flag, flo float factor = 1.0f, offset = 0.0f; if (flag & ANIM_UNITCONV_RESTORE) { - if (r_offset) + if (r_offset) { *r_offset = fcu->prev_offset; + } return 1.0f / fcu->prev_norm_factor; } if (flag & ANIM_UNITCONV_NORMALIZE_FREEZE) { - if (r_offset) + if (r_offset) { *r_offset = fcu->prev_offset; + } if (fcu->prev_norm_factor == 0.0f) { /* Happens when Auto Normalize was disabled before * any curves were displayed. @@ -372,8 +381,9 @@ static float normalization_factor_get(Scene *scene, FCurve *fcu, short flag, flo } if (G.moving & G_TRANSFORM_FCURVES) { - if (r_offset) + if (r_offset) { *r_offset = fcu->prev_offset; + } if (fcu->prev_norm_factor == 0.0f) { /* Same as above. */ return 1.0f; @@ -497,8 +507,9 @@ float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag return normalization_factor_get(scene, fcu, flag, r_offset); } - if (r_offset) + if (r_offset) { *r_offset = 0.0f; + } /* sanity checks */ if (id && fcu && fcu->rna_path) { @@ -512,10 +523,12 @@ float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION) { /* if the radians flag is not set, default to using degrees which need conversions */ if ((scene) && (scene->unit.system_rotation == USER_UNIT_ROT_RADIANS) == 0) { - if (flag & ANIM_UNITCONV_RESTORE) + if (flag & ANIM_UNITCONV_RESTORE) { return DEG2RADF(1.0f); /* degrees to radians */ - else + } + else { return RAD2DEGF(1.0f); /* radians to degrees */ + } } } @@ -575,8 +588,9 @@ static bool find_prev_next_keyframes(struct bContext *C, int *nextfra, int *prev } else { /* this changes the frame, so set the frame and we're done */ - if (++nextcount == U.view_frame_keyframes) + if (++nextcount == U.view_frame_keyframes) { donenext = true; + } } cfranext = aknext->cfra; } @@ -591,8 +605,9 @@ static bool find_prev_next_keyframes(struct bContext *C, int *nextfra, int *prev } else { /* this changes the frame, so set the frame and we're done */ - if (++prevcount == U.view_frame_keyframes) + if (++prevcount == U.view_frame_keyframes) { doneprev = true; + } } cfraprev = akprev->cfra; } @@ -603,15 +618,19 @@ static bool find_prev_next_keyframes(struct bContext *C, int *nextfra, int *prev /* any success? */ if (doneprev || donenext) { - if (doneprev) + if (doneprev) { *prevfra = cfraprev; - else + } + else { *prevfra = CFRA - (cfranext - CFRA); + } - if (donenext) + if (donenext) { *nextfra = cfranext; - else + } + else { *nextfra = CFRA + (CFRA - cfraprev); + } return true; } diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index 57ea5ad81f5..b94d0e3ada7 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -114,9 +114,10 @@ static void animedit_get_yscale_factor(bAnimContext *ac) ac->yscale_fac = btheme->space_action.keyframe_scale_fac; /* clamp to avoid problems with uninitialised values... */ - if (ac->yscale_fac < 0.1f) + if (ac->yscale_fac < 0.1f) { ac->yscale_fac = 1.0f; - //printf("yscale_fac = %f\n", ac->yscale_fac); + } + // printf("yscale_fac = %f\n", ac->yscale_fac); } /* ----------- Private Stuff - Action Editor ------------- */ @@ -130,18 +131,20 @@ static Key *actedit_get_shapekeys(bAnimContext *ac) Key *key; ob = OBACT(view_layer); - if (ob == NULL) + if (ob == NULL) { return NULL; + } /* XXX pinning is not available in 'ShapeKey' mode... */ - //if (saction->pin) return NULL; + // if (saction->pin) return NULL; /* shapekey data is stored with geometry data */ key = BKE_key_from_object(ob); if (key) { - if (key->type == KEY_RELATIVE) + if (key->type == KEY_RELATIVE) { return key; + } } return NULL; @@ -158,10 +161,12 @@ static bool actedit_get_context(bAnimContext *ac, SpaceAction *saction) case SACTCONT_ACTION: /* 'Action Editor' */ /* if not pinned, sync with active object */ if (/*saction->pin == 0*/ true) { - if (ac->obact && ac->obact->adt) + if (ac->obact && ac->obact->adt) { saction->action = ac->obact->adt->action; - else + } + else { saction->action = NULL; + } } ac->datatype = ANIMCONT_ACTION; @@ -178,10 +183,12 @@ static bool actedit_get_context(bAnimContext *ac, SpaceAction *saction) if (/*saction->pin == 0*/ true) { Key *key = (Key *)ac->data; - if (key && key->adt) + if (key && key->adt) { saction->action = key->adt->action; - else + } + else { saction->action = NULL; + } } ac->mode = saction->mode; @@ -211,7 +218,7 @@ static bool actedit_get_context(bAnimContext *ac, SpaceAction *saction) { /* TODO, other methods to get the mask */ // Sequence *seq = BKE_sequencer_active_get(ac->scene); - //MovieClip *clip = ac->scene->clip; + // MovieClip *clip = ac->scene->clip; // struct Mask *mask = seq ? seq->mask : NULL; /* update scene-pointer (no need to check for pinning yet, as not implemented) */ @@ -239,16 +246,19 @@ static bool actedit_get_context(bAnimContext *ac, SpaceAction *saction) saction->ads.source = (ID *)ac->scene; /* sync scene's "selected keys only" flag with our "only selected" flag + * * XXX: This is a workaround for T55525. We shouldn't really be syncing the flags like this, - * but it's a simpler fix for now than also figuring out how the next/prev keyframe tools - * should work in the 3D View if we allowed full access to the timeline's dopesheet filters - * (i.e. we'd have to figure out where to host those settings, to be on a scene level like - * this flag currently is, along with several other unknowns) + * but it's a simpler fix for now than also figuring out how the next/prev keyframe + * tools should work in the 3D View if we allowed full access to the timeline's + * dopesheet filters (i.e. we'd have to figure out where to host those settings, + * to be on a scene level like this flag currently is, along with several other unknowns). */ - if (ac->scene->flag & SCE_KEYS_NO_SELONLY) + if (ac->scene->flag & SCE_KEYS_NO_SELONLY) { saction->ads.filterflag &= ~ADS_FILTER_ONLYSEL; - else + } + else { saction->ads.filterflag |= ADS_FILTER_ONLYSEL; + } ac->datatype = ANIMCONT_TIMELINE; ac->data = &saction->ads; @@ -278,10 +288,12 @@ static bool graphedit_get_context(bAnimContext *ac, SpaceGraph *sipo) ac->ads = sipo->ads; /* set settings for Graph Editor - "Selected = Editable" */ - if (sipo->flag & SIPO_SELCUVERTSONLY) + if (sipo->flag & SIPO_SELCUVERTSONLY) { sipo->ads->filterflag |= ADS_FILTER_SELEDIT; - else + } + else { sipo->ads->filterflag &= ~ADS_FILTER_SELEDIT; + } /* sync settings with current view status, then return appropriate data */ switch (sipo->mode) { @@ -322,8 +334,9 @@ static bool graphedit_get_context(bAnimContext *ac, SpaceGraph *sipo) static bool nlaedit_get_context(bAnimContext *ac, SpaceNla *snla) { /* init dopesheet data if non-existent (i.e. for old files) */ - if (snla->ads == NULL) + if (snla->ads == NULL) { snla->ads = MEM_callocN(sizeof(bDopeSheet), "NlaEdit DopeSheet"); + } ac->ads = snla->ads; /* sync settings with current view status, then return appropriate data */ @@ -339,7 +352,8 @@ static bool nlaedit_get_context(bAnimContext *ac, SpaceNla *snla) /* ----------- Public API --------------- */ -/* Obtain current anim-data context, given that context info from Blender context has already been set +/* Obtain current anim-data context, + * given that context info from Blender context has already been set: * - AnimContext to write to is provided as pointer to var on stack so that we don't have * allocation/freeing costs (which are not that avoidable with channels). */ @@ -387,8 +401,9 @@ bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac) Scene *scene = CTX_data_scene(C); /* clear old context info */ - if (ac == NULL) + if (ac == NULL) { return false; + } memset(ac, 0, sizeof(bAnimContext)); /* get useful default context settings from context */ @@ -410,7 +425,8 @@ bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac) animedit_get_yscale_factor(ac); /* get data context info */ - // XXX: if the below fails, try to grab this info from context instead... (to allow for scripting) + /* XXX: if the below fails, try to grab this info from context instead... + * (to allow for scripting). */ return ANIM_animdata_context_getdata(ac); } @@ -467,20 +483,25 @@ bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac) /* quick macro to test if AnimData is usable for NLA */ #define ANIMDATA_HAS_NLA(id) ((id)->adt && (id)->adt->nla_tracks.first) -/* Quick macro to test for all three above usability tests, performing the appropriate provided +/** + * Quick macro to test for all three above usability tests, performing the appropriate provided * action for each when the AnimData context is appropriate. * - * Priority order for this goes (most important, to least): AnimData blocks, NLA, Drivers, Keyframes. + * Priority order for this goes (most important, to least): + * AnimData blocks, NLA, Drivers, Keyframes. + * + * For this to work correctly, + * a standard set of data needs to be available within the scope that this * - * For this to work correctly, a standard set of data needs to be available within the scope that this - * gets called in: + * Gets called in: * - ListBase anim_data; * - bDopeSheet *ads; * - bAnimListElem *ale; * - size_t items; * * - id: ID block which should have an AnimData pointer following it immediately, to use - * - adtOk: line or block of code to execute for AnimData-blocks case (usually ANIMDATA_ADD_ANIMDATA) + * - adtOk: line or block of code to execute for AnimData-blocks case + * (usually #ANIMDATA_ADD_ANIMDATA). * - nlaOk: line or block of code to execute for NLA tracks+strips case * - driversOk: line or block of code to execute for Drivers case * - nlaKeysOk: line or block of code for NLA Strip Keyframes case @@ -563,7 +584,8 @@ bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac) #define ANIMCHANNEL_ACTIVEOK(ale) \ (!(filter_mode & ANIMFILTER_ACTIVE) || !(ale->adt) || (ale->adt->flag & ADT_UI_ACTIVE)) -/* quick macro to test if an anim-channel (F-Curve, Group, etc.) is selected in an acceptable way */ +/* Quick macro to test if an anim-channel (F-Curve, Group, etc.) + * is selected in an acceptable way. */ #define ANIMCHANNEL_SELOK(test_func) \ (!(filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) || \ ((filter_mode & ANIMFILTER_SEL) && test_func) || \ @@ -986,27 +1008,32 @@ static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id /* get bone-name, and check if this bone is selected */ bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones["); pchan = BKE_pose_channel_find_name(ob->pose, bone_name); - if (bone_name) + if (bone_name) { MEM_freeN(bone_name); + } /* check whether to continue or skip */ if ((pchan) && (pchan->bone)) { - /* if only visible channels, skip if bone not visible unless user wants channels from hidden data too */ + /* If only visible channels, + * skip if bone not visible unless user wants channels from hidden data too. */ if (skip_hidden) { bArmature *arm = (bArmature *)ob->data; /* skipping - not visible on currently visible layers */ - if ((arm->layer & pchan->bone->layer) == 0) + if ((arm->layer & pchan->bone->layer) == 0) { return true; + } /* skipping - is currently hidden */ - if (pchan->bone->flag & BONE_HIDDEN_P) + if (pchan->bone->flag & BONE_HIDDEN_P) { return true; + } } /* can only add this F-Curve if it is selected */ if (ads->filterflag & ADS_FILTER_ONLYSEL) { - if ((pchan->bone->flag & BONE_SELECTED) == 0) + if ((pchan->bone->flag & BONE_SELECTED) == 0) { return true; + } } } } @@ -1024,14 +1051,16 @@ static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id /* get strip name, and check if this strip is selected */ seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all["); seq = BKE_sequence_get_by_name(ed->seqbasep, seq_name, false); - if (seq_name) + if (seq_name) { MEM_freeN(seq_name); + } } /* can only add this F-Curve if it is selected */ if (ads->filterflag & ADS_FILTER_ONLYSEL) { - if ((seq == NULL) || (seq->flag & SELECT) == 0) + if ((seq == NULL) || (seq->flag & SELECT) == 0) { return true; + } } } } @@ -1046,13 +1075,15 @@ static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id /* get strip name, and check if this strip is selected */ node_name = BLI_str_quoted_substrN(fcu->rna_path, "nodes["); node = nodeFindNodebyName(ntree, node_name); - if (node_name) + if (node_name) { MEM_freeN(node_name); + } /* can only add this F-Curve if it is selected */ if (ads->filterflag & ADS_FILTER_ONLYSEL) { - if ((node) && (node->flag & NODE_SELECT) == 0) + if ((node) && (node->flag & NODE_SELECT) == 0) { return true; + } } } } @@ -1144,15 +1175,17 @@ static bool fcurve_has_errors(FCurve *fcu) * BUT this may not hold with PyDrivers as this flag gets cleared * if no critical errors prevent the driver from working... */ - if (driver->flag & DRIVER_FLAG_INVALID) + if (driver->flag & DRIVER_FLAG_INVALID) { return true; + } /* check variables for other things that need linting... */ // TODO: maybe it would be more efficient just to have a quick flag for this? for (dvar = driver->variables.first; dvar; dvar = dvar->next) { DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) { - if (dtar->flag & DTAR_FLAG_INVALID) + if (dtar->flag & DTAR_FLAG_INVALID) { return true; + } } DRIVER_TARGETS_LOOPER_END; } @@ -1173,24 +1206,28 @@ static FCurve *animfilter_fcurve_next(bDopeSheet *ads, bActionGroup *grp = (channel_type == ANIMTYPE_FCURVE) ? owner : NULL; FCurve *fcu = NULL; - /* loop over F-Curves - assume that the caller of this has already checked that these should be included - * NOTE: we need to check if the F-Curves belong to the same group, as this gets called for groups too... + /* Loop over F-Curves - assume that the caller of this has already checked + * that these should be included. + * NOTE: we need to check if the F-Curves belong to the same group, + * as this gets called for groups too... */ for (fcu = first; ((fcu) && (fcu->grp == grp)); fcu = fcu->next) { /* special exception for Pose-Channel/Sequence-Strip/Node Based F-Curves: - * - the 'Only Selected' and 'Include Hidden' data filters should be applied to sub-ID data which - * can be independently selected/hidden, such as Pose-Channels, Sequence Strips, and Nodes. - * Since these checks were traditionally done as first check for objects, we do the same here - * - we currently use an 'approximate' method for getting these F-Curves that doesn't require - * carefully checking the entire path - * - this will also affect things like Drivers, and also works for Bone Constraints + * - The 'Only Selected' and 'Include Hidden' data filters should be applied to sub-ID data + * which can be independently selected/hidden, such as Pose-Channels, Sequence Strips, + * and Nodes. Since these checks were traditionally done as first check for objects, + * we do the same here. + * - We currently use an 'approximate' method for getting these F-Curves that doesn't require + * carefully checking the entire path. + * - This will also affect things like Drivers, and also works for Bone Constraints. */ if (ads && owner_id) { if ((filter_mode & ANIMFILTER_TMP_IGNORE_ONLYSEL) == 0) { if ((ads->filterflag & ADS_FILTER_ONLYSEL) || (ads->filterflag & ADS_FILTER_INCL_HIDDEN) == 0) { - if (skip_fcurve_selected_data(ads, fcu, owner_id, filter_mode)) + if (skip_fcurve_selected_data(ads, fcu, owner_id, filter_mode)) { continue; + } } } } @@ -1199,21 +1236,24 @@ static FCurve *animfilter_fcurve_next(bDopeSheet *ads, if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || (fcu->flag & FCURVE_VISIBLE)) { /* only work with this channel and its subchannels if it is editable */ if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_FCU(fcu)) { - /* only include this curve if selected in a way consistent with the filtering requirements */ + /* Only include this curve if selected in a way consistent + * with the filtering requirements. */ if (ANIMCHANNEL_SELOK(SEL_FCU(fcu)) && ANIMCHANNEL_SELEDITOK(SEL_FCU(fcu))) { /* only include if this curve is active */ if (!(filter_mode & ANIMFILTER_ACTIVE) || (fcu->flag & FCURVE_ACTIVE)) { /* name based filtering... */ if (((ads) && (ads->searchstr[0] != '\0')) && (owner_id)) { - if (skip_fcurve_with_name(ads, fcu, channel_type, owner, owner_id)) + if (skip_fcurve_with_name(ads, fcu, channel_type, owner, owner_id)) { continue; + } } /* error-based filtering... */ if ((ads) && (ads->filterflag & ADS_FILTER_ONLY_ERRORS)) { /* skip if no errors... */ - if (fcurve_has_errors(fcu) == false) + if (fcurve_has_errors(fcu) == false) { continue; + } } /* this F-Curve can be used, so return it */ @@ -1240,14 +1280,17 @@ static size_t animfilter_fcurves(ListBase *anim_data, FCurve *fcu; size_t items = 0; - /* loop over every F-Curve able to be included - * - this for-loop works like this: - * 1) the starting F-Curve is assigned to the fcu pointer so that we have a starting point to search from - * 2) the first valid F-Curve to start from (which may include the one given as 'first') in the remaining - * list of F-Curves is found, and verified to be non-null - * 3) the F-Curve referenced by fcu pointer is added to the list - * 4) the fcu pointer is set to the F-Curve after the one we just added, so that we can keep going through - * the rest of the F-Curve list without an eternal loop. Back to step 2 :) + /* Loop over every F-Curve able to be included. + * + * This for-loop works like this: + * 1) The starting F-Curve is assigned to the fcu pointer + * so that we have a starting point to search from. + * 2) The first valid F-Curve to start from (which may include the one given as 'first') + * in the remaining list of F-Curves is found, and verified to be non-null. + * 3) The F-Curve referenced by fcu pointer is added to the list + * 4) The fcu pointer is set to the F-Curve after the one we just added, + * so that we can keep going through the rest of the F-Curve list without an eternal loop. + * Back to step 2 :) */ for (fcu = first; ((fcu = animfilter_fcurve_next(ads, fcu, fcurve_type, filter_mode, owner, owner_id))); @@ -1281,7 +1324,7 @@ static size_t animfilter_act_group(bAnimContext *ac, ListBase tmp_data = {NULL, NULL}; size_t tmp_items = 0; size_t items = 0; - //int ofilter = filter_mode; + // int ofilter = filter_mode; /* if we care about the selection status of the channels, * but the group isn't expanded (1)... @@ -1290,28 +1333,30 @@ static size_t animfilter_act_group(bAnimContext *ac, * - Hierarchy ignored: cases like [#21276] won't work properly, unless we skip this hack */ if ( - /* care about hierarchy but group isn't expanded */ + /* Care about hierarchy but group isn't expanded. */ ((filter_mode & ANIMFILTER_LIST_VISIBLE) && EXPANDED_AGRP(ac, agrp) == 0) && - /* care about selection status */ + /* Care about selection status. */ (filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL))) { - /* if the group itself isn't selected appropriately, we shouldn't consider it's children either */ - if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) == 0) + /* If the group itself isn't selected appropriately, + * we shouldn't consider it's children either. */ + if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) == 0) { return 0; + } - /* if we're still here, then the selection status of the curves within this group should not matter, - * since this creates too much overhead for animators (i.e. making a slow workflow) + /* if we're still here, + * then the selection status of the curves within this group should not matter, + * since this creates too much overhead for animators (i.e. making a slow workflow). * * Tools affected by this at time of coding (2010 Feb 09): - * - inserting keyframes on selected channels only - * - pasting keyframes - * - creating ghost curves in Graph Editor + * - Inserting keyframes on selected channels only. + * - Pasting keyframes. + * - Creating ghost curves in Graph Editor. */ filter_mode &= ~(ANIMFILTER_SEL | ANIMFILTER_UNSEL | ANIMFILTER_LIST_VISIBLE); } /* add grouped F-Curves */ - BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_AGRP(ac, agrp)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_AGRP(ac, agrp)) { /* special filter so that we can get just the F-Curves within the active group */ if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) { /* for the Graph Editor, curves may be set to not be visible in the view to lessen @@ -1339,12 +1384,12 @@ static size_t animfilter_act_group(bAnimContext *ac, /* add this group as a channel first */ if (filter_mode & ANIMFILTER_LIST_CHANNELS) { /* restore original filter mode so that this next step works ok... */ - //filter_mode = ofilter; + // filter_mode = ofilter; /* filter selection of channel specially here again, * since may be open and not subject to previous test */ if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp))) { - ANIMCHANNEL_NEW_CHANNEL(agrp, ANIMTYPE_GROUP, owner_id, NULL); + ANIMCHANNEL_NEW_CHANNEL(agrp, ANIMTYPE_GROUP, owner_id, &act->id); } } @@ -1372,15 +1417,17 @@ static size_t animfilter_action(bAnimContext *ac, /* don't include anything from this action if it is linked in from another file, * and we're getting stuff for editing... */ - if ((filter_mode & ANIMFILTER_FOREDIT) && ID_IS_LINKED(act)) + if ((filter_mode & ANIMFILTER_FOREDIT) && ID_IS_LINKED(act)) { return 0; + } /* do groups */ // TODO: do nested groups? for (agrp = act->groups.first; agrp; agrp = agrp->next) { /* store reference to last channel of group */ - if (agrp->channels.last) + if (agrp->channels.last) { lastchan = agrp->channels.last; + } /* action group's channels */ items += animfilter_act_group(ac, anim_data, ads, act, agrp, filter_mode, owner_id); @@ -1398,12 +1445,13 @@ static size_t animfilter_action(bAnimContext *ac, } /* Include NLA-Data for NLA-Editor: - * - when ANIMFILTER_LIST_CHANNELS is used, that means we should be filtering the list for display - * Although the evaluation order is from the first track to the last and then apply the Action on top, - * we present this in the UI as the Active Action followed by the last track to the first so that we - * get the evaluation order presented as per a stack. - * - for normal filtering (i.e. for editing), we only need the NLA-tracks but they can be in 'normal' evaluation - * order, i.e. first to last. Otherwise, some tools may get screwed up. + * - When ANIMFILTER_LIST_CHANNELS is used, that means we should be filtering the list for display + * Although the evaluation order is from the first track to the last and then apply the + * Action on top, we present this in the UI as the Active Action followed by the last track + * to the first so that we get the evaluation order presented as per a stack. + * - For normal filtering (i.e. for editing), + * we only need the NLA-tracks but they can be in 'normal' evaluation order, i.e. first to last. + * Otherwise, some tools may get screwed up. */ static size_t animfilter_nla(bAnimContext *UNUSED(ac), ListBase *anim_data, @@ -1424,9 +1472,10 @@ static size_t animfilter_nla(bAnimContext *UNUSED(ac), if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) || (adt->action)) { /* there isn't really anything editable here, so skip if need editable */ if ((filter_mode & ANIMFILTER_FOREDIT) == 0) { - /* just add the action track now (this MUST appear for drawing) - * - as AnimData may not have an action, we pass a dummy pointer just to get the list elem created, then - * overwrite this with the real value - REVIEW THIS... + /* Just add the action track now (this MUST appear for drawing): + * - As AnimData may not have an action, + * we pass a dummy pointer just to get the list elem created, + * then overwrite this with the real value - REVIEW THIS. */ ANIMCHANNEL_NEW_CHANNEL_FULL((void *)(&adt->action), ANIMTYPE_NLAACTION, owner_id, NULL, { ale->data = adt->action ? adt->action : NULL; @@ -1442,21 +1491,27 @@ static size_t animfilter_nla(bAnimContext *UNUSED(ac), first = adt->nla_tracks.first; } - /* loop over NLA Tracks - assume that the caller of this has already checked that these should be included */ + /* loop over NLA Tracks - + * assume that the caller of this has already checked that these should be included */ for (nlt = first; nlt; nlt = next) { /* 'next' NLA-Track to use depends on whether we're filtering for drawing or not */ - if (filter_mode & ANIMFILTER_LIST_CHANNELS) + if (filter_mode & ANIMFILTER_LIST_CHANNELS) { next = nlt->prev; - else + } + else { next = nlt->next; + } - /* if we're in NLA-tweakmode, don't show this track if it was disabled (due to tweaking) for now + /* if we're in NLA-tweakmode, don't show this track if it was disabled + * (due to tweaking) for now: * - active track should still get shown though (even though it has disabled flag set) */ - // FIXME: the channels after should still get drawn, just 'differently', and after an active-action channel + // FIXME: the channels after should still get drawn, just 'differently', + // and after an active-action channel. if ((adt->flag & ADT_NLA_EDIT_ON) && (nlt->flag & NLATRACK_DISABLED) && - (adt->act_track != nlt)) + (adt->act_track != nlt)) { continue; + } /* only work with this channel and its subchannels if it is editable */ if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_NLT(nlt)) { @@ -1510,15 +1565,15 @@ static size_t animfilter_nla_controls( /* add control curves from each NLA strip... */ /* NOTE: ANIMTYPE_FCURVES are created here, to avoid duplicating the code needed */ - BEGIN_ANIMFILTER_SUBCHANNELS(((adt->flag & ADT_NLA_SKEYS_COLLAPSED) == 0)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (((adt->flag & ADT_NLA_SKEYS_COLLAPSED) == 0)) { NlaTrack *nlt; NlaStrip *strip; /* for now, we only go one level deep - so controls on grouped FCurves are not handled */ for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { for (strip = nlt->strips.first; strip; strip = strip->next) { - /* pass strip as the "owner", so that the name lookups (used while filtering) will resolve */ + /* pass strip as the "owner", + * so that the name lookups (used while filtering) will resolve */ /* NLA tracks are coming from AnimData, so owner of f-curves * is the same as owner of animation data. */ tmp_items += animfilter_fcurves(&tmp_data, @@ -1565,8 +1620,9 @@ static size_t animfilter_block_data( if (adt) { IdAdtTemplate *iat = (IdAdtTemplate *)id; - /* NOTE: this macro is used instead of inlining the logic here, since this sort of filtering is still needed - * in a few places in the rest of the code still - notably for the few cases where special mode-based + /* NOTE: this macro is used instead of inlining the logic here, + * since this sort of filtering is still needed in a few places in the rest of the code still - + * notably for the few cases where special mode-based * different types of data expanders are required. */ ANIMDATA_FILTER_CASES( @@ -1610,12 +1666,14 @@ static size_t animdata_filter_shapekey(bAnimContext *ac, /* loop through the channels adding ShapeKeys as appropriate */ for (kb = key->block.first; kb; kb = kb->next) { /* skip the first one, since that's the non-animatable basis */ - if (kb == key->block.first) + if (kb == key->block.first) { continue; + } /* only work with this channel and its subchannels if it is editable */ if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_SHAPEKEY(kb)) { - /* only include this track if selected in a way consistent with the filtering requirements */ + /* Only include this track if selected in a way consistent + * with the filtering requirements. */ if (ANIMCHANNEL_SELOK(SEL_SHAPEKEY(kb))) { // TODO: consider 'active' too? @@ -1663,8 +1721,9 @@ static size_t animdata_filter_gpencil_layers_data(ListBase *anim_data, if (!(filter_mode & ANIMFILTER_ACTIVE) || (gpl->flag & GP_LAYER_ACTIVE)) { /* skip layer if the name doesn't match the filter string */ if ((ads) && (ads->searchstr[0] != '\0')) { - if (name_matches_dopesheet_filter(ads, gpl->info) == false) + if (name_matches_dopesheet_filter(ads, gpl->info) == false) { continue; + } } /* add to list */ ANIMCHANNEL_NEW_CHANNEL(gpl, ANIMTYPE_GPLAYER, gpd, NULL); @@ -1697,8 +1756,7 @@ static size_t animdata_filter_gpencil_data(ListBase *anim_data, size_t tmp_items = 0; /* add gpencil animation channels */ - BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_GPD(gpd)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_GPD(gpd)) { tmp_items += animdata_filter_gpencil_layers_data(&tmp_data, ads, gpd, filter_mode); } END_ANIMFILTER_SUBCHANNELS; @@ -1758,13 +1816,16 @@ static size_t animdata_filter_gpencil(bAnimContext *ac, */ if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) { - /* layer visibility - we check both object and base, since these may not be in sync yet */ - if ((base->flag & BASE_VISIBLE) == 0) + /* Layer visibility - we check both object and base, + * since these may not be in sync yet. */ + if ((base->flag & BASE_VISIBLE) == 0) { continue; + } /* outliner restrict-flag */ - if (ob->restrictflag & OB_RESTRICT_VIEW) + if (ob->restrictflag & OB_RESTRICT_VIEW) { continue; + } } /* check selection and object type filters */ @@ -1779,8 +1840,9 @@ static size_t animdata_filter_gpencil(bAnimContext *ac, * - used to ease the process of doing multiple-character choreographies */ if (ads->filter_grp != NULL) { - if (BKE_collection_has_object_recursive(ads->filter_grp, ob) == 0) + if (BKE_collection_has_object_recursive(ads->filter_grp, ob) == 0) { continue; + } } /* finally, include this object's grease pencil datablock */ @@ -1796,8 +1858,9 @@ static size_t animdata_filter_gpencil(bAnimContext *ac, * but only those that seem to be useful somewhere */ for (gpd = ac->bmain->gpencils.first; gpd; gpd = gpd->id.next) { /* only show if gpd is used by something... */ - if (ID_REAL_USERS(gpd) < 1) + if (ID_REAL_USERS(gpd) < 1) { continue; + } /* add GP frames from this datablock */ items += animdata_filter_gpencil_data(anim_data, ads, gpd, filter_mode); @@ -1817,8 +1880,7 @@ static size_t animdata_filter_ds_gpencil( size_t items = 0; /* add relevant animation channels for Grease Pencil */ - BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_GPD(gpd)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_GPD(gpd)) { /* add animation channels */ tmp_items += animfilter_block_data(ac, &tmp_data, ads, &gpd->id, filter_mode); @@ -1858,8 +1920,7 @@ static size_t animdata_filter_ds_cachefile( size_t items = 0; /* add relevant animation channels for Cache File */ - BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_CACHEFILE_OBJD(cache_file)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_CACHEFILE_OBJD(cache_file)) { /* add animation channels */ tmp_items += animfilter_block_data(ac, &tmp_data, ads, &cache_file->id, filter_mode); } @@ -1927,12 +1988,12 @@ static size_t animdata_filter_mask(Main *bmain, size_t tmp_items = 0; /* only show if mask is used by something... */ - if (ID_REAL_USERS(mask) < 1) + if (ID_REAL_USERS(mask) < 1) { continue; + } /* add mask animation channels */ - BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_MASK(mask)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_MASK(mask)) { tmp_items += animdata_filter_mask_data(&tmp_data, mask, filter_mode); } END_ANIMFILTER_SUBCHANNELS; @@ -1956,7 +2017,8 @@ static size_t animdata_filter_mask(Main *bmain, return items; } -/* NOTE: owner_id is scene, material, or texture block, which is the direct owner of the node tree in question */ +/* NOTE: owner_id is scene, material, or texture block, + * which is the direct owner of the node tree in question. */ static size_t animdata_filter_ds_nodetree_group(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, @@ -1969,8 +2031,7 @@ static size_t animdata_filter_ds_nodetree_group(bAnimContext *ac, size_t items = 0; /* add nodetree animation channels */ - BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_NTREE_DATA(ntree)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_NTREE_DATA(ntree)) { /* animation data filtering */ tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ntree, filter_mode); } @@ -2061,8 +2122,7 @@ static size_t animdata_filter_ds_linestyle( linestyle->id.tag &= ~LIB_TAG_DOIT; /* add scene-level animation channels */ - BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_LS_SCED(linestyle)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_LS_SCED(linestyle)) { /* animation data filtering */ tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)linestyle, filter_mode); } @@ -2102,16 +2162,16 @@ static size_t animdata_filter_ds_texture(bAnimContext *ac, size_t items = 0; /* add texture's animation data to temp collection */ - BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_TEX_DATA(tex)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_TEX_DATA(tex)) { /* texture animdata */ tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)tex, filter_mode); /* nodes */ if ((tex->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) { - /* owner_id as id instead of texture, since it'll otherwise be impossible to track the depth */ - // FIXME: perhaps as a result, textures should NOT be included under materials, but under their own section instead - // so that free-floating textures can also be animated + /* owner_id as id instead of texture, + * since it'll otherwise be impossible to track the depth. */ + // FIXME: perhaps as a result, textures should NOT be included under materials, + // but under their own section instead so that free-floating textures can also be animated. tmp_items += animdata_filter_ds_nodetree( ac, &tmp_data, ads, (ID *)tex, tex->nodetree, filter_mode); } @@ -2149,8 +2209,9 @@ static size_t animdata_filter_ds_textures( int a = 0; /* get datatype specific data first */ - if (owner_id == NULL) + if (owner_id == NULL) { return 0; + } switch (GS(owner_id->name)) { case ID_PA: { @@ -2160,20 +2221,23 @@ static size_t animdata_filter_ds_textures( } default: { /* invalid/unsupported option */ - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("ERROR: Unsupported owner_id (i.e. texture stack) for filter textures - %s\n", owner_id->name); + } return 0; } } - /* firstly check that we actuallly have some textures, by gathering all textures in a temp list */ + /* Firstly check that we actuallly have some textures, + * by gathering all textures in a temp list. */ for (a = 0; a < MAX_MTEX; a++) { Tex *tex = (mtex[a]) ? mtex[a]->tex : NULL; /* for now, if no texture returned, skip (this shouldn't confuse the user I hope) */ - if (tex == NULL) + if (tex == NULL) { continue; + } /* add texture's anim channels */ items += animdata_filter_ds_texture(ac, anim_data, ads, tex, owner_id, filter_mode); @@ -2191,15 +2255,15 @@ static size_t animdata_filter_ds_material( size_t items = 0; /* add material's animation data to temp collection */ - BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_MAT_OBJD(ma)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_MAT_OBJD(ma)) { /* material's animation data */ tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ma, filter_mode); /* nodes */ - if ((ma->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) + if ((ma->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) { tmp_items += animdata_filter_ds_nodetree( ac, &tmp_data, ads, (ID *)ma, ma->nodetree, filter_mode); + } } END_ANIMFILTER_SUBCHANNELS; @@ -2229,7 +2293,7 @@ static size_t animdata_filter_ds_materials( size_t items = 0; int a = 0; - /* first pass: take the materials referenced via the Material slots of the object */ + /* First pass: take the materials referenced via the Material slots of the object. */ for (a = 1; a <= ob->totcol; a++) { Material *ma = give_current_material(ob, a); @@ -2245,10 +2309,12 @@ static size_t animdata_filter_ds_materials( } } - /* second pass: go through a second time looking for "nested" materials (material.material references) + /* Second pass: go through a second time looking for "nested" materials + * (material.material references). * - * NOTE: here we ignore the expanded status of the parent, as it could be too confusing as to why these are - * disappearing/not available, since the relationships between these is not that clear + * NOTE: here we ignore the expanded status of the parent, as it could be too confusing as to + * why these are disappearing/not available, + * since the relationships between these is not that clear. */ if (has_nested) { for (a = 1; a <= ob->totcol; a++) { @@ -2296,8 +2362,9 @@ static void animfilter_modifier_idpoin_cb(void *afm_ptr, /* NOTE: the walker only guarantees to give us all the ID-ptr *slots*, * not just the ones which are actually used, so be careful! */ - if (id == NULL) + if (id == NULL) { return; + } /* check if this is something we're interested in... */ switch (GS(id->name)) { @@ -2333,7 +2400,8 @@ static size_t animdata_filter_ds_modifiers( /* 1) create a temporary "context" containing all the info we have here to pass to the callback * use to walk through the dependencies of the modifiers * - * ! Assumes that all other unspecified values (i.e. accumulation buffers) are zero'd out properly + * Assumes that all other unspecified values (i.e. accumulation buffers) + * are zero'd out properly! */ afm.ac = ac; afm.ads = ads; @@ -2366,19 +2434,20 @@ static size_t animdata_filter_ds_particles( size_t tmp_items = 0; /* if no material returned, skip - so that we don't get weird blank entries... */ - if (ELEM(NULL, psys->part, psys->part->adt)) + if (ELEM(NULL, psys->part, psys->part->adt)) { continue; + } /* add particle-system's animation data to temp collection */ - BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_PART_OBJD(psys->part)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_PART_OBJD(psys->part)) { /* particle system's animation data */ tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)psys->part, filter_mode); /* textures */ - if (!(ads->filterflag & ADS_FILTER_NOTEX)) + if (!(ads->filterflag & ADS_FILTER_NOTEX)) { tmp_items += animdata_filter_ds_textures( ac, &tmp_data, ads, (ID *)psys->part, filter_mode); + } } END_ANIMFILTER_SUBCHANNELS; @@ -2419,8 +2488,9 @@ static size_t animdata_filter_ds_obdata( { Camera *ca = (Camera *)ob->data; - if (ads->filterflag & ADS_FILTER_NOCAM) + if (ads->filterflag & ADS_FILTER_NOCAM) { return 0; + } type = ANIMTYPE_DSCAM; expanded = FILTER_CAM_OBJD(ca); @@ -2430,8 +2500,9 @@ static size_t animdata_filter_ds_obdata( { Light *la = (Light *)ob->data; - if (ads->filterflag & ADS_FILTER_NOLAM) + if (ads->filterflag & ADS_FILTER_NOLAM) { return 0; + } type = ANIMTYPE_DSLAM; expanded = FILTER_LAM_OBJD(la); @@ -2443,8 +2514,9 @@ static size_t animdata_filter_ds_obdata( { Curve *cu = (Curve *)ob->data; - if (ads->filterflag & ADS_FILTER_NOCUR) + if (ads->filterflag & ADS_FILTER_NOCUR) { return 0; + } type = ANIMTYPE_DSCUR; expanded = FILTER_CUR_OBJD(cu); @@ -2454,8 +2526,9 @@ static size_t animdata_filter_ds_obdata( { MetaBall *mb = (MetaBall *)ob->data; - if (ads->filterflag & ADS_FILTER_NOMBA) + if (ads->filterflag & ADS_FILTER_NOMBA) { return 0; + } type = ANIMTYPE_DSMBALL; expanded = FILTER_MBALL_OBJD(mb); @@ -2465,8 +2538,9 @@ static size_t animdata_filter_ds_obdata( { bArmature *arm = (bArmature *)ob->data; - if (ads->filterflag & ADS_FILTER_NOARM) + if (ads->filterflag & ADS_FILTER_NOARM) { return 0; + } type = ANIMTYPE_DSARM; expanded = FILTER_ARM_OBJD(arm); @@ -2476,8 +2550,9 @@ static size_t animdata_filter_ds_obdata( { Mesh *me = (Mesh *)ob->data; - if (ads->filterflag & ADS_FILTER_NOMESH) + if (ads->filterflag & ADS_FILTER_NOMESH) { return 0; + } type = ANIMTYPE_DSMESH; expanded = FILTER_MESH_OBJD(me); @@ -2487,8 +2562,9 @@ static size_t animdata_filter_ds_obdata( { Lattice *lt = (Lattice *)ob->data; - if (ads->filterflag & ADS_FILTER_NOLAT) + if (ads->filterflag & ADS_FILTER_NOLAT) { return 0; + } type = ANIMTYPE_DSLAT; expanded = FILTER_LATTICE_OBJD(lt); @@ -2505,8 +2581,7 @@ static size_t animdata_filter_ds_obdata( } /* add object data animation channels */ - BEGIN_ANIMFILTER_SUBCHANNELS(expanded) - { + BEGIN_ANIMFILTER_SUBCHANNELS (expanded) { /* animation data filtering */ tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)iat, filter_mode); @@ -2518,9 +2593,10 @@ static size_t animdata_filter_ds_obdata( bNodeTree *ntree = la->nodetree; /* nodetree */ - if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE)) + if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE)) { tmp_items += animdata_filter_ds_nodetree( ac, &tmp_data, ads, &la->id, ntree, filter_mode); + } break; } } @@ -2556,8 +2632,7 @@ static size_t animdata_filter_ds_keyanim( size_t items = 0; /* add shapekey-level animation channels */ - BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_SKE_OBJD(key)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_SKE_OBJD(key)) { /* animation data filtering */ tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)key, filter_mode); } @@ -2597,7 +2672,7 @@ static size_t animdata_filter_ds_obanim( /* determine the type of expander channels to use */ /* this is the best way to do this for now... */ ANIMDATA_FILTER_CASES( - ob, + ob, /* Some useless long comment to prevent wrapping by old clang-format versions... */ {/* AnimData - no channel, but consider data */}, {/* NLA - no channel, but consider data */}, { /* Drivers */ @@ -2613,8 +2688,7 @@ static size_t animdata_filter_ds_obanim( }); /* add object-level animation channels */ - BEGIN_ANIMFILTER_SUBCHANNELS(expanded) - { + BEGIN_ANIMFILTER_SUBCHANNELS (expanded) { /* animation data filtering */ tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ob, filter_mode); } @@ -2650,8 +2724,7 @@ static size_t animdata_filter_dopesheet_ob( size_t items = 0; /* filter data contained under object first */ - BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_OBJC(ob)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_OBJC(ob)) { Key *key = BKE_key_from_object(ob); /* object-level animation */ @@ -2696,7 +2769,8 @@ static size_t animdata_filter_dopesheet_ob( /* firstly add object expander if required */ if (filter_mode & ANIMFILTER_LIST_CHANNELS) { /* check if filtering by selection */ - // XXX: double-check on this - most of the time, a lot of tools need to filter out these channels! + /* XXX: double-check on this - + * most of the time, a lot of tools need to filter out these channels! */ if (ANIMCHANNEL_SELOK((base->flag & BASE_SELECTED))) { /* check if filtering by active status */ if (ANIMCHANNEL_ACTIVEOK(ob)) { @@ -2723,15 +2797,15 @@ static size_t animdata_filter_ds_world( size_t items = 0; /* add world animation channels */ - BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_WOR_SCED(wo)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_WOR_SCED(wo)) { /* animation data filtering */ tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)wo, filter_mode); /* nodes */ - if ((wo->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) + if ((wo->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) { tmp_items += animdata_filter_ds_nodetree( ac, &tmp_data, ads, (ID *)wo, wo->nodetree, filter_mode); + } } END_ANIMFILTER_SUBCHANNELS; @@ -2769,7 +2843,7 @@ static size_t animdata_filter_ds_scene( /* determine the type of expander channels to use */ // this is the best way to do this for now... ANIMDATA_FILTER_CASES( - sce, + sce, /* Some useless long comment to prevent wrapping by old clang-format versions... */ {/* AnimData - no channel, but consider data */}, {/* NLA - no channel, but consider data */}, { /* Drivers */ @@ -2785,8 +2859,7 @@ static size_t animdata_filter_ds_scene( }); /* add scene-level animation channels */ - BEGIN_ANIMFILTER_SUBCHANNELS(expanded) - { + BEGIN_ANIMFILTER_SUBCHANNELS (expanded) { /* animation data filtering */ tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)sce, filter_mode); } @@ -2820,8 +2893,7 @@ static size_t animdata_filter_dopesheet_scene( size_t items = 0; /* filter data contained under object first */ - BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_SCEC(sce)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_SCEC(sce)) { bNodeTree *ntree = sce->nodetree; bGPdata *gpd = sce->gpd; World *wo = sce->world; @@ -2851,7 +2923,8 @@ static size_t animdata_filter_dopesheet_scene( tmp_items += animdata_filter_ds_gpencil(ac, &tmp_data, ads, gpd, filter_mode); } - /* TODO: one day, when sequencer becomes its own datatype, perhaps it should be included here */ + /* TODO: one day, when sequencer becomes its own datatype, + * perhaps it should be included here. */ } END_ANIMFILTER_SUBCHANNELS; @@ -2883,8 +2956,7 @@ static size_t animdata_filter_ds_movieclip( size_t tmp_items = 0; size_t items = 0; /* add world animation channels */ - BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_MCLIP(clip)) - { + BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_MCLIP(clip)) { /* animation data filtering */ tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)clip, filter_mode); } @@ -2930,8 +3002,9 @@ static bool animdata_filter_base_is_ok(bDopeSheet *ads, Base *base, int filter_m { Object *ob = base->object; - if (base->object == NULL) + if (base->object == NULL) { return false; + } /* firstly, check if object can be included, by the following factors: * - if only visible, must check for layer and also viewport visibility @@ -2944,20 +3017,23 @@ static bool animdata_filter_base_is_ok(bDopeSheet *ads, Base *base, int filter_m */ if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) { /* layer visibility - we check both object and base, since these may not be in sync yet */ - if ((base->flag & BASE_VISIBLE) == 0) + if ((base->flag & BASE_VISIBLE) == 0) { return false; + } /* outliner restrict-flag */ - if (ob->restrictflag & OB_RESTRICT_VIEW) + if (ob->restrictflag & OB_RESTRICT_VIEW) { return false; + } } /* if only F-Curves with visible flags set can be shown, check that * datablock hasn't been set to invisible */ if (filter_mode & ANIMFILTER_CURVE_VISIBLE) { - if ((ob->adt) && (ob->adt->flag & ADT_CURVES_NOT_VISIBLE)) + if ((ob->adt) && (ob->adt->flag & ADT_CURVES_NOT_VISIBLE)) { return false; + } } /* Pinned curves are visible regardless of selection flags. */ @@ -2990,8 +3066,9 @@ static bool animdata_filter_base_is_ok(bDopeSheet *ads, Base *base, int filter_m * - used to ease the process of doing multiple-character choreographies */ if (ads->filter_grp != NULL) { - if (BKE_collection_has_object_recursive(ads->filter_grp, ob) == 0) + if (BKE_collection_has_object_recursive(ads->filter_grp, ob) == 0) { return false; + } } /* no reason to exclude this object... */ @@ -3032,7 +3109,9 @@ static Base **animdata_filter_ds_sorted_bases(bDopeSheet *ads, return sorted_bases; } -// TODO: implement pinning... (if and when pinning is done, what we need to do is to provide freeing mechanisms - to protect against data that was deleted) +// TODO: implement pinning... +// (if and when pinning is done, what we need to do is to provide freeing mechanisms - +// to protect against data that was deleted). static size_t animdata_filter_dopesheet(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, @@ -3045,10 +3124,11 @@ static size_t animdata_filter_dopesheet(bAnimContext *ac, /* check that we do indeed have a scene */ if ((ads->source == NULL) || (GS(ads->source->name) != ID_SCE)) { printf("Dope Sheet Error: No scene!\n"); - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("\tPointer = %p, Name = '%s'\n", (void *)ads->source, (ads->source) ? ads->source->name : NULL); + } return 0; } @@ -3071,12 +3151,14 @@ static size_t animdata_filter_dopesheet(bAnimContext *ac, /* movie clip's animation */ items += animdata_filter_dopesheet_movieclips(ac, anim_data, ads, filter_mode); - /* scene-linked animation - e.g. world, compositing nodes, scene anim (including sequencer currently) */ + /* Scene-linked animation - e.g. world, compositing nodes, scene anim + * (including sequencer currently). */ items += animdata_filter_dopesheet_scene(ac, anim_data, ads, scene, filter_mode); /* If filtering for channel drawing, we want the objects in alphabetical order, * to make it easier to predict where items are in the hierarchy - * - This order only really matters if we need to show all channels in the list (e.g. for drawing) + * - This order only really matters + * if we need to show all channels in the list (e.g. for drawing). * (XXX: What about lingering "active" flags? The order may now become unpredictable) * - Don't do this if this behavior has been turned off (i.e. due to it being too slow) * - Don't do this if there's just a single object @@ -3152,11 +3234,12 @@ static short animdata_filter_dopesheet_summary(bAnimContext *ac, (*items)++; } - /* if summary is collapsed, don't show other channels beneath this - * - this check is put inside the summary check so that it doesn't interfere with normal operation + /* If summary is collapsed, don't show other channels beneath this - this check is put inside + * the summary check so that it doesn't interfere with normal operation. */ - if (ads->flag & ADS_FLAG_SUMMARY_COLLAPSED) + if (ads->flag & ADS_FLAG_SUMMARY_COLLAPSED) { return 0; + } } /* the other channels beneath this can be shown */ @@ -3218,10 +3301,12 @@ static size_t animdata_filter_remove_invalid(ListBase *anim_data) for (ale = anim_data->first; ale; ale = next) { next = ale->next; - if (ale->type == ANIMTYPE_NONE) + if (ale->type == ANIMTYPE_NONE) { BLI_freelinkN(anim_data, ale); - else + } + else { items++; + } } return items; @@ -3245,7 +3330,8 @@ static size_t animdata_filter_remove_duplis(ListBase *anim_data) /* check if hash has any record of an entry like this * - just use ale->data for now, though it would be nicer to involve - * ale->type in combination too to capture corner cases (where same data performs differently) + * ale->type in combination too to capture corner cases + * (where same data performs differently) */ if (BLI_gset_add(gs, ale->data)) { /* this entry is 'unique' and can be kept */ @@ -3300,9 +3386,11 @@ size_t ANIM_animdata_filter(bAnimContext *ac, } } else { - /* the check for the DopeSheet summary is included here since the summary works here too */ - if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) + /* The check for the DopeSheet summary is included here + * since the summary works here too. */ + if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) { items += animfilter_action(ac, anim_data, ads, data, filter_mode, (ID *)obact); + } } break; @@ -3319,9 +3407,11 @@ size_t ANIM_animdata_filter(bAnimContext *ac, } } else { - /* the check for the DopeSheet summary is included here since the summary works here too */ - if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) + /* The check for the DopeSheet summary is included here + * since the summary works here too. */ + if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) { items = animdata_filter_shapekey(ac, anim_data, key, filter_mode); + } } break; @@ -3329,13 +3419,15 @@ size_t ANIM_animdata_filter(bAnimContext *ac, /* Modes for Specialty Data Types (i.e. not keyframes) */ case ANIMCONT_GPENCIL: { - if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) + if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) { items = animdata_filter_gpencil(ac, anim_data, data, filter_mode); + } break; } case ANIMCONT_MASK: { - if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) + if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) { items = animdata_filter_mask(ac->bmain, anim_data, data, filter_mode); + } break; } @@ -3343,8 +3435,9 @@ size_t ANIM_animdata_filter(bAnimContext *ac, case ANIMCONT_DOPESHEET: /* 'DopeSheet Editor' */ { /* the DopeSheet editor is the primary place where the DopeSheet summaries are useful */ - if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) + if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) { items += animdata_filter_dopesheet(ac, anim_data, data, filter_mode); + } break; } case ANIMCONT_FCURVES: /* Graph Editor -> F-Curves/Animation Editing */ @@ -3357,11 +3450,13 @@ size_t ANIM_animdata_filter(bAnimContext *ac, break; } - /* Timeline Mode - Basically the same as dopesheet, except we only have the summary for now */ + /* Timeline Mode - Basically the same as dopesheet, + * except we only have the summary for now */ case ANIMCONT_TIMELINE: { /* the DopeSheet editor is the primary place where the DopeSheet summaries are useful */ - if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) + if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) { items += animdata_filter_dopesheet(ac, anim_data, data, filter_mode); + } break; } @@ -3386,8 +3481,9 @@ size_t ANIM_animdata_filter(bAnimContext *ac, items = animdata_filter_remove_invalid(anim_data); /* remove duplicates (if required) */ - if (filter_mode & ANIMFILTER_NODUPLIS) + if (filter_mode & ANIMFILTER_NODUPLIS) { items = animdata_filter_remove_duplis(anim_data); + } } /* return the number of items in the list */ diff --git a/source/blender/editors/animation/anim_ipo_utils.c b/source/blender/editors/animation/anim_ipo_utils.c index fd22fa16fe8..19fd521d7d9 100644 --- a/source/blender/editors/animation/anim_ipo_utils.c +++ b/source/blender/editors/animation/anim_ipo_utils.c @@ -43,24 +43,32 @@ /* ----------------------- Getter functions ----------------------- */ -/* Write into "name" buffer, the name of the property (retrieved using RNA from the curve's settings), +/** + * Write into "name" buffer, the name of the property + * (retrieved using RNA from the curve's settings), * and return the icon used for the struct that this property refers to - * WARNING: name buffer we're writing to cannot exceed 256 chars (check anim_channels_defines.c for details) + * + * \warning name buffer we're writing to cannot exceed 256 chars + * (check anim_channels_defines.c for details). */ int getname_anim_fcurve(char *name, ID *id, FCurve *fcu) { int icon = 0; /* sanity checks */ - if (name == NULL) + if (name == NULL) { return icon; + } else if (ELEM(NULL, id, fcu, fcu->rna_path)) { - if (fcu == NULL) + if (fcu == NULL) { strcpy(name, IFACE_("<invalid>")); - else if (fcu->rna_path == NULL) + } + else if (fcu->rna_path == NULL) { strcpy(name, IFACE_("<no path>")); - else /* id == NULL */ + } + else { /* id == NULL */ BLI_snprintf(name, 256, "%s[%d]", fcu->rna_path, fcu->array_index); + } } else { PointerRNA id_ptr, ptr; @@ -83,17 +91,19 @@ int getname_anim_fcurve(char *name, ID *id, FCurve *fcu) * 2) <array-index> <property-name> (<struct name>) * i.e. X Location (Bone1), or X Location (Object) * - * Currently, option 2 is in use, to try and make it easier to quickly identify F-Curves (it does have - * problems with looking rather odd though). Option 1 is better in terms of revealing a consistent sense of - * hierarchy though, which isn't so clear with option 2. + * Currently, option 2 is in use, to try and make it easier to quickly identify F-Curves + * (it does have problems with looking rather odd though). + * Option 1 is better in terms of revealing a consistent sense of hierarchy though, + * which isn't so clear with option 2. */ - /* for structname - * - as base, we use a custom name from the structs if one is available - * - however, if we're showing subdata of bones (probably there will be other exceptions later) - * need to include that info too since it gets confusing otherwise - * - if a pointer just refers to the ID-block, then don't repeat this info - * since this just introduces clutter + /* For structname: + * - As base, we use a custom name from the structs if one is available + * - However, if we're showing subdata of bones + * (probably there will be other exceptions later). + * need to include that info too since it gets confusing otherwise. + * - If a pointer just refers to the ID-block, then don't repeat this info + * since this just introduces clutter. */ if (strstr(fcu->rna_path, "bones") && strstr(fcu->rna_path, "constraints")) { /* perform string 'chopping' to get "Bone Name : Constraint Name" */ @@ -105,10 +115,12 @@ int getname_anim_fcurve(char *name, ID *id, FCurve *fcu) free_structname = 1; /* free the temp names */ - if (pchanName) + if (pchanName) { MEM_freeN(pchanName); - if (constName) + } + if (constName) { MEM_freeN(constName); + } } else if (ptr.data != ptr.id.data) { PropertyRNA *nameprop = RNA_struct_name_property(ptr.type); @@ -117,8 +129,9 @@ int getname_anim_fcurve(char *name, ID *id, FCurve *fcu) structname = RNA_property_string_get_alloc(&ptr, nameprop, NULL, 0, NULL); free_structname = 1; } - else + else { structname = RNA_struct_ui_name(ptr.type); + } } /* Property Name is straightforward */ @@ -129,10 +142,12 @@ int getname_anim_fcurve(char *name, ID *id, FCurve *fcu) char c = RNA_property_array_item_char(prop, fcu->array_index); /* we need to write the index to a temp buffer (in py syntax) */ - if (c) + if (c) { BLI_snprintf(arrayindbuf, sizeof(arrayindbuf), "%c ", c); - else + } + else { BLI_snprintf(arrayindbuf, sizeof(arrayindbuf), "[%d]", fcu->array_index); + } arrayname = &arrayindbuf[0]; } @@ -144,14 +159,17 @@ int getname_anim_fcurve(char *name, ID *id, FCurve *fcu) /* putting this all together into the buffer */ /* XXX we need to check for invalid names... * XXX the name length limit needs to be passed in or as some define */ - if (structname) + if (structname) { BLI_snprintf(name, 256, "%s%s (%s)", arrayname, propname, structname); - else + } + else { BLI_snprintf(name, 256, "%s%s", arrayname, propname); + } /* free temp name if nameprop is set */ - if (free_structname) + if (free_structname) { MEM_freeN((void *)structname); + } /* Icon for this property's owner: * use the struct's icon if it is set @@ -210,8 +228,9 @@ void getcolor_fcurve_rainbow(int cur, int tot, float out[3]) /* the base color can get offset a bit so that the colors aren't so identical */ hsv[0] += fac * HSV_BANDWIDTH; - if (hsv[0] > 1.0f) + if (hsv[0] > 1.0f) { hsv[0] = fmod(hsv[0], 1.0f); + } /* saturation adjustments for more visible range */ hsv[1] = ((hsv[0] > 0.5f) && (hsv[0] < 0.8f)) ? 0.5f : 0.6f; diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index beffa47b2c5..66cdae07a36 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -107,10 +107,12 @@ ListBase *ED_context_get_markers(const bContext *C) /* public API for getting markers from "animation" context */ ListBase *ED_animcontext_get_markers(const bAnimContext *ac) { - if (ac) + if (ac) { return context_get_markers(ac->scene, ac->sa); - else + } + else { return NULL; + } } /* --------------------------------- */ @@ -118,7 +120,8 @@ ListBase *ED_animcontext_get_markers(const bAnimContext *ac) /** * Apply some transformation to markers after the fact * - * \param markers: List of markers to affect - this may or may not be the scene markers list, so don't assume anything + * \param markers: List of markers to affect - this may or may not be the scene markers list, + * so don't assume anything. * \param scene: Current scene (for getting current frame) * \param mode: (TfmMode) transform mode that this transform is for * \param value: From the transform code, this is ``t->vec[0]`` @@ -200,7 +203,7 @@ void ED_markers_get_minmax(ListBase *markers, short sel, float *first, float *la float min, max; /* sanity check */ - //printf("markers = %p - %p, %p\n", markers, markers->first, markers->last); + // printf("markers = %p - %p, %p\n", markers, markers->first, markers->last); if (ELEM(NULL, markers, markers->first, markers->last)) { *first = 0.0f; *last = 0.0f; @@ -211,10 +214,12 @@ void ED_markers_get_minmax(ListBase *markers, short sel, float *first, float *la max = -FLT_MAX; for (marker = markers->first; marker; marker = marker->next) { if (!sel || (marker->flag & SELECT)) { - if (marker->frame < min) + if (marker->frame < min) { min = (float)marker->frame; - if (marker->frame > max) + } + if (marker->frame > max) { max = (float)marker->frame; + } } } @@ -231,15 +236,17 @@ static void add_marker_to_cfra_elem(ListBase *lb, TimeMarker *marker, short only CfraElem *ce, *cen; /* should this one only be considered if it is selected? */ - if ((only_sel) && ((marker->flag & SELECT) == 0)) + if ((only_sel) && ((marker->flag & SELECT) == 0)) { return; + } /* insertion sort - try to find a previous cfra elem */ for (ce = lb->first; ce; ce = ce->next) { if (ce->cfra == marker->frame) { /* do because of double keys */ - if (marker->flag & SELECT) + if (marker->flag & SELECT) { ce->sel = marker->flag; + } return; } else if (ce->cfra > marker->frame) { @@ -248,10 +255,12 @@ static void add_marker_to_cfra_elem(ListBase *lb, TimeMarker *marker, short only } cen = MEM_callocN(sizeof(CfraElem), "add_to_cfra_elem"); - if (ce) + if (ce) { BLI_insertlinkbefore(lb, ce, cen); - else + } + else { BLI_addtail(lb, cen); + } cen->cfra = marker->frame; cen->sel = marker->flag; @@ -280,8 +289,9 @@ void ED_markers_make_cfra_list(ListBase *markers, ListBase *lb, short only_sel) return; } - for (marker = markers->first; marker; marker = marker->next) + for (marker = markers->first; marker; marker = marker->next) { add_marker_to_cfra_elem(lb, marker, only_sel); + } } void ED_markers_deselect_all(ListBase *markers, int action) @@ -315,8 +325,9 @@ TimeMarker *ED_markers_get_first_selected(ListBase *markers) if (markers) { for (marker = markers->first; marker; marker = marker->next) { - if (marker->flag & SELECT) + if (marker->flag & SELECT) { return marker; + } } } @@ -326,7 +337,8 @@ TimeMarker *ED_markers_get_first_selected(ListBase *markers) /* --------------------------------- */ /* Print debugging prints of list of markers - * BSI's: do NOT make static or put in if-defs as "unused code". That's too much trouble when we need to use for quick debugging! + * BSI's: do NOT make static or put in if-defs as "unused code". + * That's too much trouble when we need to use for quick debugging! */ void debug_markers_print_list(ListBase *markers) { @@ -349,45 +361,38 @@ void debug_markers_print_list(ListBase *markers) /* ************* Marker Drawing ************ */ -static void draw_marker_name(const uiFontStyle *fstyle, - TimeMarker *marker, - const char *name, - int cfra, - const float xpos, - const float ypixels) +static void marker_color_get(TimeMarker *marker, unsigned char *color) { - unsigned char text_col[4]; - float x, y; - - /* minimal y coordinate which wouldn't be occluded by scroll */ - int min_y = 17.0f * UI_DPI_FAC; - if (marker->flag & SELECT) { - UI_GetThemeColor4ubv(TH_TEXT_HI, text_col); - x = xpos + 4.0f * UI_DPI_FAC; - y = (ypixels <= 39.0f * UI_DPI_FAC) ? (ypixels - 10.0f * UI_DPI_FAC) : 29.0f * UI_DPI_FAC; - y = max_ii(y, min_y); + UI_GetThemeColor4ubv(TH_TEXT_HI, color); } else { - UI_GetThemeColor4ubv(TH_TEXT, text_col); - if ((marker->frame <= cfra) && (marker->frame + 5 > cfra)) { - x = xpos + 8.0f * UI_DPI_FAC; - y = (ypixels <= 39.0f * UI_DPI_FAC) ? (ypixels - 10.0f * UI_DPI_FAC) : 29.0f * UI_DPI_FAC; - y = max_ii(y, min_y); - } - else { - x = xpos + 8.0f * UI_DPI_FAC; - y = 17.0f * UI_DPI_FAC; - } + UI_GetThemeColor4ubv(TH_TEXT, color); } +} + +static void draw_marker_name(const uiFontStyle *fstyle, + TimeMarker *marker, + float marker_x, + float text_y) +{ + unsigned char text_color[4]; + marker_color_get(marker, text_color); + + const char *name = marker->name; #ifdef DURIAN_CAMERA_SWITCH - if (marker->camera && (marker->camera->restrictflag & OB_RESTRICT_RENDER)) { - text_col[3] = 100; + if (marker->camera) { + Object *camera = marker->camera; + name = camera->id.name + 2; + if (camera->restrictflag & OB_RESTRICT_RENDER) { + text_color[3] = 100; + } } #endif - UI_fontstyle_draw_simple(fstyle, x, y, name, text_col); + int name_x = marker_x + UI_DPI_ICON_SIZE * 0.6; + UI_fontstyle_draw_simple(fstyle, name_x, text_y, name, text_color); } static void draw_marker_line(const float color[4], float x, float ymin, float ymax) @@ -414,29 +419,24 @@ static void draw_marker_line(const float color[4], float x, float ymin, float ym immUnbindProgram(); } -/* function to draw markers */ -static void draw_marker(const uiFontStyle *fstyle, - TimeMarker *marker, - int cfra, - int flag, - /* avoid re-calculating each time */ - const float ypixels, - const float xscale, - int height) +static int marker_get_icon_id(TimeMarker *marker, int flag) { - const float xpos = marker->frame * xscale; + if (flag & DRAW_MARKERS_LOCAL) { + return (marker->flag & ACTIVE) ? ICON_PMARKER_ACT : + (marker->flag & SELECT) ? ICON_PMARKER_SEL : ICON_PMARKER; + } #ifdef DURIAN_CAMERA_SWITCH - const float yoffs = (marker->camera) ? 0.2f * UI_DPI_ICON_SIZE : 0.0f; -#else - const float yoffs = 0.0f; + else if (marker->camera) { + return (marker->flag & SELECT) ? ICON_OUTLINER_OB_CAMERA : ICON_CAMERA_DATA; + } #endif - int icon_id; - - GPU_blend(true); - GPU_blend_set_func_separate( - GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); + else { + return (marker->flag & SELECT) ? ICON_MARKER_HLT : ICON_MARKER; + } +} - /* vertical line - dotted */ +static void draw_marker_line_if_necessary(TimeMarker *marker, int flag, int xpos, int height) +{ #ifdef DURIAN_CAMERA_SWITCH if ((marker->camera) || (flag & DRAW_MARKERS_LINES)) #else @@ -451,103 +451,114 @@ static void draw_marker(const uiFontStyle *fstyle, copy_v4_fl4(color, 0.0f, 0.0f, 0.0f, 0.38f); } - draw_marker_line(color, xpos, yoffs + 1.5f * UI_DPI_ICON_SIZE, height); + draw_marker_line(color, xpos, UI_DPI_FAC * 20, height); } +} - /* 5 px to offset icon to align properly, space / pixels corrects for zoom */ - if (flag & DRAW_MARKERS_LOCAL) { - icon_id = (marker->flag & ACTIVE) ? ICON_PMARKER_ACT : - (marker->flag & SELECT) ? ICON_PMARKER_SEL : ICON_PMARKER; - } -#ifdef DURIAN_CAMERA_SWITCH - else if (marker->camera) { - icon_id = (marker->flag & SELECT) ? ICON_OUTLINER_OB_CAMERA : ICON_CAMERA_DATA; - } -#endif - else { - icon_id = (marker->flag & SELECT) ? ICON_MARKER_HLT : ICON_MARKER; - } +static void draw_marker( + const uiFontStyle *fstyle, TimeMarker *marker, int xpos, int flag, int region_height) +{ + GPU_blend(true); + GPU_blend_set_func_separate( + GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); + + draw_marker_line_if_necessary(marker, flag, xpos, region_height); - UI_icon_draw(xpos - 0.55f * UI_DPI_ICON_SIZE, yoffs + UI_DPI_ICON_SIZE, icon_id); + int icon_id = marker_get_icon_id(marker, flag); + UI_icon_draw(xpos - 0.55f * UI_DPI_ICON_SIZE, UI_DPI_FAC * 18, icon_id); GPU_blend(false); - /* and the marker name too, shifted slightly to the top-right */ -#ifdef DURIAN_CAMERA_SWITCH - if (marker->camera) { - draw_marker_name(fstyle, marker, marker->camera->id.name + 2, cfra, xpos, ypixels); + float name_y = UI_DPI_FAC * 18; + if (marker->flag & SELECT) { + name_y += UI_DPI_FAC * 10; } - else if (marker->name[0]) { - draw_marker_name(fstyle, marker, marker->name, cfra, xpos, ypixels); + draw_marker_name(fstyle, marker, xpos, name_y); +} + +static void draw_markers_background(rctf *rect) +{ + uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + const unsigned char shade[4] = {0, 0, 0, 16}; + immUniformColor4ubv(shade); + + GPU_blend(true); + GPU_blend_set_func_separate( + GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); + + immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax); + + GPU_blend(false); + + immUnbindProgram(); +} + +static bool marker_is_in_frame_range(TimeMarker *marker, int frame_range[2]) +{ + if (marker->frame < frame_range[0]) { + return false; } -#else - if (marker->name[0]) { - draw_marker_name(fstyle, marker, marker->name, cfra, xpos, ypixels); + if (marker->frame > frame_range[1]) { + return false; } -#endif + return true; +} + +static void get_marker_region_rect(View2D *v2d, rctf *rect) +{ + rect->xmin = v2d->cur.xmin; + rect->xmax = v2d->cur.xmax; + rect->ymin = 0; + rect->ymax = UI_MARKER_MARGIN_Y; +} + +static void get_marker_clip_frame_range(View2D *v2d, float xscale, int r_range[2]) +{ + float font_width_max = (10 * UI_DPI_FAC) / xscale; + r_range[0] = v2d->cur.xmin - sizeof(((TimeMarker *)NULL)->name) * font_width_max; + r_range[1] = v2d->cur.xmax + font_width_max; } /* Draw Scene-Markers in time window */ void ED_markers_draw(const bContext *C, int flag) { - const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; ListBase *markers = ED_context_get_markers(C); - View2D *v2d; - TimeMarker *marker; - Scene *scene; - int select_pass; - int v2d_clip_range_x[2]; - float font_width_max; - - /* cache values */ - float ypixels, xscale, yscale; - if (markers == NULL || BLI_listbase_is_empty(markers)) { return; } - scene = CTX_data_scene(C); - v2d = UI_view2d_fromcontext(C); - int height = v2d->mask.ymax - v2d->mask.ymin; - - if (flag & DRAW_MARKERS_MARGIN) { - uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - - const unsigned char shade[4] = {0, 0, 0, 16}; - immUniformColor4ubv(shade); - - GPU_blend(true); - GPU_blend_set_func_separate( - GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); - - immRectf(pos, v2d->cur.xmin, 0, v2d->cur.xmax, UI_MARKER_MARGIN_Y); + ARegion *ar = CTX_wm_region(C); + View2D *v2d = UI_view2d_fromcontext(C); - GPU_blend(false); + rctf markers_region_rect; + get_marker_region_rect(v2d, &markers_region_rect); - immUnbindProgram(); - } + draw_markers_background(&markers_region_rect); /* no time correction for framelen! space is drawn with old values */ - ypixels = BLI_rcti_size_y(&v2d->mask); - UI_view2d_scale_get(v2d, &xscale, &yscale); + float xscale, dummy; + UI_view2d_scale_get(v2d, &xscale, &dummy); GPU_matrix_push(); GPU_matrix_scale_2f(1.0f / xscale, 1.0f); - /* x-bounds with offset for text (adjust for long string, avoid checking string width) */ - font_width_max = (10 * UI_DPI_FAC) / xscale; - v2d_clip_range_x[0] = v2d->cur.xmin - (sizeof(marker->name) * font_width_max); - v2d_clip_range_x[1] = v2d->cur.xmax + font_width_max; + int clip_frame_range[2]; + get_marker_clip_frame_range(v2d, xscale, clip_frame_range); - /* loop [unselected, selected] */ - for (select_pass = 0; select_pass <= SELECT; select_pass += SELECT) { - /* unselected markers are drawn at the first time */ - for (marker = markers->first; marker; marker = marker->next) { - if ((marker->flag & SELECT) == select_pass) { - /* bounds check */ - if ((marker->frame >= v2d_clip_range_x[0]) && (marker->frame <= v2d_clip_range_x[1])) { - draw_marker(fstyle, marker, scene->r.cfra, flag, ypixels, xscale, height); - } + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; + + for (TimeMarker *marker = markers->first; marker; marker = marker->next) { + if ((marker->flag & SELECT) == 0) { + if (marker_is_in_frame_range(marker, clip_frame_range)) { + draw_marker(fstyle, marker, marker->frame * xscale, flag, ar->winy); + } + } + } + for (TimeMarker *marker = markers->first; marker; marker = marker->next) { + if (marker->flag & SELECT) { + if (marker_is_in_frame_range(marker, clip_frame_range)) { + draw_marker(fstyle, marker, marker->frame * xscale, flag, ar->winy); } } } @@ -569,8 +580,9 @@ static bool ed_markers_poll_selected_markers(bContext *C) ListBase *markers = ED_context_get_markers(C); /* first things first: markers can only exist in timeline views */ - if (ED_operator_animview_active(C) == 0) + if (ED_operator_animview_active(C) == 0) { return 0; + } /* check if some marker is selected */ return ED_markers_get_first_selected(markers) != NULL; @@ -581,12 +593,14 @@ static bool ed_markers_poll_selected_no_locked_markers(bContext *C) ListBase *markers = ED_context_get_markers(C); ToolSettings *ts = CTX_data_tool_settings(C); - if (ts->lock_markers) + if (ts->lock_markers) { return 0; + } /* first things first: markers can only exist in timeline views */ - if (ED_operator_animview_active(C) == 0) + if (ED_operator_animview_active(C) == 0) { return 0; + } /* check if some marker is selected */ return ED_markers_get_first_selected(markers) != NULL; @@ -598,12 +612,14 @@ static bool ed_markers_poll_markers_exist(bContext *C) ListBase *markers = ED_context_get_markers(C); ToolSettings *ts = CTX_data_tool_settings(C); - if (ts->lock_markers) + if (ts->lock_markers) { return 0; + } /* first things first: markers can only exist in timeline views */ - if (ED_operator_animview_active(C) == 0) + if (ED_operator_animview_active(C) == 0) { return 0; + } /* list of markers must exist, as well as some markers in it! */ return (markers && markers->first); @@ -632,14 +648,17 @@ static int ed_markers_opwrap_invoke_custom(bContext *C, /* removed check for Y coord of event, keymap has bounbox now */ /* allow operator to run now */ - if (invoke_func) + if (invoke_func) { retval = invoke_func(C, op, event); - else if (op->type->exec) + } + else if (op->type->exec) { retval = op->type->exec(C, op); - else + } + else { BKE_report(op->reports, RPT_ERROR, "Programming error: operator does not actually have code to do anything!"); + } /* unless successful, must add "pass-through" * to let normal operator's have a chance at tackling this event */ @@ -669,19 +688,22 @@ static int ed_marker_add_exec(bContext *C, wmOperator *UNUSED(op)) TimeMarker *marker; int frame = CTX_data_scene(C)->r.cfra; - if (markers == NULL) + if (markers == NULL) { return OPERATOR_CANCELLED; + } /* prefer not having 2 markers at the same place, * though the user can move them to overlap once added */ for (marker = markers->first; marker; marker = marker->next) { - if (marker->frame == frame) + if (marker->frame == frame) { return OPERATOR_CANCELLED; + } } /* deselect all */ - for (marker = markers->first; marker; marker = marker->next) + for (marker = markers->first; marker; marker = marker->next) { marker->flag &= ~SELECT; + } marker = MEM_callocN(sizeof(TimeMarker), "TimeMarker"); marker->flag = SELECT; @@ -1079,8 +1101,9 @@ static void ed_marker_duplicate_apply(bContext *C) ListBase *markers = ED_context_get_markers(C); TimeMarker *marker, *newmarker; - if (markers == NULL) + if (markers == NULL) { return; + } /* go through the list of markers, duplicate selected markers and add duplicated copies * to the beginning of the list (unselect original markers) @@ -1189,8 +1212,9 @@ static int ed_marker_select(bContext *C, const wmEvent *event, bool extend, bool float viewx; int x, cfra; - if (markers == NULL) + if (markers == NULL) { return OPERATOR_PASS_THROUGH; + } x = event->x - ar->winrct.xmin; @@ -1209,8 +1233,9 @@ static int ed_marker_select(bContext *C, const wmEvent *event, bool extend, bool TimeMarker *marker; int sel = 0; - if (!extend) + if (!extend) { BKE_view_layer_base_deselect_all(view_layer); + } for (marker = markers->first; marker; marker = marker->next) { if (marker->frame == cfra) { @@ -1225,8 +1250,9 @@ static int ed_marker_select(bContext *C, const wmEvent *event, bool extend, bool base = BKE_view_layer_base_find(view_layer, marker->camera); if (base) { ED_object_base_select(base, sel); - if (sel) + if (sel) { ED_object_base_activate(C, base); + } } } } @@ -1315,8 +1341,9 @@ static int ed_marker_box_select_exec(bContext *C, wmOperator *op) WM_operator_properties_border_to_rctf(op, &rect); UI_view2d_region_to_view_rctf(v2d, &rect, &rect); - if (markers == NULL) + if (markers == NULL) { return 0; + } const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); const bool select = (sel_op != SEL_OP_SUB); @@ -1410,8 +1437,9 @@ static int ed_marker_delete_exec(bContext *C, wmOperator *UNUSED(op)) TimeMarker *marker, *nmarker; bool changed = false; - if (markers == NULL) + if (markers == NULL) { return OPERATOR_CANCELLED; + } for (marker = markers->first; marker; marker = nmarker) { nmarker = marker->next; @@ -1475,8 +1503,9 @@ static int ed_marker_rename_invoke_wrapper(bContext *C, wmOperator *op, const wm { /* must initialize the marker name first if there is a marker selected */ TimeMarker *marker = ED_markers_get_first_selected(ED_context_get_markers(C)); - if (marker) + if (marker) { RNA_string_set(op->ptr, "name", marker->name); + } /* now see if the operator is usable */ return ed_markers_opwrap_invoke_custom(C, op, event, WM_operator_props_popup_confirm); @@ -1504,7 +1533,13 @@ static void MARKER_OT_rename(wmOperatorType *ot) sizeof(((TimeMarker *)NULL)->name), "Name", "New name for marker"); - //RNA_def_boolean(ot->srna, "ensure_unique", 0, "Ensure Unique", "Ensure that new name is unique within collection of markers"); +#if 0 + RNA_def_boolean(ot->srna, + "ensure_unique", + 0, + "Ensure Unique", + "Ensure that new name is unique within collection of markers"); +#endif } /* **************** make links to scene ***************** */ @@ -1592,8 +1627,9 @@ static int ed_marker_camera_bind_exec(bContext *C, wmOperator *op) } /* add new marker, unless we already have one on this frame, in which case, replace it */ - if (markers == NULL) + if (markers == NULL) { return OPERATOR_CANCELLED; + } marker = ED_markers_find_nearest_marker(markers, CFRA); if ((marker == NULL) || (marker->frame != CFRA)) { diff --git a/source/blender/editors/animation/anim_motion_paths.c b/source/blender/editors/animation/anim_motion_paths.c index b1183167945..e3c4e2a8cfb 100644 --- a/source/blender/editors/animation/anim_motion_paths.c +++ b/source/blender/editors/animation/anim_motion_paths.c @@ -216,8 +216,9 @@ void animviz_calc_motionpaths(Depsgraph *depsgraph, bool current_frame_only) { /* sanity check */ - if (ELEM(NULL, targets, targets->first)) + if (ELEM(NULL, targets, targets->first)) { return; + } /* Compute frame range to bake within. * TODO: this method could be improved... @@ -249,7 +250,8 @@ void animviz_calc_motionpaths(Depsgraph *depsgraph, /* get copies of objects/bones to get the calculated results from * (for copy-on-write evaluation), so that we actually get some results */ - // TODO: Create a copy of background depsgraph that only contain these entities, and only evaluates them.. + // TODO: Create a copy of background depsgraph that only contain these entities, + // and only evaluates them. for (MPathTarget *mpt = targets->first; mpt; mpt = mpt->next) { mpt->ob_eval = DEG_get_evaluated_object(depsgraph, mpt->ob); @@ -262,10 +264,12 @@ void animviz_calc_motionpaths(Depsgraph *depsgraph, bAnimVizSettings *avs; /* get pointer to animviz settings for each target */ - if (mpt->pchan) + if (mpt->pchan) { avs = &mpt->ob->pose->avs; - else + } + else { avs = &mpt->ob->avs; + } /* it is assumed that keyframes for bones are all grouped in a single group * unless an option is set to always use the whole action @@ -319,10 +323,12 @@ void animviz_calc_motionpaths(Depsgraph *depsgraph, bMotionPath *mpath = mpt->mpath; /* get pointer to animviz settings for each target */ - if (mpt->pchan) + if (mpt->pchan) { avs = &mpt->ob->pose->avs; - else + } + else { avs = &mpt->ob->avs; + } /* clear the flag requesting recalculation of targets */ avs->recalc &= ~ANIMVIZ_RECALC_PATHS; diff --git a/source/blender/editors/animation/anim_ops.c b/source/blender/editors/animation/anim_ops.c index 91cbc2ff3e0..45bb8f3b11e 100644 --- a/source/blender/editors/animation/anim_ops.c +++ b/source/blender/editors/animation/anim_ops.c @@ -62,8 +62,9 @@ static bool change_frame_poll(bContext *C) ScrArea *sa = CTX_wm_area(C); /* XXX temp? prevent changes during render */ - if (G.is_rendering) + if (G.is_rendering) { return false; + } /* although it's only included in keymaps for regions using ED_KEYMAP_ANIMATION, * this shouldn't show up in 3D editor (or others without 2D timeline view) via search @@ -157,8 +158,9 @@ static void change_frame_seq_preview_begin(bContext *C, const wmEvent *event) ED_sequencer_special_preview_set(C, event->mval); } } - if (screen) + if (screen) { screen->scrubbing = true; + } } static void change_frame_seq_preview_end(bContext *C) @@ -225,8 +227,9 @@ static int change_frame_modal(bContext *C, wmOperator *op, const wmEvent *event) case RIGHTMOUSE: case MIDDLEMOUSE: /* We check for either mouse-button to end, to work with all user keymaps. */ - if (event->val == KM_RELEASE) + if (event->val == KM_RELEASE) { ret = OPERATOR_FINISHED; + } break; case LEFTCTRLKEY: @@ -281,8 +284,9 @@ static bool anim_set_end_frames_poll(bContext *C) ScrArea *sa = CTX_wm_area(C); /* XXX temp? prevent changes during render */ - if (G.is_rendering) + if (G.is_rendering) { return false; + } /* although it's only included in keymaps for regions using ED_KEYMAP_ANIMATION, * this shouldn't show up in 3D editor (or others without 2D timeline view) via search @@ -302,22 +306,27 @@ static int anim_set_sfra_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene = CTX_data_scene(C); int frame; - if (scene == NULL) + if (scene == NULL) { return OPERATOR_CANCELLED; + } frame = CFRA; /* if Preview Range is defined, set the 'start' frame for that */ - if (PRVRANGEON) + if (PRVRANGEON) { scene->r.psfra = frame; - else + } + else { scene->r.sfra = frame; + } if (PEFRA < frame) { - if (PRVRANGEON) + if (PRVRANGEON) { scene->r.pefra = frame; - else + } + else { scene->r.efra = frame; + } } WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); @@ -345,22 +354,27 @@ static int anim_set_efra_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene = CTX_data_scene(C); int frame; - if (scene == NULL) + if (scene == NULL) { return OPERATOR_CANCELLED; + } frame = CFRA; /* if Preview Range is defined, set the 'end' frame for that */ - if (PRVRANGEON) + if (PRVRANGEON) { scene->r.pefra = frame; - else + } + else { scene->r.efra = frame; + } if (PSFRA > frame) { - if (PRVRANGEON) + if (PRVRANGEON) { scene->r.psfra = frame; - else + } + else { scene->r.sfra = frame; + } } WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); @@ -405,8 +419,9 @@ static int previewrange_define_exec(bContext *C, wmOperator *op) */ FRAMENUMBER_MIN_CLAMP(sfra); FRAMENUMBER_MIN_CLAMP(efra); - if (efra < sfra) + if (efra < sfra) { efra = sfra; + } scene->r.flag |= SCER_PRV_RANGE; scene->r.psfra = round_fl_to_int(sfra); @@ -452,8 +467,9 @@ static int previewrange_clear_exec(bContext *C, wmOperator *UNUSED(op)) ScrArea *curarea = CTX_wm_area(C); /* sanity checks */ - if (ELEM(NULL, scene, curarea)) + if (ELEM(NULL, scene, curarea)) { return OPERATOR_CANCELLED; + } /* simply clear values */ scene->r.flag &= ~SCER_PRV_RANGE; diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c index d6564be9574..2a8702802aa 100644 --- a/source/blender/editors/animation/drivers.c +++ b/source/blender/editors/animation/drivers.c @@ -73,13 +73,15 @@ FCurve *verify_driver_fcurve(ID *id, const char rna_path[], const int array_inde FCurve *fcu; /* sanity checks */ - if (ELEM(NULL, id, rna_path)) + if (ELEM(NULL, id, rna_path)) { return NULL; + } /* init animdata if none available yet */ adt = BKE_animdata_from_id(id); - if ((adt == NULL) && (add)) + if ((adt == NULL) && (add)) { adt = BKE_animdata_add_id(id); + } if (adt == NULL) { /* if still none (as not allowed to add, or ID doesn't have animdata for some reason) */ return NULL; @@ -102,7 +104,8 @@ FCurve *verify_driver_fcurve(ID *id, const char rna_path[], const int array_inde fcu->rna_path = BLI_strdup(rna_path); fcu->array_index = array_index; - /* if add is negative, don't init this data yet, since it will be filled in by the pasted driver */ + /* If add is negative, don't init this data yet, + * since it will be filled in by the pasted driver. */ if (add > 0) { BezTriple *bezt; size_t i; @@ -232,31 +235,40 @@ static int add_driver_with_target(ReportList *UNUSED(reports), /* Transform channel depends on type */ if (STREQ(prop_name, "location")) { - if (src_index == 2) + if (src_index == 2) { dtar->transChan = DTAR_TRANSCHAN_LOCZ; - else if (src_index == 1) + } + else if (src_index == 1) { dtar->transChan = DTAR_TRANSCHAN_LOCY; - else + } + else { dtar->transChan = DTAR_TRANSCHAN_LOCX; + } } else if (STREQ(prop_name, "scale")) { - if (src_index == 2) + if (src_index == 2) { dtar->transChan = DTAR_TRANSCHAN_SCALEZ; - else if (src_index == 1) + } + else if (src_index == 1) { dtar->transChan = DTAR_TRANSCHAN_SCALEY; - else + } + else { dtar->transChan = DTAR_TRANSCHAN_SCALEX; + } } else { /* XXX: With quaternions and axis-angle, this mapping might not be correct... * But since those have 4 elements instead, there's not much we can do */ - if (src_index == 2) + if (src_index == 2) { dtar->transChan = DTAR_TRANSCHAN_ROTZ; - else if (src_index == 1) + } + else if (src_index == 1) { dtar->transChan = DTAR_TRANSCHAN_ROTY; - else + } + else { dtar->transChan = DTAR_TRANSCHAN_ROTX; + } } } else { @@ -437,12 +449,14 @@ int ANIM_add_driver( array_index_max = RNA_property_array_length(&ptr, prop); array_index = 0; } - else + else { array_index_max = array_index; + } /* maximum index should be greater than the start index */ - if (array_index == array_index_max) + if (array_index == array_index_max) { array_index_max += 1; + } /* will only loop once unless the array index was -1 */ for (; array_index < array_index_max; array_index++) { @@ -476,26 +490,32 @@ int ANIM_add_driver( float fval; if (proptype == PROP_BOOLEAN) { - if (!array) + if (!array) { val = RNA_property_boolean_get(&ptr, prop); - else + } + else { val = RNA_property_boolean_get_index(&ptr, prop, array_index); + } BLI_snprintf(expression, maxlen, "%s%s", dvar_prefix, (val) ? "True" : "False"); } else if (proptype == PROP_INT) { - if (!array) + if (!array) { val = RNA_property_int_get(&ptr, prop); - else + } + else { val = RNA_property_int_get_index(&ptr, prop, array_index); + } BLI_snprintf(expression, maxlen, "%s%d", dvar_prefix, val); } else if (proptype == PROP_FLOAT) { - if (!array) + if (!array) { fval = RNA_property_float_get(&ptr, prop); - else + } + else { fval = RNA_property_float_get_index(&ptr, prop, array_index); + } BLI_snprintf(expression, maxlen, "%s%.3f", dvar_prefix, fval); BLI_str_rstrip_float_zero(expression, '\0'); @@ -586,8 +606,9 @@ static FCurve *channeldriver_copypaste_buf = NULL; void ANIM_drivers_copybuf_free(void) { /* free the buffer F-Curve if it exists, as if it were just another F-Curve */ - if (channeldriver_copypaste_buf) + if (channeldriver_copypaste_buf) { free_fcurve(channeldriver_copypaste_buf); + } channeldriver_copypaste_buf = NULL; } @@ -629,8 +650,9 @@ bool ANIM_copy_driver( /* copy this to the copy/paste buf if it exists */ if (fcu && fcu->driver) { - /* make copies of some info such as the rna_path, then clear this info from the F-Curve temporarily - * so that we don't end up wasting memory storing the path which won't get used ever... + /* Make copies of some info such as the rna_path, then clear this info from the + * F-Curve temporarily so that we don't end up wasting memory storing the path + * which won't get used ever. */ char *tmp_path = fcu->rna_path; fcu->rna_path = NULL; @@ -866,8 +888,9 @@ static const EnumPropertyItem *driver_mapping_type_itemsf(bContext *C, int totitem = 0; - if (!C) /* needed for docs */ + if (!C) { /* needed for docs */ return prop_driver_create_mapping_types; + } UI_context_active_but_prop_get(C, &ptr, &prop, &index); @@ -899,13 +922,25 @@ static bool add_driver_button_poll(bContext *C) PointerRNA ptr = {{NULL}}; PropertyRNA *prop = NULL; int index; + bool driven, special; /* this operator can only run if there's a property button active, and it can be animated */ UI_context_active_but_prop_get(C, &ptr, &prop, &index); - return (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)); + + if (!(ptr.id.data && ptr.data && prop)) { + return false; + } + if (!RNA_property_animateable(&ptr, prop)) { + return false; + } + + /* Don't do anything if there is an fcurve for animation without a driver. */ + FCurve *fcu = rna_get_fcurve_context_ui(C, &ptr, prop, index, NULL, NULL, &driven, &special); + return (fcu == NULL || fcu->driver); } -/* Wrapper for creating a driver without knowing what the targets will be yet (i.e. "manual/add later") */ +/* Wrapper for creating a driver without knowing what the targets will be yet + * (i.e. "manual/add later"). */ static int add_driver_button_none(bContext *C, wmOperator *op, short mapping_type) { PointerRNA ptr = {{NULL}}; @@ -915,8 +950,9 @@ static int add_driver_button_none(bContext *C, wmOperator *op, short mapping_typ UI_context_active_but_prop_get(C, &ptr, &prop, &index); - if (mapping_type == CREATEDRIVER_MAPPING_NONE_ALL) + if (mapping_type == CREATEDRIVER_MAPPING_NONE_ALL) { index = -1; + } if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) { char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL); @@ -952,7 +988,8 @@ static int add_driver_button_menu_exec(bContext *C, wmOperator *op) /* Create Driver using Eyedropper */ wmOperatorType *ot = WM_operatortype_find("UI_OT_eyedropper_driver", true); - /* XXX: We assume that it's fine to use the same set of properties, since they're actually the same... */ + /* XXX: We assume that it's fine to use the same set of properties, + * since they're actually the same. */ WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, op->ptr); return OPERATOR_FINISHED; @@ -1069,8 +1106,9 @@ static int remove_driver_button_exec(bContext *C, wmOperator *op) /* try to find driver using property retrieved from UI */ UI_context_active_but_prop_get(C, &ptr, &prop, &index); - if (all) + if (all) { index = -1; + } if (ptr.id.data && ptr.data && prop) { char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL); @@ -1102,7 +1140,7 @@ void ANIM_OT_driver_button_remove(wmOperatorType *ot) /* callbacks */ ot->exec = remove_driver_button_exec; - //op->poll = ??? // TODO: need to have some driver to be able to do this... + // op->poll = ??? // TODO: need to have some driver to be able to do this... /* flags */ ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL; @@ -1139,7 +1177,7 @@ void ANIM_OT_driver_button_edit(wmOperatorType *ot) /* callbacks */ ot->exec = edit_driver_button_exec; - //op->poll = ??? // TODO: need to have some driver to be able to do this... + // op->poll = ??? // TODO: need to have some driver to be able to do this... /* flags */ ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL; @@ -1183,7 +1221,7 @@ void ANIM_OT_copy_driver_button(wmOperatorType *ot) /* callbacks */ ot->exec = copy_driver_button_exec; - //op->poll = ??? // TODO: need to have some driver to be able to do this... + // op->poll = ??? // TODO: need to have some driver to be able to do this... /* flags */ ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL; @@ -1232,7 +1270,7 @@ void ANIM_OT_paste_driver_button(wmOperatorType *ot) /* callbacks */ ot->exec = paste_driver_button_exec; - //op->poll = ??? // TODO: need to have some driver to be able to do this... + // op->poll = ??? // TODO: need to have some driver to be able to do this... /* flags */ ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL; diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 919090cdee9..f4e1268ab77 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -63,7 +63,8 @@ /* UI STUFF */ // XXX! -------------------------------- -/* temporary definition for limits of float number buttons (FLT_MAX tends to infinity with old system) */ +/* Temporary definition for limits of float number buttons + * (FLT_MAX tends to infinity with old system). */ #define UI_FLT_MAX 10000.0f #define B_REDR 1 @@ -76,8 +77,9 @@ static void validate_fmodifier_cb(bContext *UNUSED(C), void *fcm_v, void *UNUSED const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm); /* call the verify callback on the modifier if applicable */ - if (fmi && fmi->verify_data) + if (fmi && fmi->verify_data) { fmi->verify_data(fcm); + } } /* callback to remove the given modifier */ @@ -97,7 +99,8 @@ static void delete_fmodifier_cb(bContext *C, void *ctx_v, void *fcm_v) ED_undo_push(C, "Delete F-Curve Modifier"); /* send notifiers */ - // XXX for now, this is the only way to get updates in all the right places... but would be nice to have a special one in this case + /* XXX for now, this is the only way to get updates in all the right places... + * but would be nice to have a special one in this case. */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); DEG_id_tag_update(ctx->fcurve_owner_id, ID_RECALC_ANIMATION); } @@ -208,7 +211,7 @@ static void draw_modifier__generator(uiLayout *layout, cp = data->coefficients; for (i = 0; (i < data->arraysize) && (cp); i++, cp++) { /* To align with first line... */ - if (i) + if (i) { uiDefBut(block, UI_BTYPE_LABEL, 1, @@ -223,7 +226,8 @@ static void draw_modifier__generator(uiLayout *layout, 0, 0, ""); - else + } + else { uiDefBut(block, UI_BTYPE_LABEL, 1, @@ -238,6 +242,7 @@ static void draw_modifier__generator(uiLayout *layout, 0, 0, ""); + } /* coefficient */ uiDefButF(block, @@ -256,12 +261,15 @@ static void draw_modifier__generator(uiLayout *layout, TIP_("Coefficient for polynomial")); /* 'x' param (and '+' if necessary) */ - if (i == 0) + if (i == 0) { BLI_strncpy(xval, "", sizeof(xval)); - else if (i == 1) + } + else if (i == 1) { BLI_strncpy(xval, "x", sizeof(xval)); - else + } + else { BLI_snprintf(xval, sizeof(xval), "x^%u", i); + } uiDefBut(block, UI_BTYPE_LABEL, 1, @@ -326,7 +334,7 @@ static void draw_modifier__generator(uiLayout *layout, cp = data->coefficients; for (i = 0; (i < data->poly_order) && (cp); i++, cp += 2) { /* To align with first line */ - if (i) + if (i) { uiDefBut(block, UI_BTYPE_LABEL, 1, @@ -341,7 +349,8 @@ static void draw_modifier__generator(uiLayout *layout, 0, 0, ""); - else + } + else { uiDefBut(block, UI_BTYPE_LABEL, 1, @@ -356,6 +365,7 @@ static void draw_modifier__generator(uiLayout *layout, 0, 0, ""); + } /* opening bracket */ uiDefBut( block, UI_BTYPE_LABEL, 1, "(", 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); @@ -427,7 +437,7 @@ static void draw_modifier__generator(uiLayout *layout, row = uiLayoutRow(layout, true); block = uiLayoutGetBlock(row); } - else + else { uiDefBut(block, UI_BTYPE_LABEL, 1, @@ -442,6 +452,7 @@ static void draw_modifier__generator(uiLayout *layout, 0, 0, ""); + } } break; } @@ -567,15 +578,17 @@ static void fmod_envelope_addpoint_cb(bContext *C, void *fcm_dv, void *UNUSED(ar fedn = MEM_callocN((env->totvert + 1) * sizeof(FCM_EnvelopeData), "FCM_EnvelopeData"); /* add the points that should occur before the point to be pasted */ - if (i > 0) + if (i > 0) { memcpy(fedn, env->data, i * sizeof(FCM_EnvelopeData)); + } /* add point to paste at index i */ *(fedn + i) = fed; /* add the points that occur after the point to be pasted */ - if (i < env->totvert) + if (i < env->totvert) { memcpy(fedn + i + 1, env->data + i, (env->totvert - i) * sizeof(FCM_EnvelopeData)); + } /* replace (+ free) old with new */ MEM_freeN(env->data); @@ -883,10 +896,12 @@ void ANIM_uiTemplate_fmodifier_draw(uiLayout *layout, uiItemR(sub, &ptr, "active", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); /* name */ - if (fmi) + if (fmi) { uiItemL(sub, IFACE_(fmi->name), ICON_NONE); - else + } + else { uiItemL(sub, IFACE_("<Unknown Modifier>"), ICON_NONE); + } /* right-align ------------------------------------------- */ sub = uiLayoutRow(row, true); @@ -1023,8 +1038,9 @@ bool ANIM_fmodifiers_copy_to_buf(ListBase *modifiers, bool active) bool ok = true; /* sanity checks */ - if (ELEM(NULL, modifiers, modifiers->first)) + if (ELEM(NULL, modifiers, modifiers->first)) { return 0; + } /* copy the whole list, or just the active one? */ if (active) { @@ -1034,11 +1050,13 @@ bool ANIM_fmodifiers_copy_to_buf(ListBase *modifiers, bool active) FModifier *fcmN = copy_fmodifier(fcm); BLI_addtail(&fmodifier_copypaste_buf, fcmN); } - else + else { ok = 0; + } } - else + else { copy_fmodifiers(&fmodifier_copypaste_buf, modifiers); + } /* did we succeed? */ return ok; @@ -1053,14 +1071,16 @@ bool ANIM_fmodifiers_paste_from_buf(ListBase *modifiers, bool replace, FCurve *c bool ok = false; /* sanity checks */ - if (modifiers == NULL) + if (modifiers == NULL) { return 0; + } bool was_cyclic = curve && BKE_fcurve_is_cyclic(curve); /* if replacing the list, free the existing modifiers */ - if (replace) + if (replace) { free_fmodifiers(modifiers); + } /* now copy over all the modifiers in the buffer to the end of the list */ for (fcm = fmodifier_copypaste_buf.first; fcm; fcm = fcm->next) { @@ -1078,8 +1098,9 @@ bool ANIM_fmodifiers_paste_from_buf(ListBase *modifiers, bool replace, FCurve *c } /* adding or removing the Cycles modifier requires an update to handles */ - if (curve && BKE_fcurve_is_cyclic(curve) != was_cyclic) + if (curve && BKE_fcurve_is_cyclic(curve) != was_cyclic) { calchandles_fcurve(curve); + } /* did we succeed? */ return ok; diff --git a/source/blender/editors/animation/keyframes_draw.c b/source/blender/editors/animation/keyframes_draw.c index e8c17e10b17..678afef5773 100644 --- a/source/blender/editors/animation/keyframes_draw.c +++ b/source/blender/editors/animation/keyframes_draw.c @@ -77,13 +77,16 @@ short compare_ak_cfraPtr(void *node, void *data) const float *cframe = data; float val = *cframe; - if (is_cfra_eq(val, ak->cfra)) + if (is_cfra_eq(val, ak->cfra)) { return 0; + } - if (val < ak->cfra) + if (val < ak->cfra) { return -1; - else + } + else { return 1; + } } /* --------------- */ @@ -205,15 +208,18 @@ static void nupdate_ak_bezt(void *node, void *data) BezTriple *bezt = chain->cur; /* set selection status and 'touched' status */ - if (BEZT_ISSEL_ANY(bezt)) + if (BEZT_ISSEL_ANY(bezt)) { ak->sel = SELECT; + } /* count keyframes in this column */ ak->totkey++; - /* for keyframe type, 'proper' keyframes have priority over breakdowns (and other types for now) */ - if (BEZKEYTYPE(bezt) == BEZT_KEYTYPE_KEYFRAME) + /* For keyframe type, 'proper' keyframes have priority over breakdowns + * (and other types for now). */ + if (BEZKEYTYPE(bezt) == BEZT_KEYTYPE_KEYFRAME) { ak->key_type = BEZT_KEYTYPE_KEYFRAME; + } /* For interpolation type, select the highest value (enum is sorted). */ ak->handle_type = MAX2(ak->handle_type, bezt_handle_type(bezt)); @@ -267,15 +273,18 @@ static void nupdate_ak_gpframe(void *node, void *data) bGPDframe *gpf = (bGPDframe *)data; /* set selection status and 'touched' status */ - if (gpf->flag & GP_FRAME_SELECT) + if (gpf->flag & GP_FRAME_SELECT) { ak->sel = SELECT; + } /* count keyframes in this column */ ak->totkey++; - /* for keyframe type, 'proper' keyframes have priority over breakdowns (and other types for now) */ - if (gpf->key_type == BEZT_KEYTYPE_KEYFRAME) + /* for keyframe type, 'proper' keyframes have priority over breakdowns + * (and other types for now). */ + if (gpf->key_type == BEZT_KEYTYPE_KEYFRAME) { ak->key_type = BEZT_KEYTYPE_KEYFRAME; + } } /* ......... */ @@ -312,8 +321,9 @@ static void nupdate_ak_masklayshape(void *node, void *data) MaskLayerShape *masklay_shape = (MaskLayerShape *)data; /* set selection status and 'touched' status */ - if (masklay_shape->flag & MASK_SHAPE_SELECT) + if (masklay_shape->flag & MASK_SHAPE_SELECT) { ak->sel = SELECT; + } /* count keyframes in this column */ ak->totkey++; @@ -324,32 +334,38 @@ static void nupdate_ak_masklayshape(void *node, void *data) /* Add the given BezTriple to the given 'list' of Keyframes */ static void add_bezt_to_keycolumns_list(DLRBT_Tree *keys, BezTripleChain *bezt) { - if (ELEM(NULL, keys, bezt)) + if (ELEM(NULL, keys, bezt)) { return; - else + } + else { BLI_dlrbTree_add(keys, compare_ak_bezt, nalloc_ak_bezt, nupdate_ak_bezt, bezt); + } } /* Add the given GPencil Frame to the given 'list' of Keyframes */ static void add_gpframe_to_keycolumns_list(DLRBT_Tree *keys, bGPDframe *gpf) { - if (ELEM(NULL, keys, gpf)) + if (ELEM(NULL, keys, gpf)) { return; - else + } + else { BLI_dlrbTree_add(keys, compare_ak_gpframe, nalloc_ak_gpframe, nupdate_ak_gpframe, gpf); + } } /* Add the given MaskLayerShape Frame to the given 'list' of Keyframes */ static void add_masklay_to_keycolumns_list(DLRBT_Tree *keys, MaskLayerShape *masklay_shape) { - if (ELEM(NULL, keys, masklay_shape)) + if (ELEM(NULL, keys, masklay_shape)) { return; - else + } + else { BLI_dlrbTree_add(keys, compare_ak_masklayshape, nalloc_ak_masklayshape, nupdate_ak_masklayshape, masklay_shape); + } } /* ActKeyBlocks (Long Keyframes) ------------------------------------------ */ @@ -526,8 +542,9 @@ bool actkeyblock_is_valid(ActKeyColumn *ac) int actkeyblock_get_valid_hold(ActKeyColumn *ac) { /* check that block is valid */ - if (!actkeyblock_is_valid(ac)) + if (!actkeyblock_is_valid(ac)) { return 0; + } const int hold_mask = (ACTKEYBLOCK_FLAG_ANY_HOLD | ACTKEYBLOCK_FLAG_STATIC_HOLD | ACTKEYBLOCK_FLAG_ANY_HOLD); @@ -567,8 +584,8 @@ void draw_keyframe_shape(float x, size *= 0.85f; break; - case BEZT_KEYTYPE_MOVEHOLD: /* slightly smaller than normal keyframes - * (but by less than for breakdowns) */ + case BEZT_KEYTYPE_MOVEHOLD: /* Slightly smaller than normal keyframes + * (but by less than for breakdowns). */ size *= 0.925f; break; @@ -698,7 +715,7 @@ static void draw_keylist(View2D *v2d, float sel_mhcol[4], unsel_mhcol[4]; float ipo_color[4], ipo_color_mix[4]; - /* cache colours first */ + /* cache colors first */ UI_GetThemeColor4fv(TH_STRIP_SELECT, sel_color); UI_GetThemeColor4fv(TH_STRIP, unsel_color); UI_GetThemeColor4fv(TH_DOPESHEET_IPOLINE, ipo_color); @@ -777,11 +794,14 @@ static void draw_keylist(View2D *v2d, /* count keys */ uint key_len = 0; for (ActKeyColumn *ak = keys->first; ak; ak = ak->next) { - /* optimization: if keyframe doesn't appear within 5 units (screenspace) in visible area, don't draw - * - this might give some improvements, since we current have to flip between view/region matrices + /* Optimization: if keyframe doesn't appear within 5 units (screenspace) + * in visible area, don't draw. + * This might give some improvements, + * since we current have to flip between view/region matrices. */ - if (IN_RANGE_INCL(ak->cfra, v2d->cur.xmin, v2d->cur.xmax)) + if (IN_RANGE_INCL(ak->cfra, v2d->cur.xmin, v2d->cur.xmax)) { key_len++; + } } if (key_len > 0) { @@ -1042,8 +1062,9 @@ void scene_to_keylist(bDopeSheet *ads, Scene *sce, DLRBT_Tree *keys, int saction bAnimListElem dummychan = {NULL}; - if (sce == NULL) + if (sce == NULL) { return; + } /* create a dummy wrapper data to work with */ dummychan.type = ANIMTYPE_SCENE; @@ -1060,8 +1081,9 @@ void scene_to_keylist(bDopeSheet *ads, Scene *sce, DLRBT_Tree *keys, int saction ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* loop through each F-Curve, grabbing the keyframes */ - for (ale = anim_data.first; ale; ale = ale->next) + for (ale = anim_data.first; ale; ale = ale->next) { fcurve_to_keylist(ale->adt, ale->data, keys, saction_flag); + } ANIM_animdata_freelist(&anim_data); } @@ -1076,8 +1098,9 @@ void ob_to_keylist(bDopeSheet *ads, Object *ob, DLRBT_Tree *keys, int saction_fl bAnimListElem dummychan = {NULL}; Base dummybase = {NULL}; - if (ob == NULL) + if (ob == NULL) { return; + } /* create a dummy wrapper data to work with */ dummybase.object = ob; @@ -1096,8 +1119,9 @@ void ob_to_keylist(bDopeSheet *ads, Object *ob, DLRBT_Tree *keys, int saction_fl ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* loop through each F-Curve, grabbing the keyframes */ - for (ale = anim_data.first; ale; ale = ale->next) + for (ale = anim_data.first; ale; ale = ale->next) { fcurve_to_keylist(ale->adt, ale->data, keys, saction_flag); + } ANIM_animdata_freelist(&anim_data); } @@ -1140,8 +1164,9 @@ void fcurve_to_keylist(AnimData *adt, FCurve *fcu, DLRBT_Tree *keys, int saction { if (fcu && fcu->totvert && fcu->bezt) { /* apply NLA-mapping (if applicable) */ - if (adt) + if (adt) { ANIM_nla_mapping_apply_fcurve(adt, fcu, 0, 0); + } /* Check if the curve is cyclic. */ bool is_cyclic = BKE_fcurve_is_cyclic(fcu) && (fcu->totvert >= 2); @@ -1166,8 +1191,9 @@ void fcurve_to_keylist(AnimData *adt, FCurve *fcu, DLRBT_Tree *keys, int saction update_keyblocks(keys, fcu->bezt, fcu->totvert); /* unapply NLA-mapping if applicable */ - if (adt) + if (adt) { ANIM_nla_mapping_apply_fcurve(adt, fcu, 1, 0); + } } } @@ -1216,9 +1242,11 @@ void gpl_to_keylist(bDopeSheet *UNUSED(ads), bGPDlayer *gpl, DLRBT_Tree *keys) bGPDframe *gpf; if (gpl && keys) { - /* although the frames should already be in an ordered list, they are not suitable for displaying yet */ - for (gpf = gpl->frames.first; gpf; gpf = gpf->next) + /* Although the frames should already be in an ordered list, + * they are not suitable for displaying yet. */ + for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { add_gpframe_to_keycolumns_list(keys, gpf); + } update_keyblocks(keys, NULL, 0); } diff --git a/source/blender/editors/animation/keyframes_edit.c b/source/blender/editors/animation/keyframes_edit.c index bb0ab112af4..884a8c20b19 100644 --- a/source/blender/editors/animation/keyframes_edit.c +++ b/source/blender/editors/animation/keyframes_edit.c @@ -43,7 +43,8 @@ #include "ED_keyframes_edit.h" #include "ED_markers.h" -/* This file defines an API and set of callback-operators for non-destructive editing of keyframe data. +/* This file defines an API and set of callback-operators for + * non-destructive editing of keyframe data. * * Two API functions are defined for actually performing the operations on the data: * ANIM_fcurve_keyframes_loop() @@ -81,8 +82,9 @@ short ANIM_fcurve_keyframes_loop(KeyframeEditData *ked, unsigned int i; /* sanity check */ - if (ELEM(NULL, fcu, fcu->bezt)) + if (ELEM(NULL, fcu, fcu->bezt)) { return 0; + } /* set the F-Curve into the editdata so that it can be accessed */ if (ked) { @@ -106,27 +108,31 @@ short ANIM_fcurve_keyframes_loop(KeyframeEditData *ked, /* Only operate on this BezTriple if it fulfills the criteria of the validation func */ if ((ok = key_ok(ked, bezt))) { - if (ked) + if (ked) { ked->curflags = ok; + } /* Exit with return-code '1' if function returns positive * This is useful if finding if some BezTriple satisfies a condition. */ - if (key_cb(ked, bezt)) + if (key_cb(ked, bezt)) { return 1; + } } } } else { for (bezt = fcu->bezt, i = 0; i < fcu->totvert; bezt++, i++) { - if (ked) + if (ked) { ked->curIndex = i; + } /* Exit with return-code '1' if function returns positive * This is useful if finding if some BezTriple satisfies a condition. */ - if (key_cb(ked, bezt)) + if (key_cb(ked, bezt)) { return 1; + } } } } @@ -139,14 +145,15 @@ short ANIM_fcurve_keyframes_loop(KeyframeEditData *ked, } /* if fcu_cb (F-Curve post-editing callback) has been specified then execute it */ - if (fcu_cb) + if (fcu_cb) { fcu_cb(fcu); + } /* done */ return 0; } -/* -------------------------------- Further Abstracted (Not Exposed Directly) ----------------------------- */ +/* --------------------- Further Abstracted (Not Exposed Directly) ----------------------------- */ /* This function is used to loop over the keyframe data in an Action Group */ static short agrp_keyframes_loop(KeyframeEditData *ked, @@ -158,13 +165,15 @@ static short agrp_keyframes_loop(KeyframeEditData *ked, FCurve *fcu; /* sanity check */ - if (agrp == NULL) + if (agrp == NULL) { return 0; + } /* only iterate over the F-Curves that are in this group */ for (fcu = agrp->channels.first; fcu && fcu->grp == agrp; fcu = fcu->next) { - if (ANIM_fcurve_keyframes_loop(ked, fcu, key_ok, key_cb, fcu_cb)) + if (ANIM_fcurve_keyframes_loop(ked, fcu, key_ok, key_cb, fcu_cb)) { return 1; + } } return 0; @@ -180,13 +189,15 @@ static short act_keyframes_loop(KeyframeEditData *ked, FCurve *fcu; /* sanity check */ - if (act == NULL) + if (act == NULL) { return 0; + } /* just loop through all F-Curves */ for (fcu = act->curves.first; fcu; fcu = fcu->next) { - if (ANIM_fcurve_keyframes_loop(ked, fcu, key_ok, key_cb, fcu_cb)) + if (ANIM_fcurve_keyframes_loop(ked, fcu, key_ok, key_cb, fcu_cb)) { return 1; + } } return 0; @@ -209,8 +220,9 @@ static short ob_keyframes_loop(KeyframeEditData *ked, bAnimListElem dummychan = {NULL}; Base dummybase = {NULL}; - if (ob == NULL) + if (ob == NULL) { return 0; + } /* create a dummy wrapper data to work with */ dummybase.object = ob; @@ -228,7 +240,8 @@ static short ob_keyframes_loop(KeyframeEditData *ked, filter = ANIMFILTER_DATA_VISIBLE; // curves only ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); - /* loop through each F-Curve, applying the operation as required, but stopping on the first one */ + /* Loop through each F-Curve, applying the operation as required, + * but stopping on the first one. */ for (ale = anim_data.first; ale; ale = ale->next) { if (ANIM_fcurve_keyframes_loop(ked, (FCurve *)ale->data, key_ok, key_cb, fcu_cb)) { ret = 1; @@ -258,8 +271,9 @@ static short scene_keyframes_loop(KeyframeEditData *ked, bAnimListElem dummychan = {NULL}; - if (sce == NULL) + if (sce == NULL) { return 0; + } /* create a dummy wrapper data to work with */ dummychan.type = ANIMTYPE_SCENE; @@ -275,7 +289,8 @@ static short scene_keyframes_loop(KeyframeEditData *ked, filter = ANIMFILTER_DATA_VISIBLE; // curves only ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); - /* loop through each F-Curve, applying the operation as required, but stopping on the first one */ + /* Loop through each F-Curve, applying the operation as required, + * but stopping on the first one. */ for (ale = anim_data.first; ale; ale = ale->next) { if (ANIM_fcurve_keyframes_loop(ked, (FCurve *)ale->data, key_ok, key_cb, fcu_cb)) { ret = 1; @@ -301,8 +316,9 @@ static short summary_keyframes_loop(KeyframeEditData *ked, int filter, ret_code = 0; /* sanity check */ - if (ac == NULL) + if (ac == NULL) { return 0; + } /* get F-Curves to take keyframes from */ filter = ANIMFILTER_DATA_VISIBLE; @@ -327,10 +343,12 @@ static short summary_keyframes_loop(KeyframeEditData *ked, if (ked->iterflags & (KED_F1_NLA_UNMAP | KED_F2_NLA_UNMAP)) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); - if (ked->iterflags & KED_F1_NLA_UNMAP) + if (ked->iterflags & KED_F1_NLA_UNMAP) { ked->f1 = BKE_nla_tweakedit_remap(adt, f1, NLATIME_CONVERT_UNMAP); - if (ked->iterflags & KED_F2_NLA_UNMAP) + } + if (ked->iterflags & KED_F2_NLA_UNMAP) { ked->f2 = BKE_nla_tweakedit_remap(adt, f2, NLATIME_CONVERT_UNMAP); + } } /* now operate on the channel as per normal */ @@ -348,8 +366,9 @@ static short summary_keyframes_loop(KeyframeEditData *ked, } } - if (ret_code) + if (ret_code) { break; + } } ANIM_animdata_freelist(&anim_data); @@ -368,8 +387,9 @@ short ANIM_animchannel_keyframes_loop(KeyframeEditData *ked, FcuEditFunc fcu_cb) { /* sanity checks */ - if (ale == NULL) + if (ale == NULL) { return 0; + } /* method to use depends on the type of keyframe data */ switch (ale->datatype) { @@ -407,8 +427,9 @@ short ANIM_animchanneldata_keyframes_loop(KeyframeEditData *ked, FcuEditFunc fcu_cb) { /* sanity checks */ - if (data == NULL) + if (data == NULL) { return 0; + } /* method to use depends on the type of keyframe data */ switch (keytype) { @@ -467,9 +488,11 @@ void ANIM_editkeyframes_refresh(bAnimContext *ac) /* ------------------------ */ /* Some macros to make this easier... */ -/* run the given check on the 3 handles - * - check should be a macro, which takes the handle index as its single arg, which it substitutes later - * - requires that a var, of type short, is named 'ok', and has been initialized to 0 +/* run the given check on the 3 handles: + * - Check should be a macro, which takes the handle index as its single arg, + * which it substitutes later. + * - Requires that a var, of type short, is named 'ok', + * and has been initialized to 0. */ #define KEYFRAME_OK_CHECKS(check) \ { \ @@ -519,19 +542,22 @@ static short ok_bezier_selected(KeyframeEditData *UNUSED(ked), BezTriple *bezt) /* this macro checks all beztriple handles for selection... * only one of the verts has to be selected for this to be ok... */ - if (BEZT_ISSEL_ANY(bezt)) + if (BEZT_ISSEL_ANY(bezt)) { return KEYFRAME_OK_ALL; - else + } + else { return 0; + } } static short ok_bezier_value(KeyframeEditData *ked, BezTriple *bezt) { short ok = 0; - /* value is stored in f1 property - * - this float accuracy check may need to be dropped? - * - should value be stored in f2 instead so that we won't have conflicts when using f1 for frames too? + /* Value is stored in f1 property: + * - This float accuracy check may need to be dropped? + * - Should value be stored in f2 instead + * so that we won't have conflicts when using f1 for frames too? */ #define KEY_CHECK_OK(_index) IS_EQF(bezt->vec[_index][1], ked->f1) KEYFRAME_OK_CHECKS(KEY_CHECK_OK); @@ -567,8 +593,9 @@ static short ok_bezier_region(KeyframeEditData *ked, BezTriple *bezt) /* return ok flags */ return ok; } - else + else { return 0; + } } /** @@ -603,8 +630,9 @@ static short ok_bezier_region_lasso(KeyframeEditData *ked, BezTriple *bezt) /* return ok flags */ return ok; } - else + else { return 0; + } } static short ok_bezier_channel_lasso(KeyframeEditData *ked, BezTriple *bezt) @@ -628,8 +656,9 @@ static short ok_bezier_channel_lasso(KeyframeEditData *ked, BezTriple *bezt) pt[0] = bezt->vec[1][0]; pt[1] = ked->channel_y; - if (keyframe_region_lasso_test(data, pt)) + if (keyframe_region_lasso_test(data, pt)) { return KEYFRAME_OK_KEY; + } } return 0; } @@ -665,8 +694,9 @@ static short ok_bezier_region_circle(KeyframeEditData *ked, BezTriple *bezt) /* return ok flags */ return ok; } - else + else { return 0; + } } static short ok_bezier_channel_circle(KeyframeEditData *ked, BezTriple *bezt) @@ -690,8 +720,9 @@ static short ok_bezier_channel_circle(KeyframeEditData *ked, BezTriple *bezt) pt[0] = bezt->vec[1][0]; pt[1] = ked->channel_y; - if (keyframe_region_circle_test(data, pt)) + if (keyframe_region_circle_test(data, pt)) { return KEYFRAME_OK_KEY; + } } return 0; } @@ -798,8 +829,9 @@ void bezt_remap_times(KeyframeEditData *ked, BezTriple *bezt) /* snaps the keyframe to the nearest frame */ static short snap_bezier_nearest(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->vec[1][0] = (float)(floorf(bezt->vec[1][0] + 0.5f)); + } return 0; } @@ -809,8 +841,9 @@ static short snap_bezier_nearestsec(KeyframeEditData *ked, BezTriple *bezt) const Scene *scene = ked->scene; const float secf = (float)FPS; - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->vec[1][0] = (floorf(bezt->vec[1][0] / secf + 0.5f) * secf); + } return 0; } @@ -818,16 +851,18 @@ static short snap_bezier_nearestsec(KeyframeEditData *ked, BezTriple *bezt) static short snap_bezier_cframe(KeyframeEditData *ked, BezTriple *bezt) { const Scene *scene = ked->scene; - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->vec[1][0] = (float)CFRA; + } return 0; } /* snaps the keyframe time to the nearest marker's frame */ static short snap_bezier_nearmarker(KeyframeEditData *ked, BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->vec[1][0] = (float)ED_markers_find_nearest_marker_time(&ked->list, bezt->vec[1][0]); + } return 0; } @@ -837,10 +872,12 @@ static short snap_bezier_horizontal(KeyframeEditData *UNUSED(ked), BezTriple *be if (bezt->f2 & SELECT) { bezt->vec[0][1] = bezt->vec[2][1] = bezt->vec[1][1]; - if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM, HD_VECT)) + if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM, HD_VECT)) { bezt->h1 = HD_ALIGN; - if (ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM, HD_VECT)) + } + if (ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM, HD_VECT)) { bezt->h2 = HD_ALIGN; + } } return 0; } @@ -848,16 +885,18 @@ static short snap_bezier_horizontal(KeyframeEditData *UNUSED(ked), BezTriple *be /* frame to snap to is stored in the custom data -> first float value slot */ static short snap_bezier_time(KeyframeEditData *ked, BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->vec[1][0] = ked->f1; + } return 0; } /* value to snap to is stored in the custom data -> first float value slot */ static short snap_bezier_value(KeyframeEditData *ked, BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->vec[1][1] = ked->f1; + } return 0; } @@ -998,8 +1037,10 @@ KeyframeEditFunc ANIM_editkeyframes_mirror(short type) /* ******************************************* */ /* Settings */ -/* standard validation step for a few of these (implemented as macro for inlining without fn-call overhead): - * "if the handles are not of the same type, set them to type free" +/** + * Standard validation step for a few of these + * (implemented as macro for inlining without fn-call overhead): + * "if the handles are not of the same type, set them to type free". */ #define ENSURE_HANDLES_MATCH(bezt) \ if (bezt->h1 != bezt->h2) { \ @@ -1014,10 +1055,12 @@ KeyframeEditFunc ANIM_editkeyframes_mirror(short type) static short set_bezier_auto(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { if ((bezt->f1 & SELECT) || (bezt->f3 & SELECT)) { - if (bezt->f1 & SELECT) + if (bezt->f1 & SELECT) { bezt->h1 = HD_AUTO; - if (bezt->f3 & SELECT) + } + if (bezt->f3 & SELECT) { bezt->h2 = HD_AUTO; + } ENSURE_HANDLES_MATCH(bezt); } @@ -1030,10 +1073,12 @@ static short set_bezier_auto(KeyframeEditData *UNUSED(ked), BezTriple *bezt) static short set_bezier_auto_clamped(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { if ((bezt->f1 & SELECT) || (bezt->f3 & SELECT)) { - if (bezt->f1 & SELECT) + if (bezt->f1 & SELECT) { bezt->h1 = HD_AUTO_ANIM; - if (bezt->f3 & SELECT) + } + if (bezt->f3 & SELECT) { bezt->h2 = HD_AUTO_ANIM; + } ENSURE_HANDLES_MATCH(bezt); } @@ -1043,10 +1088,12 @@ static short set_bezier_auto_clamped(KeyframeEditData *UNUSED(ked), BezTriple *b /* Sets the selected bezier handles to type 'vector' */ static short set_bezier_vector(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f1 & SELECT) + if (bezt->f1 & SELECT) { bezt->h1 = HD_VECT; - if (bezt->f3 & SELECT) + } + if (bezt->f3 & SELECT) { bezt->h2 = HD_VECT; + } return 0; } @@ -1055,30 +1102,36 @@ static short set_bezier_vector(KeyframeEditData *UNUSED(ked), BezTriple *bezt) // currently this isn't used, but may be restored later static short bezier_isfree(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if ((bezt->f1 & SELECT) && (bezt->h1)) + if ((bezt->f1 & SELECT) && (bezt->h1)) { return 1; - if ((bezt->f3 & SELECT) && (bezt->h2)) + } + if ((bezt->f3 & SELECT) && (bezt->h2)) { return 1; + } return 0; } /* Sets selected bezier handles to type 'align' */ static short set_bezier_align(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f1 & SELECT) + if (bezt->f1 & SELECT) { bezt->h1 = HD_ALIGN; - if (bezt->f3 & SELECT) + } + if (bezt->f3 & SELECT) { bezt->h2 = HD_ALIGN; + } return 0; } /* Sets selected bezier handles to type 'free' */ static short set_bezier_free(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f1 & SELECT) + if (bezt->f1 & SELECT) { bezt->h1 = HD_FREE; - if (bezt->f3 & SELECT) + } + if (bezt->f3 & SELECT) { bezt->h2 = HD_FREE; + } return 0; } @@ -1108,92 +1161,105 @@ KeyframeEditFunc ANIM_editkeyframes_handles(short code) static short set_bezt_constant(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->ipo = BEZT_IPO_CONST; + } return 0; } static short set_bezt_linear(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->ipo = BEZT_IPO_LIN; + } return 0; } static short set_bezt_bezier(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->ipo = BEZT_IPO_BEZ; + } return 0; } static short set_bezt_back(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->ipo = BEZT_IPO_BACK; + } return 0; } static short set_bezt_bounce(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->ipo = BEZT_IPO_BOUNCE; + } return 0; } static short set_bezt_circle(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->ipo = BEZT_IPO_CIRC; + } return 0; } static short set_bezt_cubic(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->ipo = BEZT_IPO_CUBIC; + } return 0; } static short set_bezt_elastic(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->ipo = BEZT_IPO_ELASTIC; + } return 0; } static short set_bezt_expo(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->ipo = BEZT_IPO_EXPO; + } return 0; } static short set_bezt_quad(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->ipo = BEZT_IPO_QUAD; + } return 0; } static short set_bezt_quart(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->ipo = BEZT_IPO_QUART; + } return 0; } static short set_bezt_quint(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->ipo = BEZT_IPO_QUINT; + } return 0; } static short set_bezt_sine(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->ipo = BEZT_IPO_SINE; + } return 0; } @@ -1239,36 +1305,41 @@ KeyframeEditFunc ANIM_editkeyframes_ipo(short code) static short set_keytype_keyframe(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { BEZKEYTYPE(bezt) = BEZT_KEYTYPE_KEYFRAME; + } return 0; } static short set_keytype_breakdown(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { BEZKEYTYPE(bezt) = BEZT_KEYTYPE_BREAKDOWN; + } return 0; } static short set_keytype_extreme(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { BEZKEYTYPE(bezt) = BEZT_KEYTYPE_EXTREME; + } return 0; } static short set_keytype_jitter(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { BEZKEYTYPE(bezt) = BEZT_KEYTYPE_JITTER; + } return 0; } static short set_keytype_moving_hold(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { BEZKEYTYPE(bezt) = BEZT_KEYTYPE_MOVEHOLD; + } return 0; } @@ -1298,29 +1369,33 @@ KeyframeEditFunc ANIM_editkeyframes_keytype(short code) static short set_easingtype_easein(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->easing = BEZT_IPO_EASE_IN; + } return 0; } static short set_easingtype_easeout(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->easing = BEZT_IPO_EASE_OUT; + } return 0; } static short set_easingtype_easeinout(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->easing = BEZT_IPO_EASE_IN_OUT; + } return 0; } static short set_easingtype_easeauto(KeyframeEditData *UNUSED(ked), BezTriple *bezt) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { bezt->easing = BEZT_IPO_EASE_AUTO; + } return 0; } @@ -1349,12 +1424,15 @@ static short select_bezier_add(KeyframeEditData *ked, BezTriple *bezt) { /* if we've got info on what to select, use it, otherwise select all */ if ((ked) && (ked->iterflags & KEYFRAME_ITER_INCL_HANDLES)) { - if (ked->curflags & KEYFRAME_OK_KEY) + if (ked->curflags & KEYFRAME_OK_KEY) { bezt->f2 |= SELECT; - if (ked->curflags & KEYFRAME_OK_H1) + } + if (ked->curflags & KEYFRAME_OK_H1) { bezt->f1 |= SELECT; - if (ked->curflags & KEYFRAME_OK_H2) + } + if (ked->curflags & KEYFRAME_OK_H2) { bezt->f3 |= SELECT; + } } else { BEZT_SEL_ALL(bezt); @@ -1367,12 +1445,15 @@ static short select_bezier_subtract(KeyframeEditData *ked, BezTriple *bezt) { /* if we've got info on what to deselect, use it, otherwise deselect all */ if ((ked) && (ked->iterflags & KEYFRAME_ITER_INCL_HANDLES)) { - if (ked->curflags & KEYFRAME_OK_KEY) + if (ked->curflags & KEYFRAME_OK_KEY) { bezt->f2 &= ~SELECT; - if (ked->curflags & KEYFRAME_OK_H1) + } + if (ked->curflags & KEYFRAME_OK_H1) { bezt->f1 &= ~SELECT; - if (ked->curflags & KEYFRAME_OK_H2) + } + if (ked->curflags & KEYFRAME_OK_H2) { bezt->f3 &= ~SELECT; + } } else { BEZT_DESEL_ALL(bezt); @@ -1470,8 +1551,9 @@ static short selmap_build_bezier_less(KeyframeEditData *ked, BezTriple *bezt) if (i > 0) { BezTriple *prev = bezt - 1; - if (BEZT_ISSEL_ANY(prev) == 0) + if (BEZT_ISSEL_ANY(prev) == 0) { return 0; + } } else if (i == 0) { /* current keyframe is selected at an endpoint, so should get deselected */ @@ -1482,8 +1564,9 @@ static short selmap_build_bezier_less(KeyframeEditData *ked, BezTriple *bezt) if (i < (fcu->totvert - 1)) { BezTriple *next = bezt + 1; - if (BEZT_ISSEL_ANY(next) == 0) + if (BEZT_ISSEL_ANY(next) == 0) { return 0; + } } else if (i == (fcu->totvert - 1)) { /* current keyframe is selected at an endpoint, so should get deselected */ diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 945327ed78b..5214c5f78fa 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -70,17 +70,20 @@ void delete_fcurve_key(FCurve *fcu, int index, bool do_recalc) { /* sanity check */ - if (fcu == NULL) + if (fcu == NULL) { return; + } /* verify the index: * 1) cannot be greater than the number of available keyframes * 2) negative indices are for specifying a value from the end of the array */ - if (abs(index) >= fcu->totvert) + if (abs(index) >= fcu->totvert) { return; - else if (index < 0) + } + else if (index < 0) { index += fcu->totvert; + } /* Delete this keyframe */ memmove( @@ -88,14 +91,16 @@ void delete_fcurve_key(FCurve *fcu, int index, bool do_recalc) fcu->totvert--; if (fcu->totvert == 0) { - if (fcu->bezt) + if (fcu->bezt) { MEM_freeN(fcu->bezt); + } fcu->bezt = NULL; } /* recalc handles - only if it won't cause problems */ - if (do_recalc) + if (do_recalc) { calchandles_fcurve(fcu); + } } /* Delete selected keyframes in given F-Curve */ @@ -104,8 +109,9 @@ bool delete_fcurve_keys(FCurve *fcu) int i; bool changed = false; - if (fcu->bezt == NULL) /* ignore baked curves */ + if (fcu->bezt == NULL) { /* ignore baked curves */ return false; + } /* Delete selected BezTriples */ for (i = 0; i < fcu->totvert; i++) { @@ -118,16 +124,18 @@ bool delete_fcurve_keys(FCurve *fcu) } /* Free the array of BezTriples if there are not keyframes */ - if (fcu->totvert == 0) + if (fcu->totvert == 0) { clear_fcurve_keys(fcu); + } return changed; } void clear_fcurve_keys(FCurve *fcu) { - if (fcu->bezt) + if (fcu->bezt) { MEM_freeN(fcu->bezt); + } fcu->bezt = NULL; fcu->totvert = 0; @@ -142,8 +150,9 @@ void duplicate_fcurve_keys(FCurve *fcu) int i; /* this can only work when there is an F-Curve, and also when there are some BezTriples */ - if (ELEM(NULL, fcu, fcu->bezt)) + if (ELEM(NULL, fcu, fcu->bezt)) { return; + } for (i = 0; i < fcu->totvert; i++) { /* If a key is selected */ @@ -173,8 +182,9 @@ void duplicate_fcurve_keys(FCurve *fcu) /* **************************************************** */ /* Various Tools */ -/* Basic F-Curve 'cleanup' function that removes 'double points' and unnecessary keyframes on linear-segments only - * optionally clears up curve if one keyframe with default value remains +/** + * Basic F-Curve 'cleanup' function that removes 'double points' and unnecessary keyframes on + * linear-segments only optionally clears up curve if one keyframe with default value remains. */ void clean_fcurve(struct bAnimContext *ac, bAnimListElem *ale, float thresh, bool cleardefault) { @@ -282,8 +292,9 @@ void clean_fcurve(struct bAnimContext *ac, bAnimListElem *ale, float thresh, boo } /* now free the memory used by the old BezTriples */ - if (old_bezts) + if (old_bezts) { MEM_freeN(old_bezts); + } /* final step, if there is just one key in fcurve, check if it's * the default value and if is, remove fcurve completely. */ @@ -295,8 +306,9 @@ void clean_fcurve(struct bAnimContext *ac, bAnimListElem *ale, float thresh, boo /* get property to read from, and get value as appropriate */ if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) { - if (RNA_property_type(prop) == PROP_FLOAT) + if (RNA_property_type(prop) == PROP_FLOAT) { default_value = RNA_property_float_get_default_index(&ptr, prop, fcu->array_index); + } } if (fcu->bezt->vec[1][1] == default_value) { @@ -335,8 +347,9 @@ void smooth_fcurve(FCurve *fcu) /* first loop through - count how many verts are selected */ bezt = fcu->bezt; for (i = 0; i < fcu->totvert; i++, bezt++) { - if (BEZT_ISSEL_ANY(bezt)) + if (BEZT_ISSEL_ANY(bezt)) { totSel++; + } } /* if any points were selected, allocate tSmooth_Bezt points to work on */ @@ -356,10 +369,12 @@ void smooth_fcurve(FCurve *fcu) tsb->h3 = &bezt->vec[2][1]; /* advance to the next tsb to populate */ - if (x < totSel - 1) + if (x < totSel - 1) { tsb++; - else + } + else { break; + } } } @@ -373,7 +388,8 @@ void smooth_fcurve(FCurve *fcu) /* round 1: calculate smoothing deltas and new values */ tsb = tarray; for (i = 0; i < totSel; i++, tsb++) { - /* don't touch end points (otherwise, curves slowly explode, as we don't have enough data there) */ + /* Don't touch end points (otherwise, curves slowly explode, + * as we don't have enough data there). */ if (ELEM(i, 0, (totSel - 1)) == 0) { const tSmooth_Bezt *tP1 = tsb - 1; const tSmooth_Bezt *tP2 = (i - 2 > 0) ? (tsb - 2) : (NULL); @@ -431,8 +447,9 @@ void sample_fcurve(FCurve *fcu) int sfra, range; int i, n; - if (fcu->bezt == NULL) /* ignore baked */ + if (fcu->bezt == NULL) { /* ignore baked */ return; + } /* find selected keyframes... once pair has been found, add keyframes */ for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) { @@ -500,11 +517,12 @@ void sample_fcurve(FCurve *fcu) } /* **************************************************** */ -/* Copy/Paste Tools */ -/* - The copy/paste buffer currently stores a set of temporary F-Curves containing only the keyframes - * that were selected in each of the original F-Curves - * - All pasted frames are offset by the same amount. This is calculated as the difference in the times of - * the current frame and the 'first keyframe' (i.e. the earliest one in all channels). +/* Copy/Paste Tools: + * - The copy/paste buffer currently stores a set of temporary F-Curves containing only the + * keyframes that were selected in each of the original F-Curves. + * - All pasted frames are offset by the same amount. + * This is calculated as the difference in the times of the current frame and the + * 'first keyframe' (i.e. the earliest one in all channels). * - The earliest frame is calculated per copy operation. */ @@ -540,12 +558,14 @@ void ANIM_fcurves_copybuf_free(void) acn = aci->next; /* free keyframes */ - if (aci->bezt) + if (aci->bezt) { MEM_freeN(aci->bezt); + } /* free RNA-path */ - if (aci->rna_path) + if (aci->rna_path) { MEM_freeN(aci->rna_path); + } /* free ourself */ BLI_freelinkN(&animcopybuf, aci); @@ -580,8 +600,9 @@ short copy_animedit_keys(bAnimContext *ac, ListBase *anim_data) * - this check should also eliminate any problems associated with using sample-data */ if (ANIM_fcurve_keyframes_loop( - NULL, fcu, NULL, ANIM_editkeyframes_ok(BEZT_OK_SELECTED), NULL) == 0) + NULL, fcu, NULL, ANIM_editkeyframes_ok(BEZT_OK_SELECTED), NULL) == 0) { continue; + } /* init copybuf item info */ aci = MEM_callocN(sizeof(tAnimCopybufItem), "AnimCopybufItem"); @@ -591,8 +612,9 @@ short copy_animedit_keys(bAnimContext *ac, ListBase *anim_data) aci->rna_path = MEM_dupallocN(fcu->rna_path); aci->array_index = fcu->array_index; - /* detect if this is a bone. We do that here rather than during pasting because ID pointers will get invalidated if we undo. - * storing the relevant information here helps avoiding crashes if we undo-repaste */ + /* Detect if this is a bone. We do that here rather than during pasting because ID pointers + * will get invalidated if we undo. + * Storing the relevant information here helps avoiding crashes if we undo-repaste. */ if ((aci->id_type == ID_OB) && (((Object *)aci->id)->type == OB_ARMATURE) && aci->rna_path) { Object *ob = (Object *)aci->id; bPoseChannel *pchan; @@ -603,8 +625,9 @@ short copy_animedit_keys(bAnimContext *ac, ListBase *anim_data) if (pchan) { aci->is_bone = true; } - if (bone_name) + if (bone_name) { MEM_freeN(bone_name); + } } BLI_addtail(&animcopybuf, aci); @@ -618,8 +641,9 @@ short copy_animedit_keys(bAnimContext *ac, ListBase *anim_data) newbuf = MEM_callocN(sizeof(BezTriple) * (aci->totvert + 1), "copybuf beztriple"); /* assume that since we are just re-sizing the array, just copy all existing data across */ - if (aci->bezt) + if (aci->bezt) { memcpy(newbuf, aci->bezt, sizeof(BezTriple) * (aci->totvert)); + } /* copy current beztriple across too */ nbezt = &newbuf[aci->totvert]; @@ -629,23 +653,27 @@ short copy_animedit_keys(bAnimContext *ac, ListBase *anim_data) BEZT_SEL_ALL(nbezt); /* free old array and set the new */ - if (aci->bezt) + if (aci->bezt) { MEM_freeN(aci->bezt); + } aci->bezt = newbuf; aci->totvert++; /* check if this is the earliest frame encountered so far */ - if (bezt->vec[1][0] < animcopy_firstframe) + if (bezt->vec[1][0] < animcopy_firstframe) { animcopy_firstframe = bezt->vec[1][0]; - if (bezt->vec[1][0] > animcopy_lastframe) + } + if (bezt->vec[1][0] > animcopy_lastframe) { animcopy_lastframe = bezt->vec[1][0]; + } } } } /* check if anything ended up in the buffer */ - if (ELEM(NULL, animcopybuf.first, animcopybuf.last)) + if (ELEM(NULL, animcopybuf.first, animcopybuf.last)) { return -1; + } /* in case 'relative' paste method is used */ animcopy_cfra = CFRA; @@ -758,8 +786,9 @@ static tAnimCopybufItem *pastebuf_match_path_property(Main *bmain, if (len_id <= len_path) { /* note, paths which end with "] will fail with this test - Animated ID Props */ if (STREQ(identifier, fcu->rna_path + (len_path - len_id))) { - if ((from_single) || (aci->array_index == fcu->array_index)) + if ((from_single) || (aci->array_index == fcu->array_index)) { break; + } } } } @@ -799,17 +828,21 @@ static void do_curve_mirror_flippping(tAnimCopybufItem *aci, BezTriple *bezt) if (aci->is_bone) { const size_t slength = strlen(aci->rna_path); bool flip = false; - if (BLI_strn_endswith(aci->rna_path, "location", slength) && aci->array_index == 0) + if (BLI_strn_endswith(aci->rna_path, "location", slength) && aci->array_index == 0) { flip = true; + } else if (BLI_strn_endswith(aci->rna_path, "rotation_quaternion", slength) && - ELEM(aci->array_index, 2, 3)) + ELEM(aci->array_index, 2, 3)) { flip = true; + } else if (BLI_strn_endswith(aci->rna_path, "rotation_euler", slength) && - ELEM(aci->array_index, 1, 2)) + ELEM(aci->array_index, 1, 2)) { flip = true; + } else if (BLI_strn_endswith(aci->rna_path, "rotation_axis_angle", slength) && - ELEM(aci->array_index, 2, 3)) + ELEM(aci->array_index, 2, 3)) { flip = true; + } if (flip) { bezt->vec[0][1] = -bezt->vec[0][1]; @@ -875,8 +908,9 @@ static void paste_animedit_keys_fcurve( /* just start pasting, with the first keyframe on the current frame, and so on */ for (i = 0, bezt = aci->bezt; i < aci->totvert; i++, bezt++) { /* temporarily apply offset to src beztriple while copying */ - if (flip) + if (flip) { do_curve_mirror_flippping(aci, bezt); + } bezt->vec[0][0] += offset; bezt->vec[1][0] += offset; @@ -893,8 +927,9 @@ static void paste_animedit_keys_fcurve( bezt->vec[1][0] -= offset; bezt->vec[2][0] -= offset; - if (flip) + if (flip) { do_curve_mirror_flippping(aci, bezt); + } } /* recalculate F-Curve's handles? */ @@ -1005,10 +1040,11 @@ short paste_animedit_keys(bAnimContext *ac, unsigned int totmatch = 0; for (ale = anim_data->first; ale; ale = ale->next) { - /* find buffer item to paste from - * - if names don't matter (i.e. only 1 channel in buffer), don't check id/group - * - if names do matter, only check if id-type is ok for now (group check is not that important) - * - most importantly, rna-paths should match (array indices are unimportant for now) + /* Find buffer item to paste from: + * - If names don't matter (i.e. only 1 channel in buffer), don't check id/group + * - If names do matter, only check if id-type is ok for now + * (group check is not that important). + * - Most importantly, rna-paths should match (array indices are unimportant for now) */ AnimData *adt = ANIM_nla_mapping_get(ac, ale); FCurve *fcu = (FCurve *)ale->data; /* destination F-Curve */ @@ -1049,8 +1085,9 @@ short paste_animedit_keys(bAnimContext *ac, } /* don't continue if some fcurves were pasted */ - if (totmatch) + if (totmatch) { break; + } } } diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index cc8dbbca439..a0433b49b16 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -94,27 +94,32 @@ short ANIM_get_keyframing_flags(Scene *scene, short incl_mode) /* standard flags */ { /* visual keying */ - if (IS_AUTOKEY_FLAG(scene, AUTOMATKEY)) + if (IS_AUTOKEY_FLAG(scene, AUTOMATKEY)) { flag |= INSERTKEY_MATRIX; + } /* only needed */ - if (IS_AUTOKEY_FLAG(scene, INSERTNEEDED)) + if (IS_AUTOKEY_FLAG(scene, INSERTNEEDED)) { flag |= INSERTKEY_NEEDED; + } /* default F-Curve color mode - RGB from XYZ indices */ - if (IS_AUTOKEY_FLAG(scene, XYZ2RGB)) + if (IS_AUTOKEY_FLAG(scene, XYZ2RGB)) { flag |= INSERTKEY_XYZ2RGB; + } } /* only if including settings from the autokeying mode... */ if (incl_mode) { /* keyframing mode - only replace existing keyframes */ - if (IS_AUTOKEY_MODE(scene, EDITKEYS)) + if (IS_AUTOKEY_MODE(scene, EDITKEYS)) { flag |= INSERTKEY_REPLACE; + } /* cycle-aware keyframe insertion - preserve cycle period and flow */ - if (IS_AUTOKEY_FLAG(scene, CYCLEAWARE)) + if (IS_AUTOKEY_FLAG(scene, CYCLEAWARE)) { flag |= INSERTKEY_CYCLE_AWARE; + } } return flag; @@ -132,8 +137,9 @@ bAction *verify_adt_action(Main *bmain, ID *id, short add) /* init animdata if none available yet */ adt = BKE_animdata_from_id(id); - if ((adt == NULL) && (add)) + if ((adt == NULL) && (add)) { adt = BKE_animdata_add_id(id); + } if (adt == NULL) { /* if still none (as not allowed to add, or ID doesn't have animdata for some reason) */ printf("ERROR: Couldn't add AnimData (ID = %s)\n", (id) ? (id->name) : "<None>"); @@ -181,8 +187,9 @@ FCurve *verify_fcurve(Main *bmain, FCurve *fcu; /* sanity checks */ - if (ELEM(NULL, act, rna_path)) + if (ELEM(NULL, act, rna_path)) { return NULL; + } /* try to find f-curve matching for this setting * - add if not found and allowed to add one @@ -196,8 +203,9 @@ FCurve *verify_fcurve(Main *bmain, fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED); fcu->auto_smoothing = FCURVE_SMOOTH_CONT_ACCEL; - if (BLI_listbase_is_empty(&act->curves)) + if (BLI_listbase_is_empty(&act->curves)) { fcu->flag |= FCURVE_ACTIVE; /* first one added active */ + } /* store path - make copy, and store that */ fcu->rna_path = BLI_strdup(rna_path); @@ -398,7 +406,8 @@ int insert_bezt_fcurve(FCurve *fcu, const BezTriple *bezt, eInsertKeyFlags flag) } if (flag & INSERTKEY_CYCLE_AWARE) { - /* If replacing an end point of a cyclic curve without offset, modify the other end too. */ + /* If replacing an end point of a cyclic curve without offset, + * modify the other end too. */ if ((i == 0 || i == fcu->totvert - 1) && BKE_fcurve_get_cycle_type(fcu) == FCU_CYCLE_PERFECT) { replace_bezt_keyframe_ypos(&fcu->bezt[i == 0 ? fcu->totvert - 1 : 0], bezt); @@ -411,16 +420,19 @@ int insert_bezt_fcurve(FCurve *fcu, const BezTriple *bezt, eInsertKeyFlags flag) /* insert new - if we're not restricted to replacing keyframes only */ BezTriple *newb = MEM_callocN((fcu->totvert + 1) * sizeof(BezTriple), "beztriple"); - /* add the beztriples that should occur before the beztriple to be pasted (originally in fcu) */ - if (i > 0) + /* Add the beztriples that should occur before the beztriple to be pasted + * (originally in fcu). */ + if (i > 0) { memcpy(newb, fcu->bezt, i * sizeof(BezTriple)); + } /* add beztriple to paste at index i */ *(newb + i) = *bezt; /* add the beztriples that occur after the beztriple to be pasted (originally in fcu) */ - if (i < fcu->totvert) + if (i < fcu->totvert) { memcpy(newb + i + 1, fcu->bezt + i, (fcu->totvert - i) * sizeof(BezTriple)); + } /* replace (+ free) old with new, only if necessary to do so */ MEM_freeN(fcu->bezt); @@ -531,37 +543,43 @@ int insert_vert_fcurve( /* what if 'a' is a negative index? * for now, just exit to prevent any segfaults */ - if (a < 0) + if (a < 0) { return -1; + } /* don't recalculate handles if fast is set * - this is a hack to make importers faster * - we may calculate twice (due to autohandle needing to be calculated twice) */ - if ((flag & INSERTKEY_FAST) == 0) + if ((flag & INSERTKEY_FAST) == 0) { calchandles_fcurve(fcu); + } /* set handletype and interpolation */ if ((fcu->totvert > 2) && (flag & INSERTKEY_REPLACE) == 0) { BezTriple *bezt = (fcu->bezt + a); - /* set interpolation from previous (if available), but only if we didn't just replace some keyframe - * - replacement is indicated by no-change in number of verts - * - when replacing, the user may have specified some interpolation that should be kept + /* Set interpolation from previous (if available), + * but only if we didn't just replace some keyframe: + * - Replacement is indicated by no-change in number of verts. + * - When replacing, the user may have specified some interpolation that should be kept. */ if (fcu->totvert > oldTot) { - if (a > 0) + if (a > 0) { bezt->ipo = (bezt - 1)->ipo; - else if (a < fcu->totvert - 1) + } + else if (a < fcu->totvert - 1) { bezt->ipo = (bezt + 1)->ipo; + } } /* don't recalculate handles if fast is set * - this is a hack to make importers faster * - we may calculate twice (due to autohandle needing to be calculated twice) */ - if ((flag & INSERTKEY_FAST) == 0) + if ((flag & INSERTKEY_FAST) == 0) { calchandles_fcurve(fcu); + } } /* return the index at which the keyframe was added */ @@ -590,11 +608,13 @@ static short new_key_needed(FCurve *fcu, float cFrame, float nValue) float valA = 0.0f, valB = 0.0f; /* safety checking */ - if (fcu == NULL) + if (fcu == NULL) { return KEYNEEDED_JUSTADD; + } totCount = fcu->totvert; - if (totCount == 0) + if (totCount == 0) { return KEYNEEDED_JUSTADD; + } /* loop through checking if any are the same */ bezt = fcu->bezt; @@ -631,10 +651,12 @@ static short new_key_needed(FCurve *fcu, float cFrame, float nValue) realVal = evaluate_fcurve(fcu, cFrame); /* compare whether it's the same as proposed */ - if (IS_EQF(realVal, nValue)) + if (IS_EQF(realVal, nValue)) { return KEYNEEDED_DONTADD; - else + } + else { return KEYNEEDED_JUSTADD; + } } } @@ -644,18 +666,21 @@ static short new_key_needed(FCurve *fcu, float cFrame, float nValue) * stays around or not depends on whether the values of previous/current * beztriples and new keyframe are the same. */ - if (IS_EQF(prevVal, nValue) && IS_EQF(beztVal, nValue) && IS_EQF(prevVal, beztVal)) + if (IS_EQF(prevVal, nValue) && IS_EQF(beztVal, nValue) && IS_EQF(prevVal, beztVal)) { return KEYNEEDED_DELNEXT; - else + } + else { return KEYNEEDED_JUSTADD; + } } } else { /* just add a keyframe if there's only one keyframe * and the new one occurs before the existing one does. */ - if ((cFrame < beztPosi) && (totCount == 1)) + if ((cFrame < beztPosi) && (totCount == 1)) { return KEYNEEDED_JUSTADD; + } } /* continue. frame to do not yet passed (or other conditions not met) */ @@ -663,8 +688,9 @@ static short new_key_needed(FCurve *fcu, float cFrame, float nValue) prev = bezt; bezt++; } - else + else { break; + } } /* Frame in which to add a new-keyframe occurs after all other keys @@ -677,15 +703,19 @@ static short new_key_needed(FCurve *fcu, float cFrame, float nValue) bezt = (fcu->bezt + (fcu->totvert - 1)); valA = bezt->vec[1][1]; - if (prev) + if (prev) { valB = prev->vec[1][1]; - else + } + else { valB = bezt->vec[1][1] + 1.0f; + } - if (IS_EQF(valA, nValue) && IS_EQF(valA, valB)) + if (IS_EQF(valA, nValue) && IS_EQF(valA, valB)) { return KEYNEEDED_DELPREV; - else + } + else { return KEYNEEDED_JUSTADD; + } } /* ------------------ RNA Data-Access Functions ------------------ */ @@ -791,8 +821,9 @@ static bool visualkey_can_use(PointerRNA *ptr, PropertyRNA *prop) const char *identifier = NULL; /* validate data */ - if (ELEM(NULL, ptr, ptr->data, prop)) + if (ELEM(NULL, ptr, ptr->data, prop)) { return false; + } /* get first constraint and determine type of keyframe constraints to check for * - constraints can be on either Objects or PoseChannels, so we only check if the @@ -821,8 +852,9 @@ static bool visualkey_can_use(PointerRNA *ptr, PropertyRNA *prop) } /* check if any data to search using */ - if (ELEM(NULL, con, identifier) && (has_parent == false) && (has_rigidbody == false)) + if (ELEM(NULL, con, identifier) && (has_parent == false) && (has_rigidbody == false)) { return false; + } /* location or rotation identifiers only... */ if (identifier == NULL) { @@ -846,16 +878,19 @@ static bool visualkey_can_use(PointerRNA *ptr, PropertyRNA *prop) /* only search if a searchtype and initial constraint are available */ if (searchtype) { /* parent or rigidbody are always matching */ - if (has_parent || has_rigidbody) + if (has_parent || has_rigidbody) { return true; + } /* constraints */ for (; con; con = con->next) { /* only consider constraint if it is not disabled, and has influence */ - if (con->flag & CONSTRAINT_DISABLE) + if (con->flag & CONSTRAINT_DISABLE) { continue; - if (con->enforce == 0.0f) + } + if (con->enforce == 0.0f) { continue; + } /* some constraints may alter these transforms */ switch (con->type) { @@ -873,48 +908,59 @@ static bool visualkey_can_use(PointerRNA *ptr, PropertyRNA *prop) /* single-transform constraints */ case CONSTRAINT_TYPE_TRACKTO: - if (searchtype == VISUALKEY_ROT) + if (searchtype == VISUALKEY_ROT) { return true; + } break; case CONSTRAINT_TYPE_DAMPTRACK: - if (searchtype == VISUALKEY_ROT) + if (searchtype == VISUALKEY_ROT) { return true; + } break; case CONSTRAINT_TYPE_ROTLIMIT: - if (searchtype == VISUALKEY_ROT) + if (searchtype == VISUALKEY_ROT) { return true; + } break; case CONSTRAINT_TYPE_LOCLIMIT: - if (searchtype == VISUALKEY_LOC) + if (searchtype == VISUALKEY_LOC) { return true; + } break; case CONSTRAINT_TYPE_SIZELIMIT: - if (searchtype == VISUALKEY_SCA) + if (searchtype == VISUALKEY_SCA) { return true; + } break; case CONSTRAINT_TYPE_DISTLIMIT: - if (searchtype == VISUALKEY_LOC) + if (searchtype == VISUALKEY_LOC) { return true; + } break; case CONSTRAINT_TYPE_ROTLIKE: - if (searchtype == VISUALKEY_ROT) + if (searchtype == VISUALKEY_ROT) { return true; + } break; case CONSTRAINT_TYPE_LOCLIKE: - if (searchtype == VISUALKEY_LOC) + if (searchtype == VISUALKEY_LOC) { return true; + } break; case CONSTRAINT_TYPE_SIZELIKE: - if (searchtype == VISUALKEY_SCA) + if (searchtype == VISUALKEY_SCA) { return true; + } break; case CONSTRAINT_TYPE_LOCKTRACK: - if (searchtype == VISUALKEY_ROT) + if (searchtype == VISUALKEY_ROT) { return true; + } break; case CONSTRAINT_TYPE_MINMAX: - if (searchtype == VISUALKEY_LOC) + if (searchtype == VISUALKEY_LOC) { return true; + } break; default: @@ -1025,7 +1071,10 @@ static float *visualkey_get_values(Depsgraph *depsgraph, /* ------------------------- Insert Key API ------------------------- */ -/* Retrieve current property values to keyframe, possibly applying NLA correction when necessary. */ +/** + * Retrieve current property values to keyframe, + * possibly applying NLA correction when necessary. + */ static float *get_keyframe_values(Depsgraph *depsgraph, ReportList *reports, PointerRNA ptr, @@ -1146,8 +1195,9 @@ static bool insert_keyframe_value(ReportList *reports, } /* Secondary Keyframing API call: - * Use this when validation of necessary animation data is not necessary, since an RNA-pointer to the necessary - * data being keyframed, and a pointer to the F-Curve to use have both been provided. + * Use this when validation of necessary animation data is not necessary, + * since an RNA-pointer to the necessary data being keyframed, + * and a pointer to the F-Curve to use have both been provided. * * This function can't keyframe quaternion channels on some NLA strip types. * @@ -1508,8 +1558,9 @@ static bool delete_keyframe_fcurve(AnimData *adt, FCurve *fcu, float cfra) /* Only delete curve too if it won't be doing anything anymore */ if ((fcu->totvert == 0) && - (list_has_suitable_fmodifier(&fcu->modifiers, 0, FMI_TYPE_GENERATE_CURVE) == 0)) + (list_has_suitable_fmodifier(&fcu->modifiers, 0, FMI_TYPE_GENERATE_CURVE) == 0)) { ANIM_fcurve_delete_from_animdata(NULL, adt, fcu); + } /* return success */ return true; @@ -1594,8 +1645,9 @@ short delete_keyframe(Main *bmain, * but don't do this for standard arrays since that can cause corruption issues * (extra unused curves) */ - if (array_index_max == array_index) + if (array_index_max == array_index) { array_index_max++; + } } /* will only loop once unless the array index was -1 */ @@ -1603,8 +1655,9 @@ short delete_keyframe(Main *bmain, FCurve *fcu = verify_fcurve(bmain, act, group, &ptr, rna_path, array_index, 0); /* check if F-Curve exists and/or whether it can be edited */ - if (fcu == NULL) + if (fcu == NULL) { continue; + } if (BKE_fcurve_is_protected(fcu)) { BKE_reportf(reports, @@ -1694,8 +1747,9 @@ static short clear_keyframe(Main *bmain, * but don't do this for standard arrays since that can cause corruption issues * (extra unused curves) */ - if (array_index_max == array_index) + if (array_index_max == array_index) { array_index_max++; + } } /* will only loop once unless the array index was -1 */ @@ -1703,8 +1757,9 @@ static short clear_keyframe(Main *bmain, FCurve *fcu = verify_fcurve(bmain, act, group, &ptr, rna_path, array_index, 0); /* check if F-Curve exists and/or whether it can be edited */ - if (fcu == NULL) + if (fcu == NULL) { continue; + } if (BKE_fcurve_is_protected(fcu)) { BKE_reportf(reports, @@ -1747,8 +1802,9 @@ static bool modify_key_op_poll(bContext *C) Scene *scene = CTX_data_scene(C); /* if no area or active scene */ - if (ELEM(NULL, sa, scene)) + if (ELEM(NULL, sa, scene)) { return false; + } /* should be fine */ return true; @@ -1780,12 +1836,13 @@ static int insert_key_exec(bContext *C, wmOperator *op) /* try to insert keyframes for the channels specified by KeyingSet */ success = ANIM_apply_keyingset(C, NULL, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { BKE_reportf(op->reports, RPT_INFO, "Keying set '%s' - successfully added %d keyframes", ks->name, success); + } /* restore the edit mode if necessary */ if (ob_edit_mode) { @@ -1799,18 +1856,20 @@ static int insert_key_exec(bContext *C, wmOperator *op) } else if (success) { /* if the appropriate properties have been set, make a note that we've inserted something */ - if (RNA_boolean_get(op->ptr, "confirm_success")) + if (RNA_boolean_get(op->ptr, "confirm_success")) { BKE_reportf(op->reports, RPT_INFO, "Successfully added %d keyframes for keying set '%s'", success, ks->name); + } /* send notifiers that keyframes have been changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_ADDED, NULL); } - else + else { BKE_report(op->reports, RPT_WARNING, "Keying set failed to insert any keyframes"); + } return OPERATOR_FINISHED; } @@ -2002,8 +2061,9 @@ static int delete_key_exec(bContext *C, wmOperator *op) /* try to delete keyframes for the channels specified by KeyingSet */ success = ANIM_apply_keyingset(C, NULL, NULL, ks, MODIFYKEY_MODE_DELETE, cfra); - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("KeyingSet '%s' - Successfully removed %d Keyframes\n", ks->name, success); + } /* report failure or do updates? */ if (success == MODIFYKEY_INVALID_CONTEXT) { @@ -2012,18 +2072,20 @@ static int delete_key_exec(bContext *C, wmOperator *op) } else if (success) { /* if the appropriate properties have been set, make a note that we've inserted something */ - if (RNA_boolean_get(op->ptr, "confirm_success")) + if (RNA_boolean_get(op->ptr, "confirm_success")) { BKE_reportf(op->reports, RPT_INFO, "Successfully removed %d keyframes for keying set '%s'", success, ks->name); + } /* send notifiers that keyframes have been changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, NULL); } - else + else { BKE_report(op->reports, RPT_WARNING, "Keying set failed to remove any keyframes"); + } return OPERATOR_FINISHED; } @@ -2123,13 +2185,15 @@ static int clear_anim_v3d_exec(bContext *C, wmOperator *UNUSED(op)) /* get bone-name, and check if this bone is selected */ bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones["); pchan = BKE_pose_channel_find_name(ob->pose, bone_name); - if (bone_name) + if (bone_name) { MEM_freeN(bone_name); + } /* delete if bone is selected*/ if ((pchan) && (pchan->bone)) { - if (pchan->bone->flag & BONE_SELECTED) + if (pchan->bone->flag & BONE_SELECTED) { can_delete = true; + } } } } @@ -2145,6 +2209,11 @@ static int clear_anim_v3d_exec(bContext *C, wmOperator *UNUSED(op)) changed = true; } } + + /* Delete the action itself if it is empty. */ + if (ANIM_remove_empty_action_from_animdata(adt)) { + changed = true; + } } } CTX_DATA_END; @@ -2205,8 +2274,9 @@ static int delete_key_v3d_exec(bContext *C, wmOperator *op) continue; } - /* special exception for bones, as this makes this operator more convenient to use - * NOTE: This is only done in pose mode. In object mode, we're dealing with the entire object. + /* Special exception for bones, as this makes this operator more convenient to use + * NOTE: This is only done in pose mode. + * In object mode, we're dealing with the entire object. */ if ((ob->mode & OB_MODE_POSE) && strstr(fcu->rna_path, "pose.bones[\"")) { bPoseChannel *pchan; @@ -2215,8 +2285,9 @@ static int delete_key_v3d_exec(bContext *C, wmOperator *op) /* get bone-name, and check if this bone is selected */ bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones["); pchan = BKE_pose_channel_find_name(ob->pose, bone_name); - if (bone_name) + if (bone_name) { MEM_freeN(bone_name); + } /* skip if bone is not selected */ if ((pchan) && (pchan->bone)) { @@ -2224,15 +2295,18 @@ static int delete_key_v3d_exec(bContext *C, wmOperator *op) bArmature *arm = (bArmature *)ob->data; /* skipping - not visible on currently visible layers */ - if ((arm->layer & pchan->bone->layer) == 0) + if ((arm->layer & pchan->bone->layer) == 0) { continue; + } /* skipping - is currently hidden */ - if (pchan->bone->flag & BONE_HIDDEN_P) + if (pchan->bone->flag & BONE_HIDDEN_P) { continue; + } /* selection flag... */ - if ((pchan->bone->flag & BONE_SELECTED) == 0) + if ((pchan->bone->flag & BONE_SELECTED) == 0) { continue; + } } } @@ -2245,14 +2319,16 @@ static int delete_key_v3d_exec(bContext *C, wmOperator *op) } /* report success (or failure) */ - if (success) + if (success) { BKE_reportf(op->reports, RPT_INFO, "Object '%s' successfully had %d keyframes removed", id->name + 2, success); - else + } + else { BKE_reportf(op->reports, RPT_ERROR, "No keyframes removed from Object '%s'", id->name + 2); + } DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM); } @@ -2355,8 +2431,9 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) const char *group = NULL; /* Special exception for keyframing transforms: - * Set "group" for this manually, instead of having them appearing at the bottom (ungrouped) - * part of the channels list. Leaving these ungrouped is not a nice user behavior in this case. + * Set "group" for this manually, instead of having them appearing at the bottom + * (ungrouped) part of the channels list. + * Leaving these ungrouped is not a nice user behavior in this case. * * TODO: Perhaps we can extend this behavior in future for other properties... */ @@ -2526,8 +2603,9 @@ static int delete_key_button_exec(bContext *C, wmOperator *op) bmain, op->reports, ptr.id.data, NULL, NULL, path, index, cfra, 0); MEM_freeN(path); } - else if (G.debug & G_DEBUG) + else if (G.debug & G_DEBUG) { printf("Button Delete-Key: no path to property\n"); + } } } else if (G.debug & G_DEBUG) { @@ -2593,8 +2671,9 @@ static int clear_key_button_exec(bContext *C, wmOperator *op) success += clear_keyframe(bmain, op->reports, ptr.id.data, NULL, NULL, path, index, 0); MEM_freeN(path); } - else if (G.debug & G_DEBUG) + else if (G.debug & G_DEBUG) { printf("Button Clear-Key: no path to property\n"); + } } else if (G.debug & G_DEBUG) { printf("ptr.data = %p, prop = %p\n", (void *)ptr.data, (void *)prop); @@ -2637,8 +2716,9 @@ bool autokeyframe_cfra_can_key(Scene *scene, ID *id) float cfra = (float)CFRA; // XXX for now, this will do /* only filter if auto-key mode requires this */ - if (IS_AUTOKEY_ON(scene) == 0) + if (IS_AUTOKEY_ON(scene) == 0) { return false; + } if (IS_AUTOKEY_MODE(scene, EDITKEYS)) { /* Replace Mode: @@ -2669,8 +2749,9 @@ bool autokeyframe_cfra_can_key(Scene *scene, ID *id) bool fcurve_frame_has_keyframe(FCurve *fcu, float frame, short filter) { /* quick sanity check */ - if (ELEM(NULL, fcu, fcu->bezt)) + if (ELEM(NULL, fcu, fcu->bezt)) { return false; + } /* we either include all regardless of muting, or only non-muted */ if ((filter & ANIMFILTER_KEYS_MUTED) || (fcu->flag & FCURVE_MUTED) == 0) { @@ -2682,8 +2763,9 @@ bool fcurve_frame_has_keyframe(FCurve *fcu, float frame, short filter) */ if (replace) { /* sanity check: 'i' may in rare cases exceed arraylen */ - if ((i >= 0) && (i < fcu->totvert)) + if ((i >= 0) && (i < fcu->totvert)) { return true; + } } } @@ -2713,20 +2795,24 @@ bool fcurve_is_changed(PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, float fra return !compare_ff_relative(fcurve_val, cur_val, FLT_EPSILON, 64); } -/* Checks whether an Action has a keyframe for a given frame - * Since we're only concerned whether a keyframe exists, we can simply loop until a match is found... +/** + * Checks whether an Action has a keyframe for a given frame + * Since we're only concerned whether a keyframe exists, + * we can simply loop until a match is found. */ static bool action_frame_has_keyframe(bAction *act, float frame, short filter) { FCurve *fcu; /* can only find if there is data */ - if (act == NULL) + if (act == NULL) { return false; + } /* if only check non-muted, check if muted */ - if ((filter & ANIMFILTER_KEYS_MUTED) || (act->flag & ACT_MUTED)) + if ((filter & ANIMFILTER_KEYS_MUTED) || (act->flag & ACT_MUTED)) { return false; + } /* loop over F-Curves, using binary-search to try to find matches * - this assumes that keyframes are only beztriples @@ -2734,8 +2820,9 @@ static bool action_frame_has_keyframe(bAction *act, float frame, short filter) for (fcu = act->curves.first; fcu; fcu = fcu->next) { /* only check if there are keyframes (currently only of type BezTriple) */ if (fcu->bezt && fcu->totvert) { - if (fcurve_frame_has_keyframe(fcu, frame, filter)) + if (fcurve_frame_has_keyframe(fcu, frame, filter)) { return true; + } } } @@ -2747,8 +2834,9 @@ static bool action_frame_has_keyframe(bAction *act, float frame, short filter) static bool object_frame_has_keyframe(Object *ob, float frame, short filter) { /* error checking */ - if (ob == NULL) + if (ob == NULL) { return false; + } /* check own animation data - specifically, the action it contains */ if ((ob->adt) && (ob->adt->action)) { @@ -2758,8 +2846,9 @@ static bool object_frame_has_keyframe(Object *ob, float frame, short filter) */ float ob_frame = BKE_nla_tweakedit_remap(ob->adt, frame, NLATIME_CONVERT_UNMAP); - if (action_frame_has_keyframe(ob->adt->action, ob_frame, filter)) + if (action_frame_has_keyframe(ob->adt->action, ob_frame, filter)) { return true; + } } /* try shapekey keyframes (if available, and allowed by filter) */ @@ -2771,8 +2860,9 @@ static bool object_frame_has_keyframe(Object *ob, float frame, short filter) */ /* 1. test for relative (with keyframes) */ - if (id_frame_has_keyframe((ID *)key, frame, filter)) + if (id_frame_has_keyframe((ID *)key, frame, filter)) { return true; + } /* 2. test for time */ /* TODO... yet to be implemented (this feature may evolve before then anyway) */ @@ -2785,8 +2875,9 @@ static bool object_frame_has_keyframe(Object *ob, float frame, short filter) Material *ma = give_current_material(ob, (ob->actcol + 1)); /* we only retrieve the active material... */ - if (id_frame_has_keyframe((ID *)ma, frame, filter)) + if (id_frame_has_keyframe((ID *)ma, frame, filter)) { return true; + } } else { int a; @@ -2795,8 +2886,9 @@ static bool object_frame_has_keyframe(Object *ob, float frame, short filter) for (a = 0; a < ob->totcol; a++) { Material *ma = give_current_material(ob, a + 1); - if (id_frame_has_keyframe((ID *)ma, frame, filter)) + if (id_frame_has_keyframe((ID *)ma, frame, filter)) { return true; + } } } } @@ -2811,8 +2903,9 @@ static bool object_frame_has_keyframe(Object *ob, float frame, short filter) bool id_frame_has_keyframe(ID *id, float frame, short filter) { /* sanity checks */ - if (id == NULL) + if (id == NULL) { return false; + } /* perform special checks for 'macro' types */ switch (GS(id->name)) { @@ -2828,8 +2921,9 @@ bool id_frame_has_keyframe(ID *id, float frame, short filter) AnimData *adt = BKE_animdata_from_id(id); /* only check keyframes in active action */ - if (adt) + if (adt) { return action_frame_has_keyframe(adt->action, frame, filter); + } break; } } diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c index 93bae636571..ab5e3186c47 100644 --- a/source/blender/editors/animation/keyingsets.c +++ b/source/blender/editors/animation/keyingsets.c @@ -76,8 +76,9 @@ static bool keyingset_poll_active_edit(bContext *C) { Scene *scene = CTX_data_scene(C); - if (scene == NULL) + if (scene == NULL) { return 0; + } /* there must be an active KeyingSet (and KeyingSets) */ return ((scene->active_keyingset > 0) && (scene->keyingsets.first)); @@ -89,12 +90,15 @@ static bool keyingset_poll_activePath_edit(bContext *C) Scene *scene = CTX_data_scene(C); KeyingSet *ks; - if (scene == NULL) + if (scene == NULL) { return 0; - if (scene->active_keyingset <= 0) + } + if (scene->active_keyingset <= 0) { return 0; - else + } + else { ks = BLI_findlink(&scene->keyingsets, scene->active_keyingset - 1); + } /* there must be an active KeyingSet and an active path */ return ((ks) && (ks->paths.first) && (ks->active_path > 0)); @@ -157,8 +161,9 @@ static int remove_active_keyingset_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "Cannot remove built in keying set"); return OPERATOR_CANCELLED; } - else + else { ks = BLI_findlink(&scene->keyingsets, scene->active_keyingset - 1); + } /* free KeyingSet's data, then remove it from the scene */ BKE_keyingset_free(ks); @@ -201,8 +206,9 @@ static int add_empty_ks_path_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "No active keying set to add empty path to"); return OPERATOR_CANCELLED; } - else + else { ks = BLI_findlink(&scene->keyingsets, scene->active_keyingset - 1); + } /* don't use the API method for this, since that checks on values... */ ksp = MEM_callocN(sizeof(KS_Path), "KeyingSetPath Empty"); @@ -307,8 +313,9 @@ static int add_keyingset_button_exec(bContext *C, wmOperator *op) keyingflag |= ANIM_get_keyframing_flags(scene, 0); - if (IS_AUTOKEY_FLAG(scene, XYZ2RGB)) + if (IS_AUTOKEY_FLAG(scene, XYZ2RGB)) { keyingflag |= INSERTKEY_XYZ2RGB; + } /* call the API func, and set the active keyingset index */ ks = BKE_keyingset_add( @@ -370,7 +377,7 @@ void ANIM_OT_keyingset_button_add(wmOperatorType *ot) /* callbacks */ ot->exec = add_keyingset_button_exec; - //op->poll = ??? + // op->poll = ??? /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -452,7 +459,7 @@ void ANIM_OT_keyingset_button_remove(wmOperatorType *ot) /* callbacks */ ot->exec = remove_keyingset_button_exec; - //op->poll = ??? + // op->poll = ??? /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -461,7 +468,8 @@ void ANIM_OT_keyingset_button_remove(wmOperatorType *ot) /* ******************************************* */ /* Change Active KeyingSet Operator ------------------------ */ -/* This operator checks if a menu should be shown for choosing the KeyingSet to make the active one */ +/* This operator checks if a menu should be shown + * for choosing the KeyingSet to make the active one. */ static int keyingset_active_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { @@ -526,36 +534,41 @@ ListBase builtin_keyingsets = {NULL, NULL}; /* --------------- */ -/* Find KeyingSet type info given a name */ +/* Find KeyingSet type info given a name. */ KeyingSetInfo *ANIM_keyingset_info_find_name(const char name[]) { /* sanity checks */ - if ((name == NULL) || (name[0] == 0)) + if ((name == NULL) || (name[0] == 0)) { return NULL; + } /* search by comparing names */ return BLI_findstring(&keyingset_type_infos, name, offsetof(KeyingSetInfo, idname)); } -/* Find builtin KeyingSet by name */ +/* Find builtin KeyingSet by name. */ KeyingSet *ANIM_builtin_keyingset_get_named(KeyingSet *prevKS, const char name[]) { KeyingSet *ks, *first = NULL; /* sanity checks any name to check? */ - if (name[0] == 0) + if (name[0] == 0) { return NULL; + } /* get first KeyingSet to use */ - if (prevKS && prevKS->next) + if (prevKS && prevKS->next) { first = prevKS->next; - else + } + else { first = builtin_keyingsets.first; + } /* loop over KeyingSets checking names */ for (ks = first; ks; ks = ks->next) { - if (STREQ(name, ks->idname)) + if (STREQ(name, ks->idname)) { return ks; + } } /* complain about missing keying sets on debug builds */ @@ -569,7 +582,8 @@ KeyingSet *ANIM_builtin_keyingset_get_named(KeyingSet *prevKS, const char name[] /* --------------- */ -/* Add the given KeyingSetInfo to the list of type infos, and create an appropriate builtin set too */ +/* Add the given KeyingSetInfo to the list of type infos, + * and create an appropriate builtin set too. */ void ANIM_keyingset_info_register(KeyingSetInfo *ksi) { KeyingSet *ks; @@ -589,7 +603,8 @@ void ANIM_keyingset_info_register(KeyingSetInfo *ksi) BLI_addtail(&keyingset_type_infos, ksi); } -/* Remove the given KeyingSetInfo from the list of type infos, and also remove the builtin set if appropriate */ +/* Remove the given KeyingSetInfo from the list of type infos, + * and also remove the builtin set if appropriate. */ void ANIM_keyingset_info_unregister(Main *bmain, KeyingSetInfo *ksi) { KeyingSet *ks, *ksn; @@ -606,8 +621,9 @@ void ANIM_keyingset_info_unregister(Main *bmain, KeyingSetInfo *ksi) BKE_keyingset_free(ks); BLI_remlink(&builtin_keyingsets, ks); - for (scene = bmain->scenes.first; scene; scene = scene->id.next) + for (scene = bmain->scenes.first; scene; scene = scene->id.next) { BLI_remlink_safe(&scene->keyingsets, ks); + } MEM_freeN(ks); } @@ -628,8 +644,9 @@ void ANIM_keyingset_infos_exit(void) next = ksi->next; /* free extra RNA data, and remove from list */ - if (ksi->ext.free) + if (ksi->ext.free) { ksi->ext.free(ksi->ext.data); + } BLI_freelinkN(&keyingset_type_infos, ksi); } @@ -641,8 +658,9 @@ void ANIM_keyingset_infos_exit(void) bool ANIM_keyingset_find_id(KeyingSet *ks, ID *id) { /* sanity checks */ - if (ELEM(NULL, ks, id)) + if (ELEM(NULL, ks, id)) { return false; + } return BLI_findptr(&ks->paths, id, offsetof(KS_Path, id)) != NULL; } @@ -656,18 +674,21 @@ bool ANIM_keyingset_find_id(KeyingSet *ks, ID *id) KeyingSet *ANIM_scene_get_active_keyingset(Scene *scene) { /* if no scene, we've got no hope of finding the Keying Set */ - if (scene == NULL) + if (scene == NULL) { return NULL; + } /* currently, there are several possibilities here: * - 0: no active keying set * - > 0: one of the user-defined Keying Sets, but indices start from 0 (hence the -1) * - < 0: a builtin keying set */ - if (scene->active_keyingset > 0) + if (scene->active_keyingset > 0) { return BLI_findlink(&scene->keyingsets, scene->active_keyingset - 1); - else + } + else { return BLI_findlink(&builtin_keyingsets, (-scene->active_keyingset) - 1); + } } /* Get the index of the Keying Set provided, for the given Scene */ @@ -676,8 +697,9 @@ int ANIM_scene_get_keyingset_index(Scene *scene, KeyingSet *ks) int index; /* if no KeyingSet provided, have none */ - if (ks == NULL) + if (ks == NULL) { return 0; + } /* check if the KeyingSet exists in scene list */ if (scene) { @@ -685,8 +707,9 @@ int ANIM_scene_get_keyingset_index(Scene *scene, KeyingSet *ks) * - (absolute) Scene KeyingSets are from (>= 1) */ index = BLI_findindex(&scene->keyingsets, ks); - if (index != -1) + if (index != -1) { return (index + 1); + } } /* still here, so try builtins list too @@ -694,10 +717,12 @@ int ANIM_scene_get_keyingset_index(Scene *scene, KeyingSet *ks) * - none/invalid is (= 0) */ index = BLI_findindex(&builtin_keyingsets, ks); - if (index != -1) + if (index != -1) { return -(index + 1); - else + } + else { return 0; + } } /* Get Keying Set to use for Auto-Keyframing some transforms */ @@ -707,12 +732,15 @@ KeyingSet *ANIM_get_keyingset_for_autokeying(Scene *scene, const char *transform * - use the active KeyingSet if defined (and user wants to use it for all autokeying), * or otherwise key transforms only */ - if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (scene->active_keyingset)) + if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (scene->active_keyingset)) { return ANIM_scene_get_active_keyingset(scene); - else if (IS_AUTOKEY_FLAG(scene, INSERTAVAIL)) + } + else if (IS_AUTOKEY_FLAG(scene, INSERTAVAIL)) { return ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_AVAILABLE_ID); - else + } + else { return ANIM_builtin_keyingset_get_named(NULL, transformKSName); + } } /* Menu of All Keying Sets ----------------------------- */ @@ -832,8 +860,9 @@ bool ANIM_keyingset_context_ok_poll(bContext *C, KeyingSet *ks) KeyingSetInfo *ksi = ANIM_keyingset_info_find_name(ks->typeinfo); /* get the associated 'type info' for this KeyingSet */ - if (ksi == NULL) + if (ksi == NULL) { return 0; + } /* TODO: check for missing callbacks! */ /* check if it can be used in the current context */ @@ -880,20 +909,24 @@ void ANIM_relative_keyingset_add_source(ListBase *dsources, ID *id, StructRNA *s * - we must have somewhere to output the data * - we must have both srna+data (and with id too optionally), or id by itself only */ - if (dsources == NULL) + if (dsources == NULL) { return; - if (ELEM(NULL, srna, data) && (id == NULL)) + } + if (ELEM(NULL, srna, data) && (id == NULL)) { return; + } /* allocate new elem, and add to the list */ ds = MEM_callocN(sizeof(tRKS_DSource), "tRKS_DSource"); BLI_addtail(dsources, ds); /* depending on what data we have, create using ID or full pointer call */ - if (srna && data) + if (srna && data) { RNA_pointer_create(id, srna, data, &ds->ptr); - else + } + else { RNA_id_pointer_create(id, &ds->ptr); + } } /* KeyingSet Operations (Insert/Delete Keyframes) ------------ */ @@ -908,8 +941,9 @@ void ANIM_relative_keyingset_add_source(ListBase *dsources, ID *id, StructRNA *s short ANIM_validate_keyingset(bContext *C, ListBase *dsources, KeyingSet *ks) { /* sanity check */ - if (ks == NULL) + if (ks == NULL) { return 0; + } /* if relative Keying Sets, poll and build up the paths */ if ((ks->flag & KEYINGSET_ABSOLUTE) == 0) { @@ -921,8 +955,9 @@ short ANIM_validate_keyingset(bContext *C, ListBase *dsources, KeyingSet *ks) BKE_keyingset_free(ks); /* get the associated 'type info' for this KeyingSet */ - if (ksi == NULL) + if (ksi == NULL) { return MODIFYKEY_MISSING_TYPEINFO; + } /* TODO: check for missing callbacks! */ /* check if it can be used in the current context */ @@ -930,15 +965,18 @@ short ANIM_validate_keyingset(bContext *C, ListBase *dsources, KeyingSet *ks) /* if a list of data sources are provided, run a special iterator over them, * otherwise, just continue per normal */ - if (dsources) + if (dsources) { RKS_ITER_overrides_list(ksi, C, ks, dsources); - else + } + else { ksi->iter(ksi, C, ks); + } /* if we don't have any paths now, then this still qualifies as invalid context */ // FIXME: we need some error conditions (to be retrieved from the iterator why this failed!) - if (BLI_listbase_is_empty(&ks->paths)) + if (BLI_listbase_is_empty(&ks->paths)) { return MODIFYKEY_INVALID_CONTEXT; + } } else { /* poll callback tells us that KeyingSet is useless in current context */ @@ -983,8 +1021,10 @@ static short keyingset_apply_keying_flags(const short base_flags, return result; } -/* Given a KeyingSet and context info (if required), modify keyframes for the channels specified - * by the KeyingSet. This takes into account many of the different combinations of using KeyingSets. +/** + * Given a KeyingSet and context info (if required), + * modify keyframes for the channels specified by the KeyingSet. + * This takes into account many of the different combinations of using KeyingSets. * Returns the number of channels that keyframes were added to */ int ANIM_apply_keyingset( @@ -1002,16 +1042,18 @@ int ANIM_apply_keyingset( char keytype = scene->toolsettings->keyframe_type; /* sanity checks */ - if (ks == NULL) + if (ks == NULL) { return 0; + } /* get flags to use */ if (mode == MODIFYKEY_MODE_INSERT) { /* use context settings as base */ kflag = keyingset_apply_keying_flags(base_kflags, ks->keyingoverride, ks->keyingflag); } - else if (mode == MODIFYKEY_MODE_DELETE) + else if (mode == MODIFYKEY_MODE_DELETE) { kflag = 0; + } /* if relative Keying Sets, poll and build up the paths */ success = ANIM_validate_keyingset(C, dsources, ks); @@ -1037,16 +1079,20 @@ int ANIM_apply_keyingset( continue; } - /* since keying settings can be defined on the paths too, apply the settings for this path first */ + /* Since keying settings can be defined on the paths too, + * apply the settings for this path first. */ kflag2 = keyingset_apply_keying_flags(kflag, ksp->keyingoverride, ksp->keyingflag); /* get pointer to name of group to add channels to */ - if (ksp->groupmode == KSP_GROUP_NONE) + if (ksp->groupmode == KSP_GROUP_NONE) { groupname = NULL; - else if (ksp->groupmode == KSP_GROUP_KSNAME) + } + else if (ksp->groupmode == KSP_GROUP_KSNAME) { groupname = ks->name; - else + } + else { groupname = ksp->group; + } /* init arraylen and i - arraylen should be greater than i so that * normal non-array entries get keyframed correctly @@ -1068,15 +1114,16 @@ int ANIM_apply_keyingset( } /* we should do at least one step */ - if (arraylen == i) + if (arraylen == i) { arraylen++; + } /* for each possible index, perform operation * - assume that arraylen is greater than index */ for (; i < arraylen; i++) { /* action to take depends on mode */ - if (mode == MODIFYKEY_MODE_INSERT) + if (mode == MODIFYKEY_MODE_INSERT) { success += insert_keyframe(bmain, depsgraph, reports, @@ -1089,9 +1136,11 @@ int ANIM_apply_keyingset( keytype, &nla_cache, kflag2); - else if (mode == MODIFYKEY_MODE_DELETE) + } + else if (mode == MODIFYKEY_MODE_DELETE) { success += delete_keyframe( bmain, reports, ksp->id, act, groupname, ksp->rna_path, i, cfra, kflag2); + } } /* set recalc-flags */ diff --git a/source/blender/editors/armature/CMakeLists.txt b/source/blender/editors/armature/CMakeLists.txt index 274fa86184d..71c7febe192 100644 --- a/source/blender/editors/armature/CMakeLists.txt +++ b/source/blender/editors/armature/CMakeLists.txt @@ -26,9 +26,9 @@ set(INC ../../makesrna ../../windowmanager ../../../../intern/clog - ../../../../intern/guardedalloc ../../../../intern/eigen ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/armature/armature_add.c b/source/blender/editors/armature/armature_add.c index 6943d6bdc54..d02e58d48a9 100644 --- a/source/blender/editors/armature/armature_add.c +++ b/source/blender/editors/armature/armature_add.c @@ -79,14 +79,16 @@ EditBone *ED_armature_ebone_add(bArmature *arm, const char *name) /* Bendy-Bone parameters */ bone->roll1 = 0.0f; bone->roll2 = 0.0f; - bone->curveInX = 0.0f; - bone->curveInY = 0.0f; - bone->curveOutX = 0.0f; - bone->curveOutY = 0.0f; + bone->curve_in_x = 0.0f; + bone->curve_in_y = 0.0f; + bone->curve_out_x = 0.0f; + bone->curve_out_y = 0.0f; bone->ease1 = 1.0f; bone->ease2 = 1.0f; - bone->scaleIn = 1.0f; - bone->scaleOut = 1.0f; + bone->scale_in_x = 1.0f; + bone->scale_in_y = 1.0f; + bone->scale_out_x = 1.0f; + bone->scale_out_y = 1.0f; return bone; } @@ -137,20 +139,23 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *UNUSED(op)) /* find the active or selected bone */ for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { if (EBONE_VISIBLE(arm, ebone)) { - if (ebone->flag & BONE_TIPSEL || arm->act_edbone == ebone) + if (ebone->flag & BONE_TIPSEL || arm->act_edbone == ebone) { break; + } } } if (ebone == NULL) { for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { if (EBONE_VISIBLE(arm, ebone)) { - if (ebone->flag & BONE_ROOTSEL || arm->act_edbone == ebone) + if (ebone->flag & BONE_ROOTSEL || arm->act_edbone == ebone) { break; + } } } - if (ebone == NULL) + if (ebone == NULL) { return OPERATOR_CANCELLED; + } to_root = 1; } @@ -159,13 +164,15 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *UNUSED(op)) /* we re-use code for mirror editing... */ flipbone = NULL; - if (arm->flag & ARM_MIRROR_EDIT) + if (arm->flag & ARM_MIRROR_EDIT) { flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone); + } for (a = 0; a < 2; a++) { if (a == 1) { - if (flipbone == NULL) + if (flipbone == NULL) { break; + } else { SWAP(EditBone *, flipbone, ebone); } @@ -190,8 +197,9 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *UNUSED(op)) copy_v3_v3(newbone->tail, curs->location); sub_v3_v3v3(newbone->tail, newbone->tail, obedit->obmat[3]); - if (a == 1) + if (a == 1) { newbone->tail[0] = -newbone->tail[0]; + } copy_m3_m4(mat, obedit->obmat); invert_m3_m3(imat, mat); @@ -279,8 +287,9 @@ static EditBone *get_named_editbone(ListBase *edbo, const char *name) if (name) { for (eBone = edbo->first; eBone; eBone = eBone->next) { - if (STREQ(name, eBone->name)) + if (STREQ(name, eBone->name)) { return eBone; + } } } @@ -410,8 +419,9 @@ void updateDuplicateSubtargetObjects(EditBone *dupBone, } } - if (cti->flush_constraint_targets) + if (cti->flush_constraint_targets) { cti->flush_constraint_targets(curcon, &targets, 0); + } } } } @@ -442,8 +452,9 @@ EditBone *duplicateEditBoneObjects( BLI_addtail(editbones, eBone); /* copy the ID property */ - if (curBone->prop) + if (curBone->prop) { eBone->prop = IDP_CopyProperty(curBone->prop); + } /* Lets duplicate the list of constraints that the * current bone has. @@ -478,8 +489,9 @@ static int armature_duplicate_selected_exec(bContext *C, wmOperator *op) const bool do_flip_names = RNA_boolean_get(op->ptr, "do_flip_names"); /* cancel if nothing selected */ - if (CTX_DATA_COUNT(C, selected_bones) == 0) + if (CTX_DATA_COUNT(C, selected_bones) == 0) { return OPERATOR_CANCELLED; + } uint objects_len = 0; Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( @@ -888,8 +900,9 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) if (EBONE_VISIBLE(arm, ebone)) { if (ebone->flag & BONE_ROOTSEL) { if (ebone->parent && (ebone->flag & BONE_CONNECTED)) { - if (ebone->parent->flag & BONE_TIPSEL) + if (ebone->parent->flag & BONE_TIPSEL) { ebone->flag &= ~BONE_ROOTSEL; + } } } } @@ -920,18 +933,21 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone); if (flipbone) { forked_iter = 0; // we extrude 2 different bones - if (flipbone->flag & (BONE_TIPSEL | BONE_ROOTSEL | BONE_SELECTED)) + if (flipbone->flag & (BONE_TIPSEL | BONE_ROOTSEL | BONE_SELECTED)) { /* don't want this bone to be selected... */ flipbone->flag &= ~(BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL); + } } - if ((flipbone == NULL) && (forked_iter)) + if ((flipbone == NULL) && (forked_iter)) { flipbone = ebone; + } } for (a = 0; a < 2; a++) { if (a == 1) { - if (flipbone == NULL) + if (flipbone == NULL) { break; + } else { SWAP(EditBone *, flipbone, ebone); } @@ -948,8 +964,9 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) /* copies it, in case mirrored bone */ newbone->flag = ebone->flag & (BONE_TIPSEL | BONE_RELATIVE_PARENTING); - if (newbone->parent) + if (newbone->parent) { newbone->flag |= BONE_CONNECTED; + } } else { copy_v3_v3(newbone->head, ebone->head); @@ -975,35 +992,41 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) /* Bendy-Bone parameters */ newbone->roll1 = ebone->roll1; newbone->roll2 = ebone->roll2; - newbone->curveInX = ebone->curveInX; - newbone->curveInY = ebone->curveInY; - newbone->curveOutX = ebone->curveOutX; - newbone->curveOutY = ebone->curveOutY; + newbone->curve_in_x = ebone->curve_in_x; + newbone->curve_in_y = ebone->curve_in_y; + newbone->curve_out_x = ebone->curve_out_x; + newbone->curve_out_y = ebone->curve_out_y; newbone->ease1 = ebone->ease1; newbone->ease2 = ebone->ease2; - newbone->scaleIn = ebone->scaleIn; - newbone->scaleOut = ebone->scaleOut; + newbone->scale_in_x = ebone->scale_in_x; + newbone->scale_in_y = ebone->scale_in_y; + newbone->scale_out_x = ebone->scale_out_x; + newbone->scale_out_y = ebone->scale_out_y; BLI_strncpy(newbone->name, ebone->name, sizeof(newbone->name)); if (flipbone && forked_iter) { // only set if mirror edit if (strlen(newbone->name) < (MAXBONENAME - 2)) { - if (a == 0) + if (a == 0) { strcat(newbone->name, "_L"); - else + } + else { strcat(newbone->name, "_R"); + } } } ED_armature_ebone_unique_name(arm->edbo, newbone->name, NULL); /* Add the new bone to the list */ BLI_addtail(arm->edbo, newbone); - if (!first) + if (!first) { first = newbone; + } /* restore ebone if we were flipping */ - if (a == 1 && flipbone) + if (a == 1 && flipbone) { SWAP(EditBone *, flipbone, ebone); + } } } @@ -1073,10 +1096,12 @@ static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op) invert_m4_m4(obedit->imat, obedit->obmat); mul_m4_v3(obedit->imat, curs); - if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) + if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) { copy_m3_m4(obmat, rv3d->viewmat); - else + } + else { unit_m3(obmat); + } copy_m3_m4(viewmat, obedit->obmat); mul_m3_m3m3(totmat, obmat, viewmat); @@ -1089,10 +1114,12 @@ static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op) copy_v3_v3(bone->head, curs); - if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) + if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) { add_v3_v3v3(bone->tail, bone->head, imat[1]); // bone with unit length 1 - else + } + else { add_v3_v3v3(bone->tail, bone->head, imat[2]); // bone with unit length 1, pointing up Z + } /* note, notifier might evolve */ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit); @@ -1136,8 +1163,7 @@ static int armature_subdivide_exec(bContext *C, wmOperator *op) /* loop over all editable bones */ // XXX the old code did this in reverse order though! - CTX_DATA_BEGIN_WITH_ID(C, EditBone *, ebone, selected_editable_bones, bArmature *, arm) - { + CTX_DATA_BEGIN_WITH_ID (C, EditBone *, ebone, selected_editable_bones, bArmature *, arm) { for (i = cuts + 1; i > 1; i--) { /* compute cut ratio first */ float cutratio = 1.0f / (float)i; @@ -1175,8 +1201,9 @@ static int armature_subdivide_exec(bContext *C, wmOperator *op) /* correct parent bones */ for (tbone = arm->edbo->first; tbone; tbone = tbone->next) { - if (tbone->parent == ebone) + if (tbone->parent == ebone) { tbone->parent = newbone; + } } newbone->parent = ebone; } @@ -1207,6 +1234,7 @@ void ARMATURE_OT_subdivide(wmOperatorType *ot) /* Properties */ prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, 1000, "Number of Cuts", "", 1, 10); - /* avoid re-using last var because it can cause _very_ high poly meshes and annoy users (or worse crash) */ + /* Avoid re-using last var because it can cause + * _very_ high poly meshes and annoy users (or worse crash) */ RNA_def_property_flag(prop, PROP_SKIP_SAVE); } diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c index dfcd0bf69f7..c5430e06b6e 100644 --- a/source/blender/editors/armature/armature_edit.c +++ b/source/blender/editors/armature/armature_edit.c @@ -334,8 +334,9 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op) if (EBONE_VISIBLE(arm, ebone) && EBONE_EDITABLE(ebone)) { float cursor_rel[3]; sub_v3_v3v3(cursor_rel, cursor_local, ebone->head); - if (axis_flip) + if (axis_flip) { negate_v3(cursor_rel); + } if (normalize_v3(cursor_rel) != 0.0f) { ebone->roll = ED_armature_ebone_roll_to_vector(ebone, cursor_rel, axis_only); changed = true; @@ -375,8 +376,9 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op) (ebone_other = ebone_other->parent)); if (!is_vec_zero) { - if (axis_flip) + if (axis_flip) { negate_v3(vec); + } if (is_edit) { ebone->roll = ED_armature_ebone_roll_to_vector(ebone, vec, axis_only); @@ -424,16 +426,19 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op) } else { /* Axis */ assert(type <= 5); - if (type < 3) + if (type < 3) { vec[type] = 1.0f; - else + } + else { vec[type - 2] = -1.0f; + } mul_m3_v3(imat, vec); normalize_v3(vec); } - if (axis_flip) + if (axis_flip) { negate_v3(vec); + } for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { if (EBONE_VISIBLE(arm, ebone) && EBONE_EDITABLE(ebone)) { @@ -591,12 +596,14 @@ static void chains_find_tips(ListBase *edbo, ListBase *list) } } - if (stop) + if (stop) { break; + } } /* skip current bone if it is part of an existing chain */ - if (stop) + if (stop) { continue; + } /* is any existing chain part of the chain formed by this bone? */ stop = 0; @@ -609,12 +616,14 @@ static void chains_find_tips(ListBase *edbo, ListBase *list) } } - if (stop) + if (stop) { break; + } } /* current bone has already been added to a chain? */ - if (stop) + if (stop) { continue; + } /* add current bone to a new chain */ ld = MEM_callocN(sizeof(LinkData), "BoneChain"); @@ -688,8 +697,7 @@ static int armature_fill_bones_exec(bContext *C, wmOperator *op) /* loop over all bones, and only consider if visible */ bArmature *arm = NULL; - CTX_DATA_BEGIN_WITH_ID(C, EditBone *, ebone, visible_bones, bArmature *, arm_iter) - { + CTX_DATA_BEGIN_WITH_ID (C, EditBone *, ebone, visible_bones, bArmature *, arm_iter) { bool check = false; if (!(ebone->flag & BONE_CONNECTED) && (ebone->flag & BONE_ROOTSEL)) { fill_add_joint(ebone, 0, &points); @@ -818,17 +826,21 @@ static int armature_fill_bones_exec(bContext *C, wmOperator *op) /* do parenting (will need to set connected flag too) */ if (headtail == 2) { /* ebp tail or head - tail gets priority */ - if (ebp_a->tail_owner) + if (ebp_a->tail_owner) { newbone->parent = ebp_a->tail_owner; - else + } + else { newbone->parent = ebp_a->head_owner; + } } else { /* ebp_b tail or head - tail gets priority */ - if (ebp_b->tail_owner) + if (ebp_b->tail_owner) { newbone->parent = ebp_b->tail_owner; - else + } + else { newbone->parent = ebp_b->head_owner; + } } /* don't set for bone connecting two head points of bones */ @@ -918,17 +930,17 @@ static void bones_merge( newbone->flag = start->flag & (BONE_HINGE | BONE_NO_DEFORM | BONE_NO_SCALE | BONE_NO_CYCLICOFFSET | BONE_NO_LOCAL_LOCATION | BONE_DONE); - /* step 2a: reparent any side chains which may be parented to any bone in the chain of bones to merge - * - potentially several tips for side chains leading to some tree exist... + /* Step 2a: reparent any side chains which may be parented to any bone in the chain + * of bones to merge - potentially several tips for side chains leading to some tree exist. */ for (chain = chains->first; chain; chain = chain->next) { - /* traverse down chain until we hit the bottom or if we run into the tip of the chain of bones we're - * merging (need to stop in this case to avoid corrupting this chain too!) + /* Traverse down chain until we hit the bottom or if we run into the tip of the chain of bones + * we're merging (need to stop in this case to avoid corrupting this chain too!). */ for (ebone = chain->data; (ebone) && (ebone != end); ebone = ebone->parent) { short found = 0; - /* check if this bone is parented to one in the merging chain + /* Check if this bone is parented to one in the merging chain * ! WATCHIT: must only go check until end of checking chain */ for (ebo = end; (ebo) && (ebo != start->parent); ebo = ebo->parent) { @@ -941,14 +953,16 @@ static void bones_merge( } /* carry on to the next tip now */ - if (found) + if (found) { break; + } } } /* step 2b: parent child of end to newbone (child from this chain) */ - if (endchild) + if (endchild) { endchild->parent = newbone; + } /* step 3: delete all bones between and including start and end */ for (ebo = end; ebo; ebo = ebone) { @@ -1007,13 +1021,15 @@ static int armature_merge_exec(bContext *C, wmOperator *op) bend = ebo; bchild = child; } - else + else { bstart = ebo; + } } else { /* chain is broken... merge any continuous segments then clear */ - if (bstart && bend) + if (bstart && bend) { bones_merge(obedit, bstart, bend, bchild, &chains); + } bstart = NULL; bend = NULL; @@ -1022,8 +1038,9 @@ static int armature_merge_exec(bContext *C, wmOperator *op) } /* merge from bstart to bend if something not merged */ - if (bstart && bend) + if (bstart && bend) { bones_merge(obedit, bstart, bend, bchild, &chains); + } /* put back link */ BLI_insertlinkbefore(&chains, nchain, chain); @@ -1138,10 +1155,12 @@ static int armature_switch_direction_exec(bContext *C, wmOperator *UNUSED(op)) * - connected flag is only set if points are coincidental */ ebo->parent = child; - if ((child) && equals_v3v3(ebo->head, child->tail)) + if ((child) && equals_v3v3(ebo->head, child->tail)) { ebo->flag |= BONE_CONNECTED; - else + } + else { ebo->flag &= ~BONE_CONNECTED; + } /* get next bones * - child will become the new parent of next bone @@ -1208,8 +1227,9 @@ static void fix_connected_bone(EditBone *ebone) float diff[3]; if (!(ebone->parent) || !(ebone->flag & BONE_CONNECTED) || - equals_v3v3(ebone->parent->tail, ebone->head)) + equals_v3v3(ebone->parent->tail, ebone->head)) { return; + } /* if the parent has moved we translate child's head and tail accordingly */ sub_v3_v3v3(diff, ebone->parent->tail, ebone->head); @@ -1272,8 +1292,9 @@ static int armature_align_bones_exec(bContext *C, wmOperator *op) * then just use actbone. Useful when doing upper arm to spine. */ actmirb = ED_armature_ebone_get_mirrored(arm->edbo, actbone); - if (actmirb == NULL) + if (actmirb == NULL) { actmirb = actbone; + } } /* if there is only 1 selected bone, we assume that that is the active bone, @@ -1287,8 +1308,9 @@ static int armature_align_bones_exec(bContext *C, wmOperator *op) if (actbone->parent) { bone_align_to_bone(arm->edbo, actbone, actbone->parent); - if ((arm->flag & ARM_MIRROR_EDIT) && (actmirb->parent)) + if ((arm->flag & ARM_MIRROR_EDIT) && (actmirb->parent)) { bone_align_to_bone(arm->edbo, actmirb, actmirb->parent); + } BKE_reportf(op->reports, RPT_INFO, "Aligned bone '%s' to parent", actbone->name); } @@ -1305,10 +1327,12 @@ static int armature_align_bones_exec(bContext *C, wmOperator *op) /* align selected bones to the active one */ CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) { if (ELEM(ebone, actbone, actmirb) == 0) { - if (ebone->flag & BONE_SELECTED) + if (ebone->flag & BONE_SELECTED) { bone_align_to_bone(arm->edbo, ebone, actbone); - else + } + else { bone_align_to_bone(arm->edbo, ebone, actmirb); + } } } CTX_DATA_END; @@ -1402,8 +1426,9 @@ static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op)) bool changed_multi = false; /* cancel if nothing selected */ - if (CTX_DATA_COUNT(C, selected_bones) == 0) + if (CTX_DATA_COUNT(C, selected_bones) == 0) { return OPERATOR_CANCELLED; + } ViewLayer *view_layer = CTX_data_view_layer(C); uint objects_len = 0; @@ -1422,8 +1447,9 @@ static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op)) ebone_next = curBone->next; if (arm->layer & curBone->layer) { if (curBone->flag & BONE_SELECTED) { - if (curBone == arm->act_edbone) + if (curBone == arm->act_edbone) { arm->act_edbone = NULL; + } ED_armature_ebone_remove(arm, curBone); changed = true; } @@ -1644,8 +1670,9 @@ static int armature_hide_exec(bContext *C, wmOperator *op) const int invert = RNA_boolean_get(op->ptr, "unselected") ? BONE_SELECTED : 0; /* cancel if nothing selected */ - if (CTX_DATA_COUNT(C, selected_bones) == 0) + if (CTX_DATA_COUNT(C, selected_bones) == 0) { return OPERATOR_CANCELLED; + } uint objects_len = 0; Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h index 09e4c1acae7..6c2d9fe8f42 100644 --- a/source/blender/editors/armature/armature_intern.h +++ b/source/blender/editors/armature/armature_intern.h @@ -162,10 +162,11 @@ typedef struct tPChanFCurveLink { /** old bbone values (to be restored along with the transform properties) */ float roll1, roll2; /** (NOTE: we haven't renamed these this time, as their names are already long enough) */ - float curveInX, curveInY; - float curveOutX, curveOutY; + float curve_in_x, curve_in_y; + float curve_out_x, curve_out_y; float ease1, ease2; - float scaleIn, scaleOut; + float scale_in_x, scale_in_y; + float scale_out_x, scale_out_y; /** copy of custom properties at start of operator (to be restored before each modal step) */ struct IDProperty *oldprops; @@ -216,8 +217,9 @@ void POSE_OT_propagate(struct wmOperatorType *ot); /* ******************************************************* */ /* Various Armature Edit/Pose Editing API's */ -/* Ideally, many of these defines would not be needed as everything would be strictly self-contained - * within each file, but some tools still have a bit of overlap which makes things messy -- Feb 2013 +/* Ideally, many of these defines would not be needed as everything would be strictly + * self-contained within each file, + * but some tools still have a bit of overlap which makes things messy -- Feb 2013 */ EditBone *make_boneList(struct ListBase *edbo, struct ListBase *bones, struct Bone *actBone); diff --git a/source/blender/editors/armature/armature_naming.c b/source/blender/editors/armature/armature_naming.c index b1f0297bb29..083967d5d41 100644 --- a/source/blender/editors/armature/armature_naming.c +++ b/source/blender/editors/armature/armature_naming.c @@ -130,8 +130,9 @@ static void constraint_bone_name_fix(Object *ob, } } - if (cti->flush_constraint_targets) + if (cti->flush_constraint_targets) { cti->flush_constraint_targets(curcon, &targets, 0); + } } /* action constraints */ @@ -221,8 +222,9 @@ void ED_armature_bone_rename(Main *bmain, /* Update any object constraints to use the new bone name */ for (cob = bmain->objects.first; cob; cob = cob->id.next) { - if (cob->constraints.first) + if (cob->constraints.first) { constraint_bone_name_fix(ob, &cob->constraints, oldname, newname); + } if (cob->pose) { bPoseChannel *pchan; for (pchan = cob->pose->chanbase.first; pchan; pchan = pchan->next) { @@ -236,8 +238,9 @@ void ED_armature_bone_rename(Main *bmain, if (ob->parent && (ob->parent->data == arm)) { if (ob->partype == PARBONE) { /* bone name in object */ - if (STREQ(ob->parsubstr, oldname)) + if (STREQ(ob->parsubstr, oldname)) { BLI_strncpy(ob->parsubstr, newname, MAXBONENAME); + } } } @@ -255,8 +258,9 @@ void ED_armature_bone_rename(Main *bmain, HookModifierData *hmd = (HookModifierData *)md; if (hmd->object && (hmd->object->data == arm)) { - if (STREQ(hmd->subtarget, oldname)) + if (STREQ(hmd->subtarget, oldname)) { BLI_strncpy(hmd->subtarget, newname, MAXBONENAME); + } } break; } @@ -264,12 +268,14 @@ void ED_armature_bone_rename(Main *bmain, UVWarpModifierData *umd = (UVWarpModifierData *)md; if (umd->object_src && (umd->object_src->data == arm)) { - if (STREQ(umd->bone_src, oldname)) + if (STREQ(umd->bone_src, oldname)) { BLI_strncpy(umd->bone_src, newname, MAXBONENAME); + } } if (umd->object_dst && (umd->object_dst->data == arm)) { - if (STREQ(umd->bone_dst, oldname)) + if (STREQ(umd->bone_dst, oldname)) { BLI_strncpy(umd->bone_dst, newname, MAXBONENAME); + } } break; } @@ -284,8 +290,9 @@ void ED_armature_bone_rename(Main *bmain, bGPdata *gpd = (bGPdata *)ob->data; for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { if ((gpl->parent != NULL) && (gpl->parent->data == arm)) { - if (STREQ(gpl->parsubstr, oldname)) + if (STREQ(gpl->parsubstr, oldname)) { BLI_strncpy(gpl->parsubstr, newname, MAXBONENAME); + } } } @@ -305,8 +312,9 @@ void ED_armature_bone_rename(Main *bmain, case eGpencilModifierType_Hook: { HookGpencilModifierData *hgp_md = (HookGpencilModifierData *)gp_md; if (hgp_md->object && (hgp_md->object->data == arm)) { - if (STREQ(hgp_md->subtarget, oldname)) + if (STREQ(hgp_md->subtarget, oldname)) { BLI_strncpy(hgp_md->subtarget, newname, MAXBONENAME); + } } break; } @@ -318,10 +326,12 @@ void ED_armature_bone_rename(Main *bmain, DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); } - /* Fix all animdata that may refer to this bone - we can't just do the ones attached to objects, since - * other ID-blocks may have drivers referring to this bone [#29822] - */ - // XXX: the ID here is for armatures, but most bone drivers are actually on the object instead... + /* Fix all animdata that may refer to this bone - + * we can't just do the ones attached to objects, + * since other ID-blocks may have drivers referring to this bone T29822. */ + + /* XXX: the ID here is for armatures, + * but most bone drivers are actually on the object instead. */ { BKE_animdata_fix_paths_rename_all(&arm->id, "pose.bones", oldname, newname); @@ -376,8 +386,8 @@ void ED_armature_bones_flip_names(Main *bmain, BoneFlipNameData *bfn; /* First pass: generate flip names, and blindly rename. - * If rename did not yield expected result, store both bone's name and expected flipped one into temp list - * for second pass. */ + * If rename did not yield expected result, + * store both bone's name and expected flipped one into temp list for second pass. */ for (LinkData *link = bones_names->first; link; link = link->next) { char name_flip[MAXBONENAME]; char *name = link->data; @@ -397,8 +407,9 @@ void ED_armature_bones_flip_names(Main *bmain, } /* Second pass to handle the bones that have naming conflicts with other bones. - * Note that if the other bone was not selected, its name was not flipped, so conflict remains and that second - * rename simply generates a new numbered alternative name. */ + * Note that if the other bone was not selected, its name was not flipped, + * so conflict remains and that second rename simply generates a new numbered alternative name. + */ for (bfn = bones_names_conflicts.first; bfn; bfn = bfn->next) { ED_armature_bone_rename(bmain, arm, bfn->name, bfn->name_flip); } diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c index c820077fbf9..b53ae813f10 100644 --- a/source/blender/editors/armature/armature_ops.c +++ b/source/blender/editors/armature/armature_ops.c @@ -161,7 +161,7 @@ void ED_operatormacros_armature(void) OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "ARMATURE_OT_duplicate"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); ot = WM_operatortype_append_macro("ARMATURE_OT_extrude_move", "Extrude", @@ -170,10 +170,11 @@ void ED_operatormacros_armature(void) otmacro = WM_operatortype_macro_define(ot, "ARMATURE_OT_extrude"); RNA_boolean_set(otmacro->ptr, "forked", false); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); - /* XXX would it be nicer to just be able to have standard extrude_move, but set the forked property separate? - * that would require fixing a properties bug 19733 */ + /* XXX would it be nicer to just be able to have standard extrude_move, + * but set the forked property separate? + * that would require fixing a properties bug T19733. */ ot = WM_operatortype_append_macro("ARMATURE_OT_extrude_forked", "Extrude Forked", "Create new bones from the selected joints and move them", @@ -181,7 +182,7 @@ void ED_operatormacros_armature(void) otmacro = WM_operatortype_macro_define(ot, "ARMATURE_OT_extrude"); RNA_boolean_set(otmacro->ptr, "forked", true); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); } void ED_keymap_armature(wmKeyConfig *keyconf) diff --git a/source/blender/editors/armature/armature_relations.c b/source/blender/editors/armature/armature_relations.c index 6226059e794..b2ca1d84520 100644 --- a/source/blender/editors/armature/armature_relations.c +++ b/source/blender/editors/armature/armature_relations.c @@ -92,8 +92,9 @@ static void joined_armature_fix_links_constraints( } } - if (cti->flush_constraint_targets) + if (cti->flush_constraint_targets) { cti->flush_constraint_targets(con, &targets, 0); + } } /* action constraint? (pose constraints only) */ @@ -116,9 +117,10 @@ typedef struct tJoinArmature_AdtFixData { GHash *names_map; } tJoinArmature_AdtFixData; -/* Callback to pass to BKE_animdata_main_cb() for fixing driver ID's to point to the new ID */ -/* FIXME: For now, we only care about drivers here. When editing rigs, it's very rare to have animation - * on the rigs being edited already, so it should be safe to skip these. +/* Callback to pass to BKE_animdata_main_cb() for fixing driver ID's to point to the new ID. */ +/* FIXME: For now, we only care about drivers here. + * When editing rigs, it's very rare to have animation on the rigs being edited already, + * so it should be safe to skip these. */ static void joined_armature_fix_animdata_cb(ID *id, FCurve *fcu, void *user_data) { @@ -247,10 +249,12 @@ int join_armature_exec(bContext *C, wmOperator *op) bool ok = false; /* Ensure we're not in editmode and that the active object is an armature*/ - if (!ob_active || ob_active->type != OB_ARMATURE) + if (!ob_active || ob_active->type != OB_ARMATURE) { return OPERATOR_CANCELLED; - if (!arm || arm->edbo) + } + if (!arm || arm->edbo) { return OPERATOR_CANCELLED; + } CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) { if (ob_iter == ob_active) { @@ -292,7 +296,7 @@ int join_armature_exec(bContext *C, wmOperator *op) /* Get Pose of current armature */ opose = ob_iter->pose; ob_iter->mode &= ~OB_MODE_POSE; - //BASACT->flag &= ~OB_MODE_POSE; + // BASACT->flag &= ~OB_MODE_POSE; /* Find the difference matrix */ invert_m4_m4(oimat, ob_active->obmat); @@ -428,9 +432,10 @@ static void separated_armature_fix_links(Main *bmain, Object *origArm, Object *n cti->get_constraint_targets(con, &targets); for (ct = targets.first; ct; ct = ct->next) { - /* any targets which point to original armature are redirected to the new one only if: - * - the target isn't origArm/newArm itself - * - the target is one that can be found in newArm/origArm + /* Any targets which point to original armature + * are redirected to the new one only if: + * - The target isn't origArm/newArm itself. + * - The target is one that can be found in newArm/origArm. */ if (ct->subtarget[0] != 0) { if (ct->tar == origArm) { @@ -591,12 +596,13 @@ static int separate_armature_exec(bContext *C, wmOperator *op) Object *oldob, *newob; Base *oldbase, *newbase; - /* we are going to do this as follows (unlike every other instance of separate): - * 1. exit editmode +posemode for active armature/base. Take note of what this is. - * 2. duplicate base - BASACT is the new one now - * 3. for each of the two armatures, enter editmode -> remove appropriate bones -> exit editmode + recalc - * 4. fix constraint links - * 5. make original armature active and enter editmode + /* We are going to do this as follows (unlike every other instance of separate): + * 1. Exit editmode +posemode for active armature/base. Take note of what this is. + * 2. Duplicate base - BASACT is the new one now + * 3. For each of the two armatures, + * enter editmode -> remove appropriate bones -> exit editmode + recalc. + * 4. Fix constraint links + * 5. Make original armature active and enter editmode */ /* 1) only edit-base selected */ @@ -606,7 +612,7 @@ static int separate_armature_exec(bContext *C, wmOperator *op) oldob = obedit; oldbase = base_iter; oldob->mode &= ~OB_MODE_POSE; - //oldbase->flag &= ~OB_POSEMODE; + // oldbase->flag &= ~OB_POSEMODE; ED_armature_from_edit(bmain, obedit->data); ED_armature_edit_free(obedit->data); @@ -672,7 +678,7 @@ void ARMATURE_OT_separate(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } -/* ******************************************** Parenting ************************************************* */ +/* ********************************* Parenting ************************************************* */ /* armature parenting options */ #define ARM_PAR_CONNECT 1 @@ -694,8 +700,9 @@ static void bone_connect_to_new_parent(ListBase *edbo, EditBone *ebone; float offset[3]; - if ((selbone->parent) && (selbone->flag & BONE_CONNECTED)) + if ((selbone->parent) && (selbone->flag & BONE_CONNECTED)) { selbone->parent->flag &= ~(BONE_TIPSEL); + } /* make actbone the parent of selbone */ selbone->parent = actbone; @@ -757,51 +764,72 @@ static int armature_parent_set_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } else if (arm->flag & ARM_MIRROR_EDIT) { - /* For X-Axis Mirror Editing option, we may need a mirror copy of actbone - * - if there's a mirrored copy of selbone, try to find a mirrored copy of actbone + /* For X-Axis Mirror Editing option, we may need a mirror copy of actbone: + * - If there's a mirrored copy of selbone, try to find a mirrored copy of actbone * (i.e. selbone="child.L" and actbone="parent.L", find "child.R" and "parent.R"). - * This is useful for arm-chains, for example parenting lower arm to upper arm - * - if there's no mirrored copy of actbone (i.e. actbone = "parent.C" or "parent") + * This is useful for arm-chains, for example parenting lower arm to upper arm. + * - If there's no mirrored copy of actbone (i.e. actbone = "parent.C" or "parent") * then just use actbone. Useful when doing upper arm to spine. */ actmirb = ED_armature_ebone_get_mirrored(arm->edbo, actbone); - if (actmirb == NULL) + if (actmirb == NULL) { actmirb = actbone; + } } - /* if there is only 1 selected bone, we assume that that is the active bone, - * since a user will need to have clicked on a bone (thus selecting it) to make it active - */ - if (CTX_DATA_COUNT(C, selected_editable_bones) <= 1) { + /* If there is only 1 selected bone, we assume that that is the active bone, + * since a user will need to have clicked on a bone (thus selecting it) to make it active. */ + bool is_active_only_selected = false; + if (actbone->flag & BONE_SELECTED) { + is_active_only_selected = true; + for (EditBone *ebone = arm->edbo->first; ebone; ebone = ebone->next) { + if (EBONE_EDITABLE(ebone) && (ebone->flag & BONE_SELECTED)) { + if (ebone != actbone) { + is_active_only_selected = false; + break; + } + } + } + } + + if (is_active_only_selected) { /* When only the active bone is selected, and it has a parent, * connect it to the parent, as that is the only possible outcome. */ if (actbone->parent) { bone_connect_to_existing_parent(actbone); - if ((arm->flag & ARM_MIRROR_EDIT) && (actmirb->parent)) + if ((arm->flag & ARM_MIRROR_EDIT) && (actmirb->parent)) { bone_connect_to_existing_parent(actmirb); + } } } else { - /* Parent 'selected' bones to the active one - * - the context iterator contains both selected bones and their mirrored copies, - * so we assume that unselected bones are mirrored copies of some selected bone - * - since the active one (and/or its mirror) will also be selected, we also need + /* Parent 'selected' bones to the active one: + * - The context iterator contains both selected bones and their mirrored copies, + * so we assume that unselected bones are mirrored copies of some selected bone. + * - Since the active one (and/or its mirror) will also be selected, we also need * to check that we are not trying to operate on them, since such an operation - * would cause errors + * would cause errors. */ - /* parent selected bones to the active one */ - CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) { - if (ELEM(ebone, actbone, actmirb) == 0) { - if (ebone->flag & BONE_SELECTED) + /* Parent selected bones to the active one. */ + for (EditBone *ebone = arm->edbo->first; ebone; ebone = ebone->next) { + if (EBONE_EDITABLE(ebone) && (ebone->flag & BONE_SELECTED)) { + if (ebone != actbone) { bone_connect_to_new_parent(arm->edbo, ebone, actbone, val); - else - bone_connect_to_new_parent(arm->edbo, ebone, actmirb, val); + } + + if (arm->flag & ARM_MIRROR_EDIT) { + EditBone *ebone_mirror = ED_armature_ebone_get_mirrored(arm->edbo, ebone); + if (ebone_mirror && (ebone_mirror->flag & BONE_SELECTED) == 0) { + if (ebone_mirror != actmirb) { + bone_connect_to_new_parent(arm->edbo, ebone_mirror, actmirb, val); + } + } + } } } - CTX_DATA_END; } /* note, notifier might evolve */ @@ -814,25 +842,31 @@ static int armature_parent_set_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event)) { - EditBone *actbone = CTX_data_active_bone(C); - uiPopupMenu *pup = UI_popup_menu_begin( - C, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Make Parent"), ICON_NONE); - uiLayout *layout = UI_popup_menu_layout(pup); - int allchildbones = 0; - - CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) { - if (ebone != actbone) { - if (ebone->parent != actbone) - allchildbones = 1; + bool all_childbones = false; + { + Object *ob = CTX_data_edit_object(C); + bArmature *arm = ob->data; + EditBone *actbone = arm->act_edbone; + for (EditBone *ebone = arm->edbo->first; ebone; ebone = ebone->next) { + if (EBONE_EDITABLE(ebone) && (ebone->flag & BONE_SELECTED)) { + if (ebone != actbone) { + if (ebone->parent != actbone) { + all_childbones = true; + break; + } + } + } } } - CTX_DATA_END; + uiPopupMenu *pup = UI_popup_menu_begin( + C, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Make Parent"), ICON_NONE); + uiLayout *layout = UI_popup_menu_layout(pup); uiItemEnumO(layout, "ARMATURE_OT_parent_set", NULL, 0, "type", ARM_PAR_CONNECT); - - /* ob becomes parent, make the associated menus */ - if (allchildbones) + if (all_childbones) { + /* Object becomes parent, make the associated menus. */ uiItemEnumO(layout, "ARMATURE_OT_parent_set", NULL, 0, "type", ARM_PAR_OFFSET); + } UI_popup_menu_end(C, pup); @@ -871,8 +905,9 @@ static void editbone_clear_parent(EditBone *ebone, int mode) ebone->parent->flag &= ~(BONE_TIPSEL); } - if (mode == 1) + if (mode == 1) { ebone->parent = NULL; + } ebone->flag &= ~BONE_CONNECTED; } diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c index 0c493672d9e..fbbb68d2003 100644 --- a/source/blender/editors/armature/armature_select.c +++ b/source/blender/editors/armature/armature_select.c @@ -167,10 +167,12 @@ void *get_bone_from_selectbuffer(Base **bases, if (is_editmode == false) { base = ED_armature_base_and_bone_from_select_buffer(bases, bases_len, hitresult, &bone); if (bone != NULL) { - if (findunsel) + if (findunsel) { sel = (bone->flag & BONE_SELECTED); - else + } + else { sel = !(bone->flag & BONE_SELECTED); + } data = bone; } @@ -182,10 +184,12 @@ void *get_bone_from_selectbuffer(Base **bases, else { base = ED_armature_base_and_ebone_from_select_buffer( bases, bases_len, hitresult, &ebone); - if (findunsel) + if (findunsel) { sel = (ebone->flag & BONE_SELECTED); - else + } + else { sel = !(ebone->flag & BONE_SELECTED); + } data = ebone; } @@ -300,8 +304,9 @@ static int armature_select_linked_invoke(bContext *C, wmOperator *op, const wmEv Base *base = NULL; bone = get_nearest_bone(C, event->mval, true, &base); - if (!bone) + if (!bone) { return OPERATOR_CANCELLED; + } arm = base->object->data; @@ -316,10 +321,12 @@ static int armature_select_linked_invoke(bContext *C, wmOperator *op, const wmEv } } - if (curBone->flag & BONE_CONNECTED) + if (curBone->flag & BONE_CONNECTED) { next = curBone->parent; - else + } + else { next = NULL; + } } /* Select children */ @@ -343,8 +350,9 @@ static int armature_select_linked_invoke(bContext *C, wmOperator *op, const wmEv } } } - if (!curBone) + if (!curBone) { bone = NULL; + } } ED_armature_edit_sync_selection(arm->edbo); @@ -515,12 +523,15 @@ cache_end: if (hitresult & (BONESEL_ROOT | BONESEL_TIP)) { /* but also the unselected one */ if (findunsel) { - if ((hitresult & BONESEL_ROOT) && (ebone->flag & BONE_ROOTSEL) == 0) + if ((hitresult & BONESEL_ROOT) && (ebone->flag & BONE_ROOTSEL) == 0) { dep = 1; - else if ((hitresult & BONESEL_TIP) && (ebone->flag & BONE_TIPSEL) == 0) + } + else if ((hitresult & BONESEL_TIP) && (ebone->flag & BONE_TIPSEL) == 0) { dep = 1; - else + } + else { dep = 2; + } } else { dep = 1; @@ -529,10 +540,12 @@ cache_end: else { /* bone found */ if (findunsel) { - if ((ebone->flag & BONE_SELECTED) == 0) + if ((ebone->flag & BONE_SELECTED) == 0) { dep = 3; - else + } + else { dep = 4; + } } else { dep = 3; @@ -698,8 +711,9 @@ bool ED_armature_edit_select_pick( /* deselect this bone */ nearBone->flag &= ~(BONE_TIPSEL | BONE_SELECTED); /* only deselect parent tip if it is not selected */ - if (!(nearBone->parent->flag & BONE_SELECTED)) + if (!(nearBone->parent->flag & BONE_SELECTED)) { nearBone->parent->flag &= ~BONE_TIPSEL; + } } else if (toggle) { /* hold shift inverts this bone's selection */ @@ -707,8 +721,9 @@ bool ED_armature_edit_select_pick( /* deselect this bone */ nearBone->flag &= ~(BONE_TIPSEL | BONE_SELECTED); /* only deselect parent tip if it is not selected */ - if (!(nearBone->parent->flag & BONE_SELECTED)) + if (!(nearBone->parent->flag & BONE_SELECTED)) { nearBone->parent->flag &= ~BONE_TIPSEL; + } } else { /* select this bone */ @@ -731,24 +746,31 @@ bool ED_armature_edit_select_pick( } else if (toggle) { /* hold shift inverts this bone's selection */ - if (nearBone->flag & BONE_SELECTED) + if (nearBone->flag & BONE_SELECTED) { nearBone->flag &= ~(BONE_TIPSEL | BONE_ROOTSEL); - else + } + else { nearBone->flag |= (BONE_TIPSEL | BONE_ROOTSEL); + } } - else + else { nearBone->flag |= (BONE_TIPSEL | BONE_ROOTSEL); + } } } else { - if (extend) + if (extend) { nearBone->flag |= selmask; - else if (deselect) + } + else if (deselect) { nearBone->flag &= ~selmask; - else if (toggle && (nearBone->flag & selmask)) + } + else if (toggle && (nearBone->flag & selmask)) { nearBone->flag &= ~selmask; - else + } + else { nearBone->flag |= selmask; + } } ED_armature_edit_sync_selection(arm->edbo); @@ -845,8 +867,8 @@ static bool armature_edit_select_op_apply(bArmature *arm, } /** - * Perform a selection operation on elements which have been 'touched', use for lasso & border select - * but can be used elsewhere too. + * Perform a selection operation on elements which have been 'touched', + * use for lasso & border select but can be used elsewhere too. * * Tagging is done via #EditBone.temp.i using: #BONESEL_ROOT, #BONESEL_TIP, #BONESEL_BONE * And optionally ignoring end-points using the #BONESEL_ROOT, #BONESEL_TIP right shifted 16 bits. @@ -1373,8 +1395,9 @@ static void select_similar_suffix(bContext *C) BLI_string_split_suffix(ebone_act->name, body_tmp, suffix_act, sizeof(ebone_act->name)); - if (suffix_act[0] == '\0') + if (suffix_act[0] == '\0') { return; + } uint objects_len = 0; Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( @@ -1429,11 +1452,13 @@ static void select_similar_data_pchan(bContext *C, const size_t bytes_size, cons static void is_ancestor(EditBone *bone, EditBone *ancestor) { - if (bone->temp.ebone == ancestor || bone->temp.ebone == NULL) + if (bone->temp.ebone == ancestor || bone->temp.ebone == NULL) { return; + } - if (bone->temp.ebone->temp.ebone != NULL && bone->temp.ebone->temp.ebone != ancestor) + if (bone->temp.ebone->temp.ebone != NULL && bone->temp.ebone->temp.ebone != ancestor) { is_ancestor(bone->temp.ebone, ancestor); + } bone->temp.ebone = bone->temp.ebone->temp.ebone; } @@ -1451,8 +1476,9 @@ static void select_similar_children(bContext *C) for (EditBone *ebone_iter = arm->edbo->first; ebone_iter; ebone_iter = ebone_iter->next) { is_ancestor(ebone_iter, ebone_act); - if (ebone_iter->temp.ebone == ebone_act && EBONE_SELECTABLE(arm, ebone_iter)) + if (ebone_iter->temp.ebone == ebone_act && EBONE_SELECTABLE(arm, ebone_iter)) { ED_armature_ebone_select_set(ebone_iter, true); + } } WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit); @@ -1757,8 +1783,9 @@ static bool armature_shortest_path_select( { do { - if (!use_parent && (ebone_child == ebone_parent)) + if (!use_parent && (ebone_child == ebone_parent)) { break; + } if (is_test) { if (!EBONE_SELECTABLE(arm, ebone_child)) { @@ -1769,8 +1796,9 @@ static bool armature_shortest_path_select( ED_armature_ebone_selectflag_set(ebone_child, (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL)); } - if (ebone_child == ebone_parent) + if (ebone_child == ebone_parent) { break; + } ebone_child = ebone_child->parent; } while (true); diff --git a/source/blender/editors/armature/armature_skinning.c b/source/blender/editors/armature/armature_skinning.c index afbeb8e4377..08de699a70b 100644 --- a/source/blender/editors/armature/armature_skinning.c +++ b/source/blender/editors/armature/armature_skinning.c @@ -55,7 +55,7 @@ #include "armature_intern.h" #include "meshlaplacian.h" -/* ********************************** Bone Skinning *********************************************** */ +/* ******************************* Bone Skinning *********************************************** */ static int bone_skinnable_cb(Object *UNUSED(ob), Bone *bone, void *datap) { @@ -93,10 +93,12 @@ static int bone_skinnable_cb(Object *UNUSED(ob), Bone *bone, void *datap) if (!(data->is_weight_paint) || !(bone->flag & BONE_HIDDEN_P)) { if (!(bone->flag & BONE_NO_DEFORM)) { if (data->heat && data->armob->pose && - BKE_pose_channel_find_name(data->armob->pose, bone->name)) + BKE_pose_channel_find_name(data->armob->pose, bone->name)) { segments = bone->segments; - else + } + else { segments = 1; + } if (data->list != NULL) { hbone = (Bone ***)&data->list; @@ -165,10 +167,12 @@ static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap) if (!data->is_weight_paint || !(bone->flag & BONE_HIDDEN_P)) { if (!(bone->flag & BONE_NO_DEFORM)) { if (data->heat && data->armob->pose && - BKE_pose_channel_find_name(data->armob->pose, bone->name)) + BKE_pose_channel_find_name(data->armob->pose, bone->name)) { segments = bone->segments; - else + } + else { segments = 1; + } if (!data->is_weight_paint || ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED))) { if (!(defgroup = defgroup_find_name(ob, bone->name))) { @@ -231,8 +235,9 @@ static void envelope_bone_weighting(Object *ob, /* for each skinnable bone */ for (j = 0; j < numbones; ++j) { - if (!selected[j]) + if (!selected[j]) { continue; + } bone = bonelist[j]; dgroup = dgrouplist[j]; @@ -246,17 +251,21 @@ static void envelope_bone_weighting(Object *ob, bone->dist * scale); /* add the vert to the deform group if (weight != 0.0) */ - if (distance != 0.0f) + if (distance != 0.0f) { ED_vgroup_vert_add(ob, dgroup, i, distance, WEIGHT_REPLACE); - else + } + else { ED_vgroup_vert_remove(ob, dgroup, i); + } /* do same for mirror */ if (dgroupflip && dgroupflip[j] && iflip != -1) { - if (distance != 0.0f) + if (distance != 0.0f) { ED_vgroup_vert_add(ob, dgroupflip[j], iflip, distance, WEIGHT_REPLACE); - else + } + else { ED_vgroup_vert_remove(ob, dgroupflip[j], iflip); + } } } } @@ -308,11 +317,13 @@ static void add_verts_to_dgroups(ReportList *reports, /* count the number of skinnable bones */ numbones = bone_looper(ob, arm->bonebase.first, &looper_data, bone_skinnable_cb); - if (numbones == 0) + if (numbones == 0) { return; + } - if (BKE_object_defgroup_data_create(ob->data) == NULL) + if (BKE_object_defgroup_data_create(ob->data) == NULL) { return; + } /* create an array of pointer to bones that are skinnable * and fill it with all of the skinnable bones */ @@ -377,11 +388,13 @@ static void add_verts_to_dgroups(ReportList *reports, /* set selected */ if (wpmode) { - if ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED)) + if ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED)) { selected[j] = 1; + } } - else + else { selected[j] = 1; + } /* find flipped group */ if (dgroup && mirror) { @@ -415,8 +428,9 @@ static void add_verts_to_dgroups(ReportList *reports, /* transform verts to global space */ for (i = 0; i < mesh->totvert; i++) { - if (!vertsfilled) + if (!vertsfilled) { copy_v3_v3(verts[i], mesh->mvert[i].co); + } mul_m4_v3(ob->obmat, verts[i]); } diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c index 50289197ed4..b23081cd6fa 100644 --- a/source/blender/editors/armature/armature_utils.c +++ b/source/blender/editors/armature/armature_utils.c @@ -56,16 +56,20 @@ void ED_armature_edit_sync_selection(ListBase *edbo) /* if bone is not selectable, we shouldn't alter this setting... */ if ((ebo->flag & BONE_UNSELECTABLE) == 0) { if ((ebo->flag & BONE_CONNECTED) && (ebo->parent)) { - if (ebo->parent->flag & BONE_TIPSEL) + if (ebo->parent->flag & BONE_TIPSEL) { ebo->flag |= BONE_ROOTSEL; - else + } + else { ebo->flag &= ~BONE_ROOTSEL; + } } - if ((ebo->flag & BONE_TIPSEL) && (ebo->flag & BONE_ROOTSEL)) + if ((ebo->flag & BONE_TIPSEL) && (ebo->flag & BONE_ROOTSEL)) { ebo->flag |= BONE_SELECTED; - else + } + else { ebo->flag &= ~BONE_SELECTED; + } } } } @@ -75,8 +79,9 @@ void ED_armature_edit_validate_active(struct bArmature *arm) EditBone *ebone = arm->act_edbone; if (ebone) { - if (ebone->flag & BONE_HIDDEN_A) + if (ebone->flag & BONE_HIDDEN_A) { arm->act_edbone = NULL; + } } } @@ -116,8 +121,9 @@ int bone_looper(Object *ob, Bone *bone, void *data, int (*bone_func)(Object *, B void bone_free(bArmature *arm, EditBone *bone) { - if (arm->act_edbone == bone) + if (arm->act_edbone == bone) { arm->act_edbone = NULL; + } if (bone->prop) { IDP_FreeProperty(bone->prop); @@ -165,8 +171,9 @@ void ED_armature_ebone_remove(bArmature *arm, EditBone *exBone) bool ED_armature_ebone_is_child_recursive(EditBone *ebone_parent, EditBone *ebone_child) { for (ebone_child = ebone_child->parent; ebone_child; ebone_child = ebone_child->parent) { - if (ebone_child == ebone_parent) + if (ebone_child == ebone_parent) { return true; + } } return false; } @@ -274,8 +281,9 @@ EditBone *ED_armature_ebone_get_mirrored(const ListBase *edbo, EditBone *ebo) { char name_flip[MAXBONENAME]; - if (ebo == NULL) + if (ebo == NULL) { return NULL; + } BLI_string_flip_side_name(name_flip, ebo->name, false, sizeof(name_flip)); @@ -301,8 +309,9 @@ void armature_select_mirrored_ex(bArmature *arm, const int flag) if (arm->layer & curBone->layer) { if (curBone->flag & flag) { ebone_mirr = ED_armature_ebone_get_mirrored(arm->edbo, curBone); - if (ebone_mirr) + if (ebone_mirr) { ebone_mirr->flag |= (curBone->flag & flag); + } } } } @@ -381,7 +390,7 @@ void ED_armature_edit_transform_mirror_update(Object *obedit) eboflip->tail[2] = ebo->tail[2]; eboflip->rad_tail = ebo->rad_tail; eboflip->roll = -ebo->roll; - eboflip->curveOutX = -ebo->curveOutX; + eboflip->curve_out_x = -ebo->curve_out_x; eboflip->roll2 = -ebo->roll2; /* Also move connected children, in case children's name aren't mirrored properly */ @@ -398,7 +407,7 @@ void ED_armature_edit_transform_mirror_update(Object *obedit) eboflip->head[2] = ebo->head[2]; eboflip->rad_head = ebo->rad_head; eboflip->roll = -ebo->roll; - eboflip->curveInX = -ebo->curveInX; + eboflip->curve_in_x = -ebo->curve_in_x; eboflip->roll1 = -ebo->roll1; /* Also move connected parent, in case parent's name isn't mirrored properly */ @@ -414,8 +423,8 @@ void ED_armature_edit_transform_mirror_update(Object *obedit) eboflip->xwidth = ebo->xwidth; eboflip->zwidth = ebo->zwidth; - eboflip->curveInX = -ebo->curveInX; - eboflip->curveOutX = -ebo->curveOutX; + eboflip->curve_in_x = -ebo->curve_in_x; + eboflip->curve_out_x = -ebo->curve_out_x; eboflip->roll1 = -ebo->roll1; eboflip->roll2 = -ebo->roll2; } @@ -457,8 +466,8 @@ static EditBone *make_boneList_rec(ListBase *edbo, eBone->parent->flag |= BONE_TIPSEL; } - /* For connected bones, take care when changing the selection when we have a connected parent, - * this flag is a copy of '(eBone->parent->flag & BONE_TIPSEL)'. */ + /* For connected bones, take care when changing the selection when we have a + * connected parent, this flag is a copy of '(eBone->parent->flag & BONE_TIPSEL)'. */ eBone->flag |= BONE_ROOTSEL; } else { @@ -487,32 +496,37 @@ static EditBone *make_boneList_rec(ListBase *edbo, /* Bendy-Bone parameters */ eBone->roll1 = curBone->roll1; eBone->roll2 = curBone->roll2; - eBone->curveInX = curBone->curveInX; - eBone->curveInY = curBone->curveInY; - eBone->curveOutX = curBone->curveOutX; - eBone->curveOutY = curBone->curveOutY; + eBone->curve_in_x = curBone->curve_in_x; + eBone->curve_in_y = curBone->curve_in_y; + eBone->curve_out_x = curBone->curve_out_x; + eBone->curve_out_y = curBone->curve_out_y; eBone->ease1 = curBone->ease1; eBone->ease2 = curBone->ease2; - eBone->scaleIn = curBone->scaleIn; - eBone->scaleOut = curBone->scaleOut; + eBone->scale_in_x = curBone->scale_in_x; + eBone->scale_in_y = curBone->scale_in_y; + eBone->scale_out_x = curBone->scale_out_x; + eBone->scale_out_y = curBone->scale_out_y; eBone->bbone_prev_type = curBone->bbone_prev_type; eBone->bbone_next_type = curBone->bbone_next_type; - if (curBone->prop) + if (curBone->prop) { eBone->prop = IDP_CopyProperty(curBone->prop); + } BLI_addtail(edbo, eBone); /* Add children if necessary */ if (curBone->childbase.first) { eBoneTest = make_boneList_rec(edbo, &curBone->childbase, eBone, actBone); - if (eBoneTest) + if (eBoneTest) { eBoneAct = eBoneTest; + } } - if (curBone == actBone) + if (curBone == actBone) { eBoneAct = eBone; + } } return eBoneAct; @@ -551,9 +565,11 @@ EditBone *make_boneList(ListBase *edbo, ListBase *bones, struct Bone *actBone) /** * This function: * - Sets local head/tail rest locations using parent bone's arm_mat. - * - Calls #BKE_armature_where_is_bone() which uses parent's transform (arm_mat) to define this bone's transform. + * - Calls #BKE_armature_where_is_bone() which uses parent's transform (arm_mat) + * to define this bone's transform. * - Fixes (converts) EditBone roll into Bone roll. - * - Calls again #BKE_armature_where_is_bone(), since roll fiddling may have changed things for our bone... + * - Calls again #BKE_armature_where_is_bone(), + * since roll fiddling may have changed things for our bone. * * \note The order is crucial here, we can only handle child * if all its parents in chain have already been handled (this is ensured by recursive process). @@ -565,8 +581,8 @@ static void armature_finalize_restpose(ListBase *bonelist, ListBase *editbonelis for (curBone = bonelist->first; curBone; curBone = curBone->next) { /* Set bone's local head/tail. - * Note that it's important to use final parent's restpose (arm_mat) here, instead of setting those values - * from editbone's matrix (see T46010). */ + * Note that it's important to use final parent's restpose (arm_mat) here, + * instead of setting those values from editbone's matrix (see T46010). */ if (curBone->parent) { float parmat_inv[4][4]; @@ -610,7 +626,7 @@ static void armature_finalize_restpose(ListBase *bonelist, ListBase *editbonelis print_m4("premat", premat); print_m4("postmat", postmat); print_m4("difmat", difmat); - printf("Roll = %f\n", RAD2DEGF(-atan2(difmat[2][0], difmat[2][2]))); + printf("Roll = %f\n", RAD2DEGF(-atan2(difmat[2][0], difmat[2][2]))); #endif curBone->roll = -atan2f(difmat[2][0], difmat[2][2]); @@ -646,11 +662,13 @@ void ED_armature_from_edit(Main *bmain, bArmature *arm) /* Find any bones that refer to this bone */ for (fBone = arm->edbo->first; fBone; fBone = fBone->next) { - if (fBone->parent == eBone) + if (fBone->parent == eBone) { fBone->parent = eBone->parent; + } } - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Warning: removed zero sized bone: %s\n", eBone->name); + } bone_free(arm, eBone); } } @@ -690,20 +708,23 @@ void ED_armature_from_edit(Main *bmain, bArmature *arm) /* Bendy-Bone parameters */ newBone->roll1 = eBone->roll1; newBone->roll2 = eBone->roll2; - newBone->curveInX = eBone->curveInX; - newBone->curveInY = eBone->curveInY; - newBone->curveOutX = eBone->curveOutX; - newBone->curveOutY = eBone->curveOutY; + newBone->curve_in_x = eBone->curve_in_x; + newBone->curve_in_y = eBone->curve_in_y; + newBone->curve_out_x = eBone->curve_out_x; + newBone->curve_out_y = eBone->curve_out_y; newBone->ease1 = eBone->ease1; newBone->ease2 = eBone->ease2; - newBone->scaleIn = eBone->scaleIn; - newBone->scaleOut = eBone->scaleOut; + newBone->scale_in_x = eBone->scale_in_x; + newBone->scale_in_y = eBone->scale_in_y; + newBone->scale_out_x = eBone->scale_out_x; + newBone->scale_out_y = eBone->scale_out_y; newBone->bbone_prev_type = eBone->bbone_prev_type; newBone->bbone_next_type = eBone->bbone_next_type; - if (eBone->prop) + if (eBone->prop) { newBone->prop = IDP_CopyProperty(eBone->prop); + } } /* Fix parenting in a separate pass to ensure ebone->bone connections are valid at this point. diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index febe2a49174..81030c7f199 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -122,10 +122,12 @@ static void laplacian_increase_edge_count(EdgeHash *edgehash, int v1, int v2) { void **p; - if (BLI_edgehash_ensure_p(edgehash, v1, v2, &p)) + if (BLI_edgehash_ensure_p(edgehash, v1, v2, &p)) { *p = (void *)((intptr_t)*p + (intptr_t)1); - else + } + else { *p = (void *)((intptr_t)1); + } } static int laplacian_edge_count(EdgeHash *edgehash, int v1, int v2) @@ -147,12 +149,15 @@ static void laplacian_triangle_area(LaplacianSystem *sys, int i1, int i2, int i3 t2 = cotangent_tri_weight_v3(v2, v3, v1); t3 = cotangent_tri_weight_v3(v3, v1, v2); - if (angle_v3v3v3(v2, v1, v3) > DEG2RADF(90.0f)) + if (angle_v3v3v3(v2, v1, v3) > DEG2RADF(90.0f)) { obtuse = 1; - else if (angle_v3v3v3(v1, v2, v3) > DEG2RADF(90.0f)) + } + else if (angle_v3v3v3(v1, v2, v3) > DEG2RADF(90.0f)) { obtuse = 2; - else if (angle_v3v3v3(v1, v3, v2) > DEG2RADF(90.0f)) + } + else if (angle_v3v3v3(v1, v3, v2) > DEG2RADF(90.0f)) { obtuse = 3; + } if (obtuse > 0) { area = area_tri_v3(v1, v2, v3); @@ -228,10 +233,12 @@ static LaplacianSystem *laplacian_system_construct_begin(int totvert, int totfac sys->storeweights = 0; /* create linear solver */ - if (lsq) + if (lsq) { sys->context = EIG_linear_least_squares_solver_new(0, totvert, 1); - else + } + else { sys->context = EIG_linear_solver_new(0, totvert, 1); + } return sys; } @@ -267,28 +274,35 @@ static void laplacian_system_construct_end(LaplacianSystem *sys) laplacian_increase_edge_count(sys->edgehash, (*face)[2], (*face)[0]); } - if (sys->areaweights) - for (a = 0, face = sys->faces; a < sys->totface; a++, face++) + if (sys->areaweights) { + for (a = 0, face = sys->faces; a < sys->totface; a++, face++) { laplacian_triangle_area(sys, (*face)[0], (*face)[1], (*face)[2]); + } + } for (a = 0; a < totvert; a++) { if (sys->areaweights) { - if (sys->varea[a] != 0.0f) + if (sys->varea[a] != 0.0f) { sys->varea[a] = 0.5f / sys->varea[a]; + } } - else + else { sys->varea[a] = 1.0f; + } /* for heat weighting */ - if (sys->heat.H) + if (sys->heat.H) { EIG_linear_solver_matrix_add(sys->context, a, a, sys->heat.H[a]); + } } - if (sys->storeweights) + if (sys->storeweights) { sys->fweights = MEM_callocN(sizeof(float) * 3 * totface, "LaplacianFWeight"); + } - for (a = 0, face = sys->faces; a < totface; a++, face++) + for (a = 0, face = sys->faces; a < totface; a++, face++) { laplacian_triangle_weights(sys, a, (*face)[0], (*face)[1], (*face)[2]); + } MEM_freeN(sys->faces); sys->faces = NULL; @@ -304,16 +318,21 @@ static void laplacian_system_construct_end(LaplacianSystem *sys) static void laplacian_system_delete(LaplacianSystem *sys) { - if (sys->verts) + if (sys->verts) { MEM_freeN(sys->verts); - if (sys->varea) + } + if (sys->varea) { MEM_freeN(sys->varea); - if (sys->vpinned) + } + if (sys->vpinned) { MEM_freeN(sys->vpinned); - if (sys->faces) + } + if (sys->faces) { MEM_freeN(sys->faces); - if (sys->fweights) + } + if (sys->fweights) { MEM_freeN(sys->fweights); + } EIG_linear_solver_delete(sys->context); MEM_freeN(sys); @@ -346,7 +365,7 @@ int laplacian_system_solve(LaplacianSystem *sys) { sys->variablesdone = false; - //EIG_linear_solver_print_matrix(sys->context, ); + // EIG_linear_solver_print_matrix(sys->context, ); return EIG_linear_solver_solve(sys->context); } @@ -432,7 +451,7 @@ static void heat_ray_tree_create(LaplacianSystem *sys) BLI_bvhtree_insert(sys->heat.bvhtree, a, bb, 2); - //Setup inverse pointers to use on isect.orig + // Setup inverse pointers to use on isect.orig sys->heat.vltree[vtri[0]] = lt; sys->heat.vltree[vtri[1]] = lt; sys->heat.vltree[vtri[2]] = lt; @@ -450,8 +469,9 @@ static int heat_ray_source_visible(LaplacianSystem *sys, int vertex, int source) int visible; lt = sys->heat.vltree[vertex]; - if (lt == NULL) + if (lt == NULL) { return 1; + } data.sys = sys; copy_v3_v3(data.start, sys->heat.verts[vertex]); @@ -496,9 +516,11 @@ static int heat_source_closest(LaplacianSystem *sys, int vertex, int source) dist = heat_source_distance(sys, vertex, source); - if (dist <= sys->heat.mindist[vertex] * (1.0f + DISTANCE_EPSILON)) - if (heat_ray_source_visible(sys, vertex, source)) + if (dist <= sys->heat.mindist[vertex] * (1.0f + DISTANCE_EPSILON)) { + if (heat_ray_source_visible(sys, vertex, source)) { return 1; + } + } return 0; } @@ -514,16 +536,19 @@ static void heat_set_H(LaplacianSystem *sys, int vertex) for (j = 0; j < sys->heat.numsource; j++) { dist = heat_source_distance(sys, vertex, j); - if (dist < mindist) + if (dist < mindist) { mindist = dist; + } } sys->heat.mindist[vertex] = mindist; /* count number of sources with approximately this minimum distance */ - for (j = 0; j < sys->heat.numsource; j++) - if (heat_source_closest(sys, vertex, j)) + for (j = 0; j < sys->heat.numsource; j++) { + if (heat_source_closest(sys, vertex, j)) { numclosest++; + } + } sys->heat.p[vertex] = (numclosest > 0) ? 1.0f / numclosest : 0.0f; @@ -532,8 +557,9 @@ static void heat_set_H(LaplacianSystem *sys, int vertex) mindist = max_ff(mindist, 1e-4f); h = numclosest * C_WEIGHT / (mindist * mindist); } - else + else { h = 0.0f; + } sys->heat.H[vertex] = h; } @@ -557,8 +583,9 @@ static void heat_calc_vnormals(LaplacianSystem *sys) add_v3_v3(sys->heat.vnors[v3], fnor); } - for (a = 0; a < sys->totvert; a++) + for (a = 0; a < sys->totvert; a++) { normalize_v3(sys->heat.vnors[a]); + } } static void heat_laplacian_create(LaplacianSystem *sys) @@ -575,8 +602,9 @@ static void heat_laplacian_create(LaplacianSystem *sys) sys->heat.p = MEM_callocN(sizeof(float) * totvert, "HeatP"); /* add verts and faces to laplacian */ - for (a = 0; a < totvert; a++) + for (a = 0; a < totvert; a++) { laplacian_add_vertex(sys, sys->heat.verts[a], 0); + } for (a = 0, lt = mlooptri; a < tottri; a++, lt++) { int vtri[3]; @@ -589,8 +617,9 @@ static void heat_laplacian_create(LaplacianSystem *sys) /* for distance computation in set_H */ heat_calc_vnormals(sys); - for (a = 0; a < totvert; a++) + for (a = 0; a < totvert; a++) { heat_set_H(sys, a); + } } static void heat_system_free(LaplacianSystem *sys) @@ -616,8 +645,9 @@ static float heat_limit_weight(float weight) t = (weight - WEIGHT_LIMIT_END) / (WEIGHT_LIMIT_START - WEIGHT_LIMIT_END); return t * WEIGHT_LIMIT_START; } - else + else { return weight; + } } void heat_bone_weighting(Object *ob, @@ -695,14 +725,16 @@ void heat_bone_weighting(Object *ob, if (dgroupflip) { vertsflipped = MEM_callocN(sizeof(int) * me->totvert, "vertsflipped"); - for (a = 0; a < me->totvert; a++) + for (a = 0; a < me->totvert; a++) { vertsflipped[a] = mesh_get_x_mirror_vert(ob, NULL, a, use_topology); + } } /* compute weights per bone */ for (j = 0; j < numsource; j++) { - if (!selected[j]) + if (!selected[j]) { continue; + } firstsegment = (j == 0 || dgrouplist[j - 1] != dgrouplist[j]); lastsegment = (j == numsource - 1 || dgrouplist[j] != dgrouplist[j + 1]); @@ -711,55 +743,66 @@ void heat_bone_weighting(Object *ob, /* clear weights */ if (bbone && firstsegment) { for (a = 0; a < me->totvert; a++) { - if (mask && !mask[a]) + if (mask && !mask[a]) { continue; + } ED_vgroup_vert_remove(ob, dgrouplist[j], a); - if (vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) + if (vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) { ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]); + } } } /* fill right hand side */ laplacian_begin_solve(sys, -1); - for (a = 0; a < me->totvert; a++) - if (heat_source_closest(sys, a, j)) + for (a = 0; a < me->totvert; a++) { + if (heat_source_closest(sys, a, j)) { laplacian_add_right_hand_side(sys, a, sys->heat.H[a] * sys->heat.p[a]); + } + } /* solve */ if (laplacian_system_solve(sys)) { /* load solution into vertex groups */ for (a = 0; a < me->totvert; a++) { - if (mask && !mask[a]) + if (mask && !mask[a]) { continue; + } solution = laplacian_system_get_solution(sys, a); if (bbone) { - if (solution > 0.0f) + if (solution > 0.0f) { ED_vgroup_vert_add(ob, dgrouplist[j], a, solution, WEIGHT_ADD); + } } else { weight = heat_limit_weight(solution); - if (weight > 0.0f) + if (weight > 0.0f) { ED_vgroup_vert_add(ob, dgrouplist[j], a, weight, WEIGHT_REPLACE); - else + } + else { ED_vgroup_vert_remove(ob, dgrouplist[j], a); + } } /* do same for mirror */ if (vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) { if (bbone) { - if (solution > 0.0f) + if (solution > 0.0f) { ED_vgroup_vert_add(ob, dgroupflip[j], vertsflipped[a], solution, WEIGHT_ADD); + } } else { weight = heat_limit_weight(solution); - if (weight > 0.0f) + if (weight > 0.0f) { ED_vgroup_vert_add(ob, dgroupflip[j], vertsflipped[a], weight, WEIGHT_REPLACE); - else + } + else { ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]); + } } } } @@ -772,29 +815,34 @@ void heat_bone_weighting(Object *ob, /* remove too small vertex weights */ if (bbone && lastsegment) { for (a = 0; a < me->totvert; a++) { - if (mask && !mask[a]) + if (mask && !mask[a]) { continue; + } weight = ED_vgroup_vert_weight(ob, dgrouplist[j], a); weight = heat_limit_weight(weight); - if (weight <= 0.0f) + if (weight <= 0.0f) { ED_vgroup_vert_remove(ob, dgrouplist[j], a); + } if (vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) { weight = ED_vgroup_vert_weight(ob, dgroupflip[j], vertsflipped[a]); weight = heat_limit_weight(weight); - if (weight <= 0.0f) + if (weight <= 0.0f) { ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]); + } } } } } /* free */ - if (vertsflipped) + if (vertsflipped) { MEM_freeN(vertsflipped); - if (mask) + } + if (mask) { MEM_freeN(mask); + } heat_system_free(sys); @@ -964,8 +1012,9 @@ static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb, float end[3], vec_normal[3]; /* happens binding when a cage has no faces */ - if (UNLIKELY(mdb->bvhtree == NULL)) + if (UNLIKELY(mdb->bvhtree == NULL)) { return NULL; + } /* setup isec */ memset(&isect_mdef, 0, sizeof(isect_mdef)); @@ -1037,8 +1086,9 @@ static int meshdeform_inside_cage(MeshDeformBind *mdb, float *co) normalize_v3(dir); isect = meshdeform_ray_tree_intersect(mdb, start, outside); - if (isect && !isect->facing) + if (isect && !isect->facing) { return 1; + } } return 0; @@ -1054,12 +1104,15 @@ BLI_INLINE int meshdeform_index(MeshDeformBind *mdb, int x, int y, int z, int n) y += MESHDEFORM_OFFSET[n][1]; z += MESHDEFORM_OFFSET[n][2]; - if (x < 0 || x >= mdb->size) + if (x < 0 || x >= mdb->size) { return -1; - if (y < 0 || y >= mdb->size) + } + if (y < 0 || y >= mdb->size) { return -1; - if (z < 0 || z >= mdb->size) + } + if (z < 0 || z >= mdb->size) { return -1; + } return x + y * size + z * size * size; } @@ -1087,8 +1140,9 @@ static void meshdeform_add_intersections(MeshDeformBind *mdb, int x, int y, int /* check each outgoing edge for intersection */ for (i = 1; i <= 6; i++) { - if (meshdeform_index(mdb, x, y, z, i) == -1) + if (meshdeform_index(mdb, x, y, z, i) == -1) { continue; + } meshdeform_cell_center(mdb, x, y, z, i, ncenter); @@ -1134,9 +1188,11 @@ static void meshdeform_bind_floodfill(MeshDeformBind *mdb) } /* other cells are interior */ - for (a = 0; a < size * size * size; a++) - if (tag[a] == MESHDEFORM_TAG_UNTYPED) + for (a = 0; a < size * size * size; a++) { + if (tag[a] == MESHDEFORM_TAG_UNTYPED) { tag[a] = MESHDEFORM_TAG_INTERIOR; + } + } #if 0 { @@ -1230,8 +1286,9 @@ static float meshdeform_interp_w(MeshDeformBind *mdb, totweight += weight; } - if (totweight > 0.0f) + if (totweight > 0.0f) { result /= totweight; + } return result; } @@ -1241,12 +1298,15 @@ static void meshdeform_check_semibound(MeshDeformBind *mdb, int x, int y, int z) int i, a; a = meshdeform_index(mdb, x, y, z, 0); - if (mdb->tag[a] != MESHDEFORM_TAG_EXTERIOR) + if (mdb->tag[a] != MESHDEFORM_TAG_EXTERIOR) { return; + } - for (i = 1; i <= 6; i++) - if (mdb->boundisect[a][i - 1]) + for (i = 1; i <= 6; i++) { + if (mdb->boundisect[a][i - 1]) { mdb->semibound[a] = 1; + } + } } static float meshdeform_boundary_total_weight(MeshDeformBind *mdb, int x, int y, int z) @@ -1258,15 +1318,19 @@ static float meshdeform_boundary_total_weight(MeshDeformBind *mdb, int x, int y, /* count weight for neighbor cells */ for (i = 1; i <= 6; i++) { - if (meshdeform_index(mdb, x, y, z, i) == -1) + if (meshdeform_index(mdb, x, y, z, i) == -1) { continue; + } - if (mdb->boundisect[a][i - 1]) + if (mdb->boundisect[a][i - 1]) { weight = 1.0f / mdb->boundisect[a][i - 1]->len; - else if (!mdb->semibound[a]) + } + else if (!mdb->semibound[a]) { weight = 1.0f / mdb->width[0]; - else + } + else { weight = 0.0f; + } totweight += weight; } @@ -1282,16 +1346,18 @@ static void meshdeform_matrix_add_cell( int i, a, acenter; acenter = meshdeform_index(mdb, x, y, z, 0); - if (mdb->tag[acenter] == MESHDEFORM_TAG_EXTERIOR) + if (mdb->tag[acenter] == MESHDEFORM_TAG_EXTERIOR) { return; + } EIG_linear_solver_matrix_add(context, mdb->varidx[acenter], mdb->varidx[acenter], 1.0f); totweight = meshdeform_boundary_total_weight(mdb, x, y, z); for (i = 1; i <= 6; i++) { a = meshdeform_index(mdb, x, y, z, i); - if (a == -1 || mdb->tag[a] == MESHDEFORM_TAG_EXTERIOR) + if (a == -1 || mdb->tag[a] == MESHDEFORM_TAG_EXTERIOR) { continue; + } isect = mdb->boundisect[acenter][i - 1]; if (!isect) { @@ -1309,14 +1375,16 @@ static void meshdeform_matrix_add_rhs( int i, a, acenter; acenter = meshdeform_index(mdb, x, y, z, 0); - if (mdb->tag[acenter] == MESHDEFORM_TAG_EXTERIOR) + if (mdb->tag[acenter] == MESHDEFORM_TAG_EXTERIOR) { return; + } totweight = meshdeform_boundary_total_weight(mdb, x, y, z); for (i = 1; i <= 6; i++) { a = meshdeform_index(mdb, x, y, z, i); - if (a == -1) + if (a == -1) { continue; + } isect = mdb->boundisect[acenter][i - 1]; @@ -1336,8 +1404,9 @@ static void meshdeform_matrix_add_semibound_phi( int i, a; a = meshdeform_index(mdb, x, y, z, 0); - if (!mdb->semibound[a]) + if (!mdb->semibound[a]) { return; + } mdb->phi[a] = 0.0f; @@ -1360,8 +1429,9 @@ static void meshdeform_matrix_add_exterior_phi( int i, a, acenter; acenter = meshdeform_index(mdb, x, y, z, 0); - if (mdb->tag[acenter] != MESHDEFORM_TAG_EXTERIOR || mdb->semibound[acenter]) + if (mdb->tag[acenter] != MESHDEFORM_TAG_EXTERIOR || mdb->semibound[acenter]) { return; + } phi = 0.0f; totweight = 0.0f; @@ -1374,8 +1444,9 @@ static void meshdeform_matrix_add_exterior_phi( } } - if (totweight != 0.0f) + if (totweight != 0.0f) { mdb->phi[acenter] = phi / totweight; + } } static void meshdeform_matrix_solve(MeshDeformModifierData *mmd, MeshDeformBind *mdb) @@ -1387,8 +1458,9 @@ static void meshdeform_matrix_solve(MeshDeformModifierData *mmd, MeshDeformBind /* setup variable indices */ mdb->varidx = MEM_callocN(sizeof(int) * mdb->size3, "MeshDeformDSvaridx"); - for (a = 0, totvar = 0; a < mdb->size3; a++) + for (a = 0, totvar = 0; a < mdb->size3; a++) { mdb->varidx[a] = (mdb->tag[a] == MESHDEFORM_TAG_EXTERIOR) ? -1 : totvar++; + } if (totvar == 0) { MEM_freeN(mdb->varidx); @@ -1401,33 +1473,46 @@ static void meshdeform_matrix_solve(MeshDeformModifierData *mmd, MeshDeformBind context = EIG_linear_solver_new(totvar, totvar, 1); /* build matrix */ - for (z = 0; z < mdb->size; z++) - for (y = 0; y < mdb->size; y++) - for (x = 0; x < mdb->size; x++) + for (z = 0; z < mdb->size; z++) { + for (y = 0; y < mdb->size; y++) { + for (x = 0; x < mdb->size; x++) { meshdeform_matrix_add_cell(mdb, context, x, y, z); + } + } + } /* solve for each cage vert */ for (a = 0; a < mdb->totcagevert; a++) { /* fill in right hand side and solve */ - for (z = 0; z < mdb->size; z++) - for (y = 0; y < mdb->size; y++) - for (x = 0; x < mdb->size; x++) + for (z = 0; z < mdb->size; z++) { + for (y = 0; y < mdb->size; y++) { + for (x = 0; x < mdb->size; x++) { meshdeform_matrix_add_rhs(mdb, context, x, y, z, a); + } + } + } if (EIG_linear_solver_solve(context)) { - for (z = 0; z < mdb->size; z++) - for (y = 0; y < mdb->size; y++) - for (x = 0; x < mdb->size; x++) + for (z = 0; z < mdb->size; z++) { + for (y = 0; y < mdb->size; y++) { + for (x = 0; x < mdb->size; x++) { meshdeform_matrix_add_semibound_phi(mdb, x, y, z, a); + } + } + } - for (z = 0; z < mdb->size; z++) - for (y = 0; y < mdb->size; y++) - for (x = 0; x < mdb->size; x++) + for (z = 0; z < mdb->size; z++) { + for (y = 0; y < mdb->size; y++) { + for (x = 0; x < mdb->size; x++) { meshdeform_matrix_add_exterior_phi(mdb, x, y, z, a); + } + } + } for (b = 0; b < mdb->size3; b++) { - if (mdb->tag[b] != MESHDEFORM_TAG_EXTERIOR) + if (mdb->tag[b] != MESHDEFORM_TAG_EXTERIOR) { mdb->phi[b] = EIG_linear_solver_variable_get(context, 0, mdb->varidx[b]); + } mdb->totalphi[b] += mdb->phi[b]; } @@ -1476,7 +1561,10 @@ static void meshdeform_matrix_solve(MeshDeformModifierData *mmd, MeshDeformBind if (mdb->tag[b] != MESHDEFORM_TAG_EXTERIOR) if (fabsf(mdb->totalphi[b] - 1.0f) > 1e-4f) printf("totalphi deficiency [%s|%d] %d: %.10f\n", - (mdb->tag[b] == MESHDEFORM_TAG_INTERIOR) ? "interior" : "boundary", mdb->semibound[b], mdb->varidx[b], mdb->totalphi[b]); + (mdb->tag[b] == MESHDEFORM_TAG_INTERIOR) ? "interior" : "boundary", + mdb->semibound[b], + mdb->varidx[b], + mdb->totalphi[b]); #endif /* free */ @@ -1496,8 +1584,9 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin /* compute bounding box of the cage mesh */ INIT_MINMAX(mdb->min, mdb->max); - for (a = 0; a < mdb->totcagevert; a++) + for (a = 0; a < mdb->totcagevert; a++) { minmax_v3v3_v3(mdb->min, mdb->max, mdb->cagecos[a]); + } /* allocate memory */ mdb->size = (2 << (mmd->gridsize - 1)) + 2; @@ -1510,10 +1599,12 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin mdb->bvhtree = BKE_bvhtree_from_mesh_get(&mdb->bvhdata, mdb->cagemesh, BVHTREE_FROM_LOOPTRI, 4); mdb->inside = MEM_callocN(sizeof(int) * mdb->totvert, "MDefInside"); - if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) + if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) { mdb->dyngrid = MEM_callocN(sizeof(MDefBindInfluence *) * mdb->size3, "MDefDynGrid"); - else + } + else { mdb->weights = MEM_callocN(sizeof(float) * mdb->totvert * mdb->totcagevert, "MDefWeights"); + } mdb->memarena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "harmonic coords arena"); BLI_memarena_use_calloc(mdb->memarena); @@ -1531,9 +1622,11 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin /* make bounding box equal size in all directions, add padding, and compute * width of the cells */ maxwidth = -1.0f; - for (a = 0; a < 3; a++) - if (mdb->max[a] - mdb->min[a] > maxwidth) + for (a = 0; a < 3; a++) { + if (mdb->max[a] - mdb->min[a] > maxwidth) { maxwidth = mdb->max[a] - mdb->min[a]; + } + } for (a = 0; a < 3; a++) { center[a] = (mdb->min[a] + mdb->max[a]) * 0.5f; @@ -1554,8 +1647,9 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin for (a = 0; a < mdb->totvert; a++) { copy_v3_v3(vec, mdb->vertexcos[a]); mdb->inside[a] = meshdeform_inside_cage(mdb, vec); - if (mdb->inside[a]) + if (mdb->inside[a]) { totinside++; + } } /* free temporary MDefBoundIsects */ @@ -1563,22 +1657,29 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin mdb->memarena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "harmonic coords arena"); /* start with all cells untyped */ - for (a = 0; a < mdb->size3; a++) + for (a = 0; a < mdb->size3; a++) { mdb->tag[a] = MESHDEFORM_TAG_UNTYPED; + } /* detect intersections and tag boundary cells */ - for (z = 0; z < mdb->size; z++) - for (y = 0; y < mdb->size; y++) - for (x = 0; x < mdb->size; x++) + for (z = 0; z < mdb->size; z++) { + for (y = 0; y < mdb->size; y++) { + for (x = 0; x < mdb->size; x++) { meshdeform_add_intersections(mdb, x, y, z); + } + } + } /* compute exterior and interior tags */ meshdeform_bind_floodfill(mdb); - for (z = 0; z < mdb->size; z++) - for (y = 0; y < mdb->size; y++) - for (x = 0; x < mdb->size; x++) + for (z = 0; z < mdb->size; z++) { + for (y = 0; y < mdb->size; y++) { + for (x = 0; x < mdb->size; x++) { meshdeform_check_semibound(mdb, x, y, z); + } + } + } /* solve */ meshdeform_matrix_solve(mmd, mdb); @@ -1586,9 +1687,11 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin /* assign results */ if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) { mmd->totinfluence = 0; - for (a = 0; a < mdb->size3; a++) - for (inf = mdb->dyngrid[a]; inf; inf = inf->next) + for (a = 0; a < mdb->size3; a++) { + for (inf = mdb->dyngrid[a]; inf; inf = inf->next) { mmd->totinfluence++; + } + } /* convert MDefBindInfluences to smaller MDefInfluences */ mmd->dyngrid = MEM_callocN(sizeof(MDefCell) * mdb->size3, "MDefDynGrid"); @@ -1609,8 +1712,9 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin if (totweight > 0.0f) { mdinf = mmd->dyninfluences + cell->offset; - for (b = 0; b < cell->totinfluence; b++, mdinf++) + for (b = 0; b < cell->totinfluence; b++, mdinf++) { mdinf->weight /= totweight; + } } offset += cell->totinfluence; @@ -1663,10 +1767,12 @@ void ED_mesh_deform_bind_callback(MeshDeformModifierData *mmd, copy_m4_m4(mdb.cagemat, cagemat); mvert = mdb.cagemesh->mvert; - for (a = 0; a < mdb.totcagevert; a++) + for (a = 0; a < mdb.totcagevert; a++) { copy_v3_v3(mdb.cagecos[a], mvert[a].co); - for (a = 0; a < mdb.totvert; a++) + } + for (a = 0; a < mdb.totvert; a++) { mul_v3_m4v3(mdb.vertexcos[a], mdb.cagemat, vertexcos + a * 3); + } /* solve */ harmonic_coordinates_bind(mmd_orig, &mdb); @@ -1678,8 +1784,9 @@ void ED_mesh_deform_bind_callback(MeshDeformModifierData *mmd, copy_m4_m4(mmd_orig->bindmat, mmd_orig->object->obmat); /* transform bindcagecos to world space */ - for (a = 0; a < mdb.totcagevert; a++) + for (a = 0; a < mdb.totcagevert; a++) { mul_m4_v3(mmd_orig->object->obmat, mmd_orig->bindcagecos + a * 3); + } /* free */ MEM_freeN(mdb.vertexcos); diff --git a/source/blender/editors/armature/pose_edit.c b/source/blender/editors/armature/pose_edit.c index 51641041ea1..cf64210ebdb 100644 --- a/source/blender/editors/armature/pose_edit.c +++ b/source/blender/editors/armature/pose_edit.c @@ -78,7 +78,8 @@ Object *ED_pose_object_from_context(bContext *C) ScrArea *sa = CTX_wm_area(C); Object *ob; - /* since this call may also be used from the buttons window, we need to check for where to get the object */ + /* Since this call may also be used from the buttons window, + * we need to check for where to get the object. */ if (sa && sa->spacetype == SPACE_PROPERTIES) { ob = ED_object_context(C); } @@ -167,7 +168,8 @@ static bool pose_has_protected_selected(Object *ob, short warn) } } if (pchan) { - if (warn) error("Cannot change Proxy protected bones"); + if (warn) + error("Cannot change Proxy protected bones"); return 1; } } @@ -261,8 +263,9 @@ static int pose_calculate_paths_invoke(bContext *C, wmOperator *op, const wmEven { Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } /* set default settings from existing/stored settings */ { @@ -289,8 +292,9 @@ static int pose_calculate_paths_exec(bContext *C, wmOperator *op) Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); Scene *scene = CTX_data_scene(C); - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } /* grab baking settings from operator settings */ { @@ -389,8 +393,9 @@ static int pose_update_paths_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); Scene *scene = CTX_data_scene(C); - if (ELEM(NULL, ob, scene)) + if (ELEM(NULL, ob, scene)) { return OPERATOR_CANCELLED; + } /* calculate the bones that now have motionpaths... */ /* TODO: only make for the selected bones? */ @@ -425,8 +430,9 @@ static void ED_pose_clear_paths(Object *ob, bool only_selected) bPoseChannel *pchan; bool skipped = false; - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return; + } /* free the motionpath blocks for all bones - This is easier for users to quickly clear all */ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { @@ -442,8 +448,9 @@ static void ED_pose_clear_paths(Object *ob, bool only_selected) } /* if nothing was skipped, there should be no paths left! */ - if (skipped == false) + if (skipped == false) { ob->pose->avs.path_bakeflag &= ~MOTIONPATH_BAKE_HAS_PATHS; + } /* tag armature object for copy on write - so removed paths don't still show */ DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); @@ -456,8 +463,9 @@ static int pose_clear_paths_exec(bContext *C, wmOperator *op) bool only_selected = RNA_boolean_get(op->ptr, "only_selected"); /* only continue if there's an object */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } /* use the backend function for this */ ED_pose_clear_paths(ob, only_selected); @@ -600,8 +608,7 @@ static int pose_autoside_names_exec(bContext *C, wmOperator *op) Object *ob_prev = NULL; /* loop through selected bones, auto-naming them */ - CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) - { + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) { bArmature *arm = ob->data; BLI_strncpy(newname, pchan->name, sizeof(newname)); if (bone_autoside_name(newname, 1, axis, pchan->bone->head[axis], pchan->bone->tail[axis])) { @@ -658,8 +665,7 @@ static int pose_bone_rotmode_exec(bContext *C, wmOperator *op) Object *prev_ob = NULL; /* set rotation mode of selected bones */ - CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) - { + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) { pchan->rotmode = mode; if (prev_ob != ob) { @@ -735,8 +741,9 @@ static int pose_armature_layers_showall_exec(bContext *C, wmOperator *op) int i; /* sanity checking */ - if (arm == NULL) + if (arm == NULL) { return OPERATOR_CANCELLED; + } /* use RNA to set the layers * although it would be faster to just set directly using bitflags, we still @@ -744,8 +751,9 @@ static int pose_armature_layers_showall_exec(bContext *C, wmOperator *op) */ RNA_id_pointer_create(&arm->id, &ptr); - for (i = 0; i < maxLayers; i++) + for (i = 0; i < maxLayers; i++) { layers[i] = 1; + } RNA_boolean_set_array(&ptr, "layers", layers); @@ -788,10 +796,12 @@ static int armature_layers_invoke(bContext *C, wmOperator *op, const wmEvent *ev bool layers[32]; /* sanity checking */ - if (arm == NULL) + if (arm == NULL) { return OPERATOR_CANCELLED; + } - /* get RNA pointer to armature data to use that to retrieve the layers as ints to init the operator */ + /* Get RNA pointer to armature data to use that to retrieve the layers as ints + * to init the operator. */ RNA_id_pointer_create((ID *)arm, &ptr); RNA_boolean_get_array(&ptr, "layers", layers); RNA_boolean_set_array(op->ptr, "layers", layers); @@ -886,8 +896,7 @@ static int pose_bone_layers_exec(bContext *C, wmOperator *op) Object *prev_ob = NULL; /* set layers of pchans based on the values set in the operator props */ - CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) - { + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) { /* get pointer for pchan, and write flags this way */ RNA_pointer_create((ID *)ob->data, &RNA_Bone, pchan->bone, &ptr); RNA_boolean_set_array(&ptr, "layers", layers); @@ -963,8 +972,7 @@ static int armature_bone_layers_exec(bContext *C, wmOperator *op) RNA_boolean_get_array(op->ptr, "layers", layers); /* set layers of pchans based on the values set in the operator props */ - CTX_DATA_BEGIN_WITH_ID(C, EditBone *, ebone, selected_editable_bones, bArmature *, arm) - { + CTX_DATA_BEGIN_WITH_ID (C, EditBone *, ebone, selected_editable_bones, bArmature *, arm) { /* get pointer for pchan, and write flags this way */ RNA_pointer_create((ID *)arm, &RNA_EditBone, ebone, &ptr); RNA_boolean_set_array(&ptr, "layers", layers); diff --git a/source/blender/editors/armature/pose_group.c b/source/blender/editors/armature/pose_group.c index 0d100a09dfd..3ae9976c948 100644 --- a/source/blender/editors/armature/pose_group.c +++ b/source/blender/editors/armature/pose_group.c @@ -59,8 +59,9 @@ static int pose_group_add_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_pose_object_from_context(C); /* only continue if there's an object and pose */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } /* for now, just call the API function for this */ BKE_pose_add_group(ob->pose, NULL); @@ -91,8 +92,9 @@ static int pose_group_remove_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_pose_object_from_context(C); /* only continue if there's an object and pose */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } /* for now, just call the API function for this */ BKE_pose_remove_group_index(ob->pose, ob->pose->active_group); @@ -134,8 +136,9 @@ static int pose_groups_menu_invoke(bContext *C, wmOperator *op, const wmEvent *U int i; /* only continue if there's an object, and a pose there too */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } pose = ob->pose; /* If group index is set, try to use it! */ @@ -164,8 +167,9 @@ static int pose_groups_menu_invoke(bContext *C, wmOperator *op, const wmEvent *U } /* add entries for each group */ - for (grp = pose->agroups.first, i = 1; grp; grp = grp->next, i++) + for (grp = pose->agroups.first, i = 1; grp; grp = grp->next, i++) { uiItemIntO(layout, grp->name, ICON_NONE, op->idname, "type", i); + } /* finish building the menu, and process it (should result in calling self again) */ UI_popup_menu_end(C, pup); @@ -187,8 +191,9 @@ static int pose_group_assign_exec(bContext *C, wmOperator *op) bool done = false; /* only continue if there's an object, and a pose there too */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } pose = ob->pose; @@ -196,8 +201,9 @@ static int pose_group_assign_exec(bContext *C, wmOperator *op) * - if 0 after this, make a new group... */ pose->active_group = RNA_int_get(op->ptr, "type"); - if (pose->active_group == 0) + if (pose->active_group == 0) { BKE_pose_add_group(ob->pose, NULL); + } /* add selected bones to group then */ FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob, pchan) { @@ -211,10 +217,12 @@ static int pose_group_assign_exec(bContext *C, wmOperator *op) DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); /* report done status */ - if (done) + if (done) { return OPERATOR_FINISHED; - else + } + else { return OPERATOR_CANCELLED; + } } void POSE_OT_group_assign(wmOperatorType *ot) @@ -242,8 +250,9 @@ static int pose_group_unassign_exec(bContext *C, wmOperator *UNUSED(op)) bool done = false; /* only continue if there's an object, and a pose there too */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } /* find selected bones to remove from all bone groups */ FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob, pchan) { @@ -259,10 +268,12 @@ static int pose_group_unassign_exec(bContext *C, wmOperator *UNUSED(op)) DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); /* report done status */ - if (done) + if (done) { return OPERATOR_FINISHED; - else + } + else { return OPERATOR_CANCELLED; + } } void POSE_OT_group_unassign(wmOperatorType *ot) @@ -288,15 +299,18 @@ static int group_move_exec(bContext *C, wmOperator *op) bActionGroup *grp; int dir = RNA_enum_get(op->ptr, "direction"); - if (ELEM(NULL, ob, pose)) + if (ELEM(NULL, ob, pose)) { return OPERATOR_CANCELLED; - if (pose->active_group <= 0) + } + if (pose->active_group <= 0) { return OPERATOR_CANCELLED; + } /* get group to move */ grp = BLI_findlink(&pose->agroups, pose->active_group - 1); - if (grp == NULL) + if (grp == NULL) { return OPERATOR_CANCELLED; + } /* move bone group */ if (BLI_listbase_link_move(&pose->agroups, grp, dir)) { @@ -374,10 +388,12 @@ static int group_sort_exec(bContext *C, wmOperator *UNUSED(op)) int agrp_count; int i; - if (ELEM(NULL, ob, pose)) + if (ELEM(NULL, ob, pose)) { return OPERATOR_CANCELLED; - if (pose->active_group <= 0) + } + if (pose->active_group <= 0) { return OPERATOR_CANCELLED; + } /* create temporary array with bone groups and indices */ agrp_count = BLI_listbase_count(&pose->agroups); @@ -439,12 +455,14 @@ static void pose_group_select(Object *ob, bool select) FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (ob, pchan) { if ((pchan->bone->flag & BONE_UNSELECTABLE) == 0) { if (select) { - if (pchan->agrp_index == pose->active_group) + if (pchan->agrp_index == pose->active_group) { pchan->bone->flag |= BONE_SELECTED; + } } else { - if (pchan->agrp_index == pose->active_group) + if (pchan->agrp_index == pose->active_group) { pchan->bone->flag &= ~BONE_SELECTED; + } } } } @@ -456,8 +474,9 @@ static int pose_group_select_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_pose_object_from_context(C); /* only continue if there's an object, and a pose there too */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } pose_group_select(ob, 1); @@ -489,8 +508,9 @@ static int pose_group_deselect_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_pose_object_from_context(C); /* only continue if there's an object, and a pose there too */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return OPERATOR_CANCELLED; + } pose_group_select(ob, 0); diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c index 443bcdde028..7b31897766d 100644 --- a/source/blender/editors/armature/pose_lib.c +++ b/source/blender/editors/armature/pose_lib.c @@ -77,7 +77,9 @@ static void action_set_activemarker(void *UNUSED(a), void *UNUSED(b), void *UNUS } /* ************************************************************* */ -/* == POSE-LIBRARY TOOL FOR BLENDER == +/** + * Pose-Library Tool for Blender + * ============================= * * Overview: * This tool allows animators to store a set of frequently used poses to dump into @@ -85,13 +87,13 @@ static void action_set_activemarker(void *UNUSED(a), void *UNUSED(b), void *UNUS * It acts as a kind of "glorified clipboard for poses", allowing for naming of poses. * * Features: - * - PoseLibs are simply normal Actions - * - Each "pose" is simply a set of keyframes that occur on a particular frame - * -> a set of TimeMarkers that belong to each Action, help 'label' where a 'pose' can be - * found in the Action + * - PoseLibs are simply normal Actions. + * - Each "pose" is simply a set of keyframes that occur on a particular frame. + * - A set of TimeMarkers that belong to each Action, help 'label' where a 'pose' can be + * found in the Action. * - The Scrollwheel or PageUp/Down buttons when used in a special mode or after pressing/holding - * [a modifier] key, cycles through the poses available for the active pose's poselib, allowing the - * animator to preview what action best suits that pose + * [a modifier] key, cycles through the poses available for the active pose's poselib, + * allowing the animator to preview what action best suits that pose. */ /* ************************************************************* */ @@ -105,8 +107,9 @@ static int poselib_get_free_index(bAction *act) bool changed = false; /* sanity checks */ - if (ELEM(NULL, act, act->markers.first)) + if (ELEM(NULL, act, act->markers.first)) { return 1; + } /* As poses are not stored in chronological order, we must iterate over this list * a few times until we don't make any new discoveries (mostly about the lower bound). @@ -135,19 +138,23 @@ static int poselib_get_free_index(bAction *act) /* - if low is not equal to high, then low+1 is a gap * - if low is equal to high, then high+1 is the next index (add at end) */ - if (low < high) + if (low < high) { return (low + 1); - else + } + else { return (high + 1); + } } /* returns the active pose for a poselib */ static TimeMarker *poselib_get_active_pose(bAction *act) { - if ((act) && (act->active_marker)) + if ((act) && (act->active_marker)) { return BLI_findlink(&act->markers, act->active_marker - 1); - else + } + else { return NULL; + } } /* Get object that Pose Lib should be found on */ @@ -157,15 +164,18 @@ static Object *get_poselib_object(bContext *C) ScrArea *sa; /* sanity check */ - if (C == NULL) + if (C == NULL) { return NULL; + } sa = CTX_wm_area(C); - if (sa && (sa->spacetype == SPACE_PROPERTIES)) + if (sa && (sa->spacetype == SPACE_PROPERTIES)) { return ED_object_context(C); - else + } + else { return BKE_object_pose_armature_get(CTX_data_active_object(C)); + } } /* Poll callback for operators that require existing PoseLib data (with poses) to work */ @@ -190,12 +200,14 @@ static bool has_poselib_pose_data_for_editing_poll(bContext *C) static bAction *poselib_init_new(Main *bmain, Object *ob) { /* sanity checks - only for armatures */ - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return NULL; + } /* init object's poselib action (unlink old one if there) */ - if (ob->poselib) + if (ob->poselib) { id_us_min(&ob->poselib->id); + } ob->poselib = BKE_action_add(bmain, "PoseLib"); ob->poselib->idroot = ID_OB; @@ -206,12 +218,15 @@ static bAction *poselib_init_new(Main *bmain, Object *ob) /* Initialize a new poselib (checks if that needs to happen) */ static bAction *poselib_validate(Main *bmain, Object *ob) { - if (ELEM(NULL, ob, ob->pose)) + if (ELEM(NULL, ob, ob->pose)) { return NULL; - else if (ob->poselib == NULL) + } + else if (ob->poselib == NULL) { return poselib_init_new(bmain, ob); - else + } + else { return ob->poselib; + } } /* ************************************************************* */ @@ -223,8 +238,9 @@ static int poselib_new_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = get_poselib_object(C); /* sanity checks */ - if (ob == NULL) + if (ob == NULL) { return OPERATOR_CANCELLED; + } /* new method here deals with the rest... */ poselib_init_new(bmain, ob); @@ -257,8 +273,9 @@ static int poselib_unlink_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = get_poselib_object(C); /* sanity checks */ - if (ELEM(NULL, ob, ob->poselib)) + if (ELEM(NULL, ob, ob->poselib)) { return OPERATOR_CANCELLED; + } /* there should be a poselib (we just checked above!), so just lower its user count and remove */ id_us_min(&ob->poselib->id); @@ -338,10 +355,12 @@ static int poselib_sanitize_exec(bContext *C, wmOperator *op) for (marker = act->markers.first; marker; marker = markern) { markern = marker->next; - if (marker->flag != -1) + if (marker->flag != -1) { BLI_freelinkN(&act->markers, marker); - else + } + else { marker->flag = 0; + } } /* free temp memory */ @@ -423,8 +442,9 @@ static int poselib_add_menu_invoke(bContext *C, wmOperator *op, const wmEvent *U uiLayout *layout; /* sanity check */ - if (ELEM(NULL, ob, pose)) + if (ELEM(NULL, ob, pose)) { return OPERATOR_CANCELLED; + } /* start building */ pup = UI_popup_menu_begin(C, op->type->name, ICON_NONE); @@ -472,8 +492,9 @@ static int poselib_add_exec(bContext *C, wmOperator *op) char name[64]; /* sanity check (invoke should have checked this anyway) */ - if (ELEM(NULL, ob, pose)) + if (ELEM(NULL, ob, pose)) { return OPERATOR_CANCELLED; + } /* get name to give to pose */ RNA_string_get(op->ptr, "name", name); @@ -677,7 +698,8 @@ static int poselib_rename_invoke(bContext *C, wmOperator *op, const wmEvent *eve return OPERATOR_CANCELLED; } else { - /* use the existing name of the marker as the name, and use the active marker as the one to rename */ + /* Use the existing name of the marker as the name, + * and use the active marker as the one to rename. */ RNA_enum_set(op->ptr, "pose", act->active_marker - 1); RNA_string_set(op->ptr, "name", marker->name); } @@ -954,8 +976,9 @@ static void poselib_backup_posecopy(tPoseLib_PreviewData *pld) plb->pchan = pchan; memcpy(&plb->olddata, plb->pchan, sizeof(bPoseChannel)); - if (pchan->prop) + if (pchan->prop) { plb->oldprops = IDP_CopyProperty(pchan->prop); + } BLI_addtail(&pld->backups, plb); @@ -975,8 +998,9 @@ static void poselib_backup_restore(tPoseLib_PreviewData *pld) memcpy(plb->pchan, &plb->olddata, sizeof(bPoseChannel)); /* just overwrite values of properties from the stored copies (there should be some) */ - if (plb->oldprops) + if (plb->oldprops) { IDP_SyncGroupValues(plb->pchan->prop, plb->oldprops); + } /* TODO: constraints settings aren't restored yet, * even though these could change (though not that likely) */ @@ -1024,10 +1048,12 @@ static void poselib_apply_pose(tPoseLib_PreviewData *pld) const bool any_bone_selected = pld->flag & PL_PREVIEW_ANY_BONE_SELECTED; /* get the frame */ - if (pld->marker) + if (pld->marker) { frame = pld->marker->frame; - else + } + else { return; + } /* init settings for testing groups for keyframes */ group_ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE); @@ -1058,8 +1084,9 @@ static void poselib_apply_pose(tPoseLib_PreviewData *pld) } } - if (ok) + if (ok) { animsys_evaluate_action_group(ptr, act, agrp, (float)frame); + } } } } @@ -1090,13 +1117,15 @@ static void poselib_keytag_pose(bContext *C, Scene *scene, tPoseLib_PreviewData ANIM_relative_keyingset_add_source(&dsources, &pld->ob->id, &RNA_PoseBone, pchan); /* clear any unkeyed tags */ - if (pchan->bone) + if (pchan->bone) { pchan->bone->flag &= ~BONE_UNKEYED; + } } else { /* add unkeyed tags */ - if (pchan->bone) + if (pchan->bone) { pchan->bone->flag |= BONE_UNKEYED; + } } } } @@ -1121,27 +1150,32 @@ static void poselib_preview_apply(bContext *C, wmOperator *op) /* only recalc pose (and its dependencies) if pose has changed */ if (pld->redraw == PL_PREVIEW_REDRAWALL) { /* don't clear pose if firsttime */ - if ((pld->flag & PL_PREVIEW_FIRSTTIME) == 0) + if ((pld->flag & PL_PREVIEW_FIRSTTIME) == 0) { poselib_backup_restore(pld); - else + } + else { pld->flag &= ~PL_PREVIEW_FIRSTTIME; + } /* pose should be the right one to draw (unless we're temporarily not showing it) */ if ((pld->flag & PL_PREVIEW_SHOWORIGINAL) == 0) { RNA_int_set(op->ptr, "pose_index", BLI_findindex(&pld->act->markers, pld->marker)); poselib_apply_pose(pld); } - else + else { RNA_int_set(op->ptr, "pose_index", -2); /* -2 means don't apply any pose */ + } /* old optimize trick... this enforces to bypass the depsgraph * - note: code copied from transform_generics.c -> recalcData() */ // FIXME: shouldn't this use the builtin stuff? - if ((pld->arm->flag & ARM_DELAYDEFORM) == 0) + if ((pld->arm->flag & ARM_DELAYDEFORM) == 0) { DEG_id_tag_update(&pld->ob->id, ID_RECALC_GEOMETRY); /* sets recalc flags */ - else + } + else { BKE_pose_where_is(CTX_data_depsgraph(C), pld->scene, pld->ob); + } } /* do header print - if interactively previewing */ @@ -1202,8 +1236,9 @@ static void poselib_preview_apply(bContext *C, wmOperator *op) static void poselib_preview_get_next(tPoseLib_PreviewData *pld, int step) { /* stop if not going anywhere, as we assume that there is a direction to move in */ - if (step == 0) + if (step == 0) { return; + } /* search-string dictates a special approach */ if (pld->searchstr[0]) { @@ -1241,50 +1276,59 @@ static void poselib_preview_get_next(tPoseLib_PreviewData *pld, int step) /* find first match */ for (ldc = pld->searchp.first; ldc; ldc = ldc->next) { - if (ldc->data == pld->marker) + if (ldc->data == pld->marker) { break; + } } - if (ldc == NULL) + if (ldc == NULL) { ldc = pld->searchp.first; + } /* Loop through the matches in a cyclic fashion, incrementing/decrementing step as appropriate * until step == 0. At this point, marker should be the correct marker. */ if (step > 0) { - for (ld = ldc; ld && step; ld = ldn, step--) + for (ld = ldc; ld && step; ld = ldn, step--) { ldn = (ld->next) ? ld->next : pld->searchp.first; + } } else { - for (ld = ldc; ld && step; ld = ldn, step++) + for (ld = ldc; ld && step; ld = ldn, step++) { ldn = (ld->prev) ? ld->prev : pld->searchp.last; + } } /* set marker */ - if (ld) + if (ld) { pld->marker = ld->data; + } } else { TimeMarker *marker, *next; /* if no marker, because we just ended searching, then set that to the start of the list */ - if (pld->marker == NULL) + if (pld->marker == NULL) { pld->marker = pld->act->markers.first; + } /* Loop through the markers in a cyclic fashion, incrementing/decrementing step as appropriate * until step == 0. At this point, marker should be the correct marker. */ if (step > 0) { - for (marker = pld->marker; marker && step; marker = next, step--) + for (marker = pld->marker; marker && step; marker = next, step--) { next = (marker->next) ? marker->next : pld->act->markers.first; + } } else { - for (marker = pld->marker; marker && step; marker = next, step++) + for (marker = pld->marker; marker && step; marker = next, step++) { next = (marker->prev) ? marker->prev : pld->act->markers.last; + } } /* it should be fairly impossible for marker to be NULL */ - if (marker) + if (marker) { pld->marker = marker; + } } } @@ -1301,8 +1345,9 @@ static void poselib_preview_handle_search(tPoseLib_PreviewData *pld, short index = pld->search_cursor; short i; - for (i = index; i <= len; i++) + for (i = index; i <= len; i++) { pld->searchstr[i - 1] = pld->searchstr[i]; + } pld->search_cursor--; @@ -1319,8 +1364,9 @@ static void poselib_preview_handle_search(tPoseLib_PreviewData *pld, int i; if (index < len) { - for (i = index; i < len; i++) + for (i = index; i < len; i++) { pld->searchstr[i] = pld->searchstr[i + 1]; + } poselib_preview_get_next(pld, 1); pld->redraw = PL_PREVIEW_REDRAWALL; @@ -1337,11 +1383,13 @@ static void poselib_preview_handle_search(tPoseLib_PreviewData *pld, short i; if (len) { - for (i = len; i > index; i--) + for (i = len; i > index; i--) { pld->searchstr[i] = pld->searchstr[i - 1]; + } } - else + else { pld->searchstr[1] = 0; + } pld->searchstr[index] = ascii; pld->search_cursor++; @@ -1359,7 +1407,11 @@ static int poselib_preview_handle_event(bContext *UNUSED(C), wmOperator *op, con /* only accept 'press' event, and ignore 'release', so that we don't get double actions */ if (ELEM(event->val, KM_PRESS, KM_NOTHING) == 0) { - //printf("PoseLib: skipping event with type '%s' and val %d\n", WM_key_event_string(event->type, false), event->val); +#if 0 + printf("PoseLib: skipping event with type '%s' and val %d\n", + WM_key_event_string(event->type, false), + event->val); +#endif return ret; } @@ -1403,7 +1455,7 @@ static int poselib_preview_handle_event(bContext *UNUSED(C), wmOperator *op, con case PADMINUS: case MIDDLEMOUSE: case MOUSEMOVE: - //pld->redraw = PL_PREVIEW_REDRAWHEADER; + // pld->redraw = PL_PREVIEW_REDRAWHEADER; ret = OPERATOR_PASS_THROUGH; break; @@ -1471,8 +1523,9 @@ static int poselib_preview_handle_event(bContext *UNUSED(C), wmOperator *op, con case RIGHTARROWKEY: if (pld->searchstr[0]) { /* move text-cursor to the right */ - if (pld->search_cursor < strlen(pld->searchstr)) + if (pld->search_cursor < strlen(pld->searchstr)) { pld->search_cursor++; + } pld->redraw = PL_PREVIEW_REDRAWHEADER; } else { @@ -1486,8 +1539,9 @@ static int poselib_preview_handle_event(bContext *UNUSED(C), wmOperator *op, con case LEFTARROWKEY: if (pld->searchstr[0]) { /* move text-cursor to the left */ - if (pld->search_cursor) + if (pld->search_cursor) { pld->search_cursor--; + } pld->redraw = PL_PREVIEW_REDRAWHEADER; } else { @@ -1533,7 +1587,7 @@ static int poselib_preview_handle_event(bContext *UNUSED(C), wmOperator *op, con */ case MIDDLEMOUSE: case MOUSEMOVE: - //pld->redraw = PL_PREVIEW_REDRAWHEADER; + // pld->redraw = PL_PREVIEW_REDRAWHEADER; ret = OPERATOR_PASS_THROUGH; break; @@ -1556,7 +1610,7 @@ static int poselib_preview_handle_event(bContext *UNUSED(C), wmOperator *op, con } else { /* view manipulation (see above) */ - //pld->redraw = PL_PREVIEW_REDRAWHEADER; + // pld->redraw = PL_PREVIEW_REDRAWHEADER; ret = OPERATOR_PASS_THROUGH; } break; @@ -1592,12 +1646,15 @@ static void poselib_preview_init_data(bContext *C, wmOperator *op) pld->sa = CTX_wm_area(C); /* get starting pose based on RNA-props for this operator */ - if (pose_index == -1) + if (pose_index == -1) { pld->marker = poselib_get_active_pose(pld->act); - else if (pose_index == -2) + } + else if (pose_index == -2) { pld->flag |= PL_PREVIEW_SHOWORIGINAL; - else + } + else { pld->marker = (pld->act) ? BLI_findlink(&pld->act->markers, pose_index) : NULL; + } /* check if valid poselib */ if (ELEM(NULL, pld->ob, pld->pose, pld->arm)) { @@ -1614,8 +1671,9 @@ static void poselib_preview_init_data(bContext *C, wmOperator *op) if (pld->act->markers.first) { /* just use first one then... */ pld->marker = pld->act->markers.first; - if (pose_index > -2) + if (pose_index > -2) { BKE_report(op->reports, RPT_WARNING, "Pose lib had no active pose"); + } } else { BKE_report(op->reports, RPT_ERROR, "Pose lib has no poses to preview/apply"); @@ -1670,10 +1728,12 @@ static void poselib_preview_cleanup(bContext *C, wmOperator *op) /* old optimize trick... this enforces to bypass the depgraph * - note: code copied from transform_generics.c -> recalcData() */ - if ((arm->flag & ARM_DELAYDEFORM) == 0) + if ((arm->flag & ARM_DELAYDEFORM) == 0) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); /* sets recalc flags */ - else + } + else { BKE_pose_where_is(CTX_data_depsgraph(C), scene, ob); + } } else if (pld->state == PL_PREVIEW_CONFIRM) { /* tag poses as appropriate */ @@ -1688,10 +1748,11 @@ static void poselib_preview_cleanup(bContext *C, wmOperator *op) /* updates */ if (IS_AUTOKEY_MODE(scene, NORMAL)) { - //remake_action_ipos(ob->action); + // remake_action_ipos(ob->action); } - else + else { BKE_pose_where_is(CTX_data_depsgraph(C), scene, ob); + } } /* Request final redraw of the view. */ @@ -1715,10 +1776,12 @@ static int poselib_preview_exit(bContext *C, wmOperator *op) /* finish up */ poselib_preview_cleanup(C, op); - if (ELEM(exit_state, PL_PREVIEW_CANCEL, PL_PREVIEW_ERROR)) + if (ELEM(exit_state, PL_PREVIEW_CANCEL, PL_PREVIEW_ERROR)) { return OPERATOR_CANCELLED; - else + } + else { return OPERATOR_FINISHED; + } } /* Cancel previewing operation (called when exiting Blender) */ @@ -1734,15 +1797,17 @@ static int poselib_preview_modal(bContext *C, wmOperator *op, const wmEvent *eve int ret; /* 1) check state to see if we're still running */ - if (pld->state != PL_PREVIEW_RUNNING) + if (pld->state != PL_PREVIEW_RUNNING) { return poselib_preview_exit(C, op); + } /* 2) handle events */ ret = poselib_preview_handle_event(C, op, event); /* 3) apply changes and redraw, otherwise, confirming goes wrong */ - if (pld->redraw) + if (pld->redraw) { poselib_preview_apply(C, op); + } return ret; } @@ -1834,9 +1899,15 @@ void POSELIB_OT_browse_interactive(wmOperatorType *ot) // XXX: percentage vs factor? /* not used yet */ #if 0 - RNA_def_float_factor( - ot->srna, "blend_factor", 1.0f, 0.0f, 1.0f, "Blend Factor", - "Amount that the pose is applied on top of the existing poses", 0.0f, 1.0f); + RNA_def_float_factor(ot->srna, + "blend_factor", + 1.0f, + 0.0f, + 1.0f, + "Blend Factor", + "Amount that the pose is applied on top of the existing poses", + 0.0f, + 1.0f); #endif } diff --git a/source/blender/editors/armature/pose_select.c b/source/blender/editors/armature/pose_select.c index b825d821fe8..e9ea49aaf03 100644 --- a/source/blender/editors/armature/pose_select.c +++ b/source/blender/editors/armature/pose_select.c @@ -71,8 +71,9 @@ static void pose_do_bone_select(bPoseChannel *pchan, const int select_mode) /* select pchan only if selectable, but deselect works always */ switch (select_mode) { case SEL_SELECT: - if (!(pchan->bone->flag & BONE_UNSELECTABLE)) + if (!(pchan->bone->flag & BONE_UNSELECTABLE)) { pchan->bone->flag |= BONE_SELECTED; + } break; case SEL_DESELECT: pchan->bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); @@ -110,8 +111,9 @@ void ED_pose_bone_select(Object *ob, bPoseChannel *pchan, bool select) /* sanity checks */ // XXX: actually, we can probably still get away with no object - at most we have no updates - if (ELEM(NULL, ob, ob->pose, pchan, pchan->bone)) + if (ELEM(NULL, ob, ob->pose, pchan, pchan->bone)) { return; + } arm = ob->data; @@ -147,8 +149,9 @@ bool ED_armature_pose_select_pick_with_buffer(ViewLayer *view_layer, Object *ob = base->object; Bone *nearBone; - if (!ob || !ob->pose) + if (!ob || !ob->pose) { return 0; + } Object *ob_act = OBACT(view_layer); Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); @@ -346,16 +349,20 @@ static void selectconnected_posebonechildren(Object *ob, Bone *bone, int extend) Bone *curBone; /* stop when unconnected child is encountered, or when unselectable bone is encountered */ - if (!(bone->flag & BONE_CONNECTED) || (bone->flag & BONE_UNSELECTABLE)) + if (!(bone->flag & BONE_CONNECTED) || (bone->flag & BONE_UNSELECTABLE)) { return; + } - if (extend) + if (extend) { bone->flag &= ~BONE_SELECTED; - else + } + else { bone->flag |= BONE_SELECTED; + } - for (curBone = bone->childbase.first; curBone; curBone = curBone->next) + for (curBone = bone->childbase.first; curBone; curBone = curBone->next) { selectconnected_posebonechildren(ob, curBone, extend); + } } /* within active object context */ @@ -370,30 +377,37 @@ static int pose_select_connected_invoke(bContext *C, wmOperator *op, const wmEve Base *base = NULL; bone = get_nearest_bone(C, event->mval, !extend, &base); - if (!bone) + if (!bone) { return OPERATOR_CANCELLED; + } /* Select parents */ for (curBone = bone; curBone; curBone = next) { /* ignore bone if cannot be selected */ if ((curBone->flag & BONE_UNSELECTABLE) == 0) { - if (extend) + if (extend) { curBone->flag &= ~BONE_SELECTED; - else + } + else { curBone->flag |= BONE_SELECTED; + } - if (curBone->flag & BONE_CONNECTED) + if (curBone->flag & BONE_CONNECTED) { next = curBone->parent; - else + } + else { next = NULL; + } } - else + else { next = NULL; + } } /* Select children */ - for (curBone = bone->childbase.first; curBone; curBone = next) + for (curBone = bone->childbase.first; curBone; curBone = next) { selectconnected_posebonechildren(base->object, curBone, extend); + } ED_pose_bone_select_tag_update(base->object); @@ -444,8 +458,7 @@ static int pose_de_select_all_exec(bContext *C, wmOperator *op) Object *ob_prev = NULL; /* Set the flags */ - CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob) - { + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob) { bArmature *arm = ob->data; pose_do_bone_select(pchan, action); @@ -558,16 +571,18 @@ static int pose_select_constraint_target_exec(bContext *C, wmOperator *UNUSED(op } } - if (cti->flush_constraint_targets) + if (cti->flush_constraint_targets) { cti->flush_constraint_targets(con, &targets, 1); + } } } } } CTX_DATA_END; - if (!found) + if (!found) { return OPERATOR_CANCELLED; + } return OPERATOR_FINISHED; } @@ -741,8 +756,7 @@ static bool pose_select_same_group(bContext *C, bool extend) group_flags = NULL; ob_index = -1; ob_prev = NULL; - CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, visible_pose_bones, Object, *ob) - { + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, visible_pose_bones, Object, *ob) { if (ob != ob_prev) { ob_index++; group_flags = group_flags_array + (ob_index * groups_len); @@ -768,8 +782,7 @@ static bool pose_select_same_group(bContext *C, bool extend) ob_index = -1; ob_prev = NULL; /* only if group matches (and is not selected or current bone) */ - CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob) - { + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob) { if (ob != ob_prev) { ob_index++; group_flags = group_flags_array + (ob_index * groups_len); @@ -824,20 +837,21 @@ static bool pose_select_same_layer(bContext *C, bool extend) layers = NULL; ob_prev = NULL; ob_index = -1; - CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob) - { + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob) { if (ob != ob_prev) { layers = &layers_array[++ob_index]; ob_prev = ob; } /* Keep track of layers to use later? */ - if (pchan->bone->flag & BONE_SELECTED) + if (pchan->bone->flag & BONE_SELECTED) { *layers |= pchan->bone->layer; + } /* Deselect all bones before selecting new ones? */ - if ((extend == false) && (pchan->bone->flag & BONE_UNSELECTABLE) == 0) + if ((extend == false) && (pchan->bone->flag & BONE_UNSELECTABLE) == 0) { pchan->bone->flag &= ~BONE_SELECTED; + } } CTX_DATA_END; @@ -856,8 +870,7 @@ static bool pose_select_same_layer(bContext *C, bool extend) /* Select bones that are on same layers as layers flag. */ ob_prev = NULL; ob_index = -1; - CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob) - { + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob) { if (ob != ob_prev) { layers = &layers_array[++ob_index]; ob_prev = ob; @@ -917,8 +930,9 @@ static bool pose_select_same_keyingset(bContext *C, ReportList *reports, bool ex /* if not extending selection, deselect all selected first */ if (extend == false) { CTX_DATA_BEGIN (C, bPoseChannel *, pchan, visible_pose_bones) { - if ((pchan->bone->flag & BONE_UNSELECTABLE) == 0) + if ((pchan->bone->flag & BONE_UNSELECTABLE) == 0) { pchan->bone->flag &= ~BONE_SELECTED; + } } CTX_DATA_END; } @@ -982,8 +996,9 @@ static int pose_select_grouped_exec(bContext *C, wmOperator *op) bool changed = false; /* sanity check */ - if (ob->pose == NULL) + if (ob->pose == NULL) { return OPERATOR_CANCELLED; + } /* selection types */ switch (type) { @@ -1005,10 +1020,12 @@ static int pose_select_grouped_exec(bContext *C, wmOperator *op) } /* report done status */ - if (changed) + if (changed) { return OPERATOR_FINISHED; - else + } + else { return OPERATOR_CANCELLED; + } } void POSE_OT_select_grouped(wmOperatorType *ot) diff --git a/source/blender/editors/armature/pose_slide.c b/source/blender/editors/armature/pose_slide.c index cb9cfa64181..d683c599f7b 100644 --- a/source/blender/editors/armature/pose_slide.c +++ b/source/blender/editors/armature/pose_slide.c @@ -335,12 +335,6 @@ static void pose_slide_apply_val(tPoseSlideOp *pso, FCurve *fcu, Object *ob, flo /* next/end */ eVal = evaluate_fcurve(fcu, nextFrameF); - /* if both values are equal, don't do anything */ - if (IS_EQF(sVal, eVal)) { - (*val) = sVal; - return; - } - /* calculate the relative weights of the endpoints */ if (pso->mode == POSESLIDE_BREAKDOWN) { /* get weights from the percentage control */ @@ -362,9 +356,10 @@ static void pose_slide_apply_val(tPoseSlideOp *pso, FCurve *fcu, Object *ob, flo w2 = (w2 / wtot); } - /* depending on the mode, calculate the new value - * - in all of these, the start+end values are multiplied by w2 and w1 (respectively), - * since multiplication in another order would decrease the value the current frame is closer to + /* Depending on the mode, calculate the new value: + * - In all of these, the start+end values are multiplied by w2 and w1 (respectively), + * since multiplication in another order would decrease + * the value the current frame is closer to. */ switch (pso->mode) { case POSESLIDE_PUSH: /* make the current pose more pronounced */ @@ -397,7 +392,8 @@ static void pose_slide_apply_val(tPoseSlideOp *pso, FCurve *fcu, Object *ob, flo } case POSESLIDE_BREAKDOWN: /* make the current pose slide around between the endpoints */ { - /* perform simple linear interpolation - coefficient for start must come from pso->percentage... */ + /* Perform simple linear interpolation - + * coefficient for start must come from pso->percentage. */ /* TODO: make this use some kind of spline interpolation instead? */ (*val) = ((sVal * w2) + (eVal * w1)); break; @@ -458,8 +454,9 @@ static void pose_slide_apply_props(tPoseSlideOp *pso, FCurve *fcu = (FCurve *)ld->data; const char *bPtr, *pPtr; - if (fcu->rna_path == NULL) + if (fcu->rna_path == NULL) { continue; + } /* do we have a match? * - bPtr is the RNA Path with the standard part chopped off @@ -507,7 +504,7 @@ static void pose_slide_apply_props(tPoseSlideOp *pso, default: /* cannot handle */ - //printf("Cannot Pose Slide non-numerical property\n"); + // printf("Cannot Pose Slide non-numerical property\n"); break; } } @@ -583,7 +580,8 @@ static void pose_slide_apply_quat(tPoseSlideOp *pso, tPChanFCurveLink *pfl) /* perform blending */ if (pso->mode == POSESLIDE_BREAKDOWN) { - /* just perform the interpol between quat_prev and quat_next using pso->percentage as a guide */ + /* Just perform the interpol between quat_prev and + * quat_next using pso->percentage as a guide. */ interp_qt_qtqt(quat_final, quat_prev, quat_next, pso->percentage); } else if (pso->mode == POSESLIDE_PUSH) { @@ -695,9 +693,8 @@ static void pose_slide_apply(bContext *C, tPoseSlideOp *pso) } if (ELEM(pso->channels, PS_TFM_ALL, PS_TFM_PROPS) && (pfl->oldprops)) { - /* not strictly a transform, but custom properties contribute to the pose produced in many rigs - * (e.g. the facial rigs used in Sintel) - */ + /* Not strictly a transform, but custom properties contribute + * to the pose produced in many rigs (e.g. the facial rigs used in Sintel). */ pose_slide_apply_props(pso, pfl, "[\""); /* dummy " for texteditor bugs */ } } @@ -979,35 +976,41 @@ static int pose_slide_modal(bContext *C, wmOperator *op, const wmEvent *event) case LEFTMOUSE: /* confirm */ case RETKEY: case PADENTER: { - /* return to normal cursor and header status */ - ED_area_status_text(pso->sa, NULL); - WM_cursor_modal_restore(win); + if (event->val == KM_PRESS) { + /* return to normal cursor and header status */ + ED_area_status_text(pso->sa, NULL); + WM_cursor_modal_restore(win); - /* insert keyframes as required... */ - pose_slide_autoKeyframe(C, pso); - pose_slide_exit(op); + /* insert keyframes as required... */ + pose_slide_autoKeyframe(C, pso); + pose_slide_exit(op); - /* done! */ - return OPERATOR_FINISHED; + /* done! */ + return OPERATOR_FINISHED; + } + break; } case ESCKEY: /* cancel */ case RIGHTMOUSE: { - /* return to normal cursor and header status */ - ED_area_status_text(pso->sa, NULL); - WM_cursor_modal_restore(win); + if (event->val == KM_PRESS) { + /* return to normal cursor and header status */ + ED_area_status_text(pso->sa, NULL); + WM_cursor_modal_restore(win); - /* reset transforms back to original state */ - pose_slide_reset(pso); + /* reset transforms back to original state */ + pose_slide_reset(pso); - /* depsgraph updates + redraws */ - pose_slide_refresh(C, pso); + /* depsgraph updates + redraws */ + pose_slide_refresh(C, pso); - /* clean up temp data */ - pose_slide_exit(op); + /* clean up temp data */ + pose_slide_exit(op); - /* canceled! */ - return OPERATOR_CANCELLED; + /* canceled! */ + return OPERATOR_CANCELLED; + } + break; } /* Percentage Chane... */ @@ -1109,7 +1112,8 @@ static int pose_slide_modal(bContext *C, wmOperator *op, const wmEvent *event) } } - /* perform pose updates - in response to some user action (e.g. pressing a key or moving the mouse) */ + /* Perform pose updates - in response to some user action + * (e.g. pressing a key or moving the mouse). */ if (do_pose_update) { /* update percentage indicator in header */ pose_slide_draw_status(pso); @@ -1158,8 +1162,8 @@ static void pose_slide_opdef_properties(wmOperatorType *ot) 1.0f, "Percentage", "Weighting factor for which keyframe is favored more", - 0.3, - 0.7); + 0.0, + 1.0); RNA_def_int(ot->srna, "prev_frame", @@ -1206,8 +1210,9 @@ static int pose_slide_push_invoke(bContext *C, wmOperator *op, const wmEvent *ev pose_slide_exit(op); return OPERATOR_CANCELLED; } - else + else { pso = op->customdata; + } /* initialise percentage so that it won't pop on first mouse move */ pose_slide_mouse_update_percentage(pso, op, event); @@ -1226,8 +1231,9 @@ static int pose_slide_push_exec(bContext *C, wmOperator *op) pose_slide_exit(op); return OPERATOR_CANCELLED; } - else + else { pso = op->customdata; + } /* do common exec work */ return pose_slide_exec_common(C, op, pso); @@ -1248,7 +1254,7 @@ void POSE_OT_push(wmOperatorType *ot) ot->poll = ED_operator_posemode; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA; /* Properties */ pose_slide_opdef_properties(ot); @@ -1266,8 +1272,9 @@ static int pose_slide_relax_invoke(bContext *C, wmOperator *op, const wmEvent *e pose_slide_exit(op); return OPERATOR_CANCELLED; } - else + else { pso = op->customdata; + } /* initialise percentage so that it won't pop on first mouse move */ pose_slide_mouse_update_percentage(pso, op, event); @@ -1286,8 +1293,9 @@ static int pose_slide_relax_exec(bContext *C, wmOperator *op) pose_slide_exit(op); return OPERATOR_CANCELLED; } - else + else { pso = op->customdata; + } /* do common exec work */ return pose_slide_exec_common(C, op, pso); @@ -1308,7 +1316,7 @@ void POSE_OT_relax(wmOperatorType *ot) ot->poll = ED_operator_posemode; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA; /* Properties */ pose_slide_opdef_properties(ot); @@ -1326,8 +1334,9 @@ static int pose_slide_breakdown_invoke(bContext *C, wmOperator *op, const wmEven pose_slide_exit(op); return OPERATOR_CANCELLED; } - else + else { pso = op->customdata; + } /* initialise percentage so that it won't pop on first mouse move */ pose_slide_mouse_update_percentage(pso, op, event); @@ -1346,8 +1355,9 @@ static int pose_slide_breakdown_exec(bContext *C, wmOperator *op) pose_slide_exit(op); return OPERATOR_CANCELLED; } - else + else { pso = op->customdata; + } /* do common exec work */ return pose_slide_exec_common(C, op, pso); @@ -1368,7 +1378,7 @@ void POSE_OT_breakdown(wmOperatorType *ot) ot->poll = ED_operator_posemode; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA; /* Properties */ pose_slide_opdef_properties(ot); @@ -1396,7 +1406,8 @@ typedef enum ePosePropagate_Termination { POSE_PROPAGATE_SELECTED_MARKERS, } ePosePropagate_Termination; -/* termination data needed for some modes - assumes only one of these entries will be needed at a time */ +/* Termination data needed for some modes - + * assumes only one of these entries will be needed at a time. */ typedef union tPosePropagate_ModeData { /* smart holds + before frame: frame number to stop on */ float end_frame; @@ -1561,15 +1572,17 @@ static void pose_propagate_fcurve( short first = 1; /* skip if no keyframes to edit */ - if ((fcu->bezt == NULL) || (fcu->totvert < 2)) + if ((fcu->bezt == NULL) || (fcu->totvert < 2)) { return; + } /* find the reference value from bones directly, which means that the user * doesn't need to firstly keyframe the pose (though this doesn't mean that * they can't either) */ - if (!pose_propagate_get_refVal(ob, fcu, &refVal)) + if (!pose_propagate_get_refVal(ob, fcu, &refVal)) { return; + } /* find the first keyframe to start propagating from * - if there's a keyframe on the current frame, we probably want to save this value there too @@ -1581,10 +1594,12 @@ static void pose_propagate_fcurve( if (mode != POSE_PROPAGATE_SELECTED_KEYS) { match = binarysearch_bezt_index(fcu->bezt, startFrame, fcu->totvert, &keyExists); - if (fcu->bezt[match].vec[1][0] < startFrame) + if (fcu->bezt[match].vec[1][0] < startFrame) { i = match + 1; - else + } + else { i = match; + } } else { /* selected - start from first keyframe */ @@ -1595,18 +1610,21 @@ static void pose_propagate_fcurve( /* additional termination conditions based on the operator 'mode' property go here... */ if (ELEM(mode, POSE_PROPAGATE_BEFORE_FRAME, POSE_PROPAGATE_SMART_HOLDS)) { /* stop if keyframe is outside the accepted range */ - if (bezt->vec[1][0] > modeData.end_frame) + if (bezt->vec[1][0] > modeData.end_frame) { break; + } } else if (mode == POSE_PROPAGATE_NEXT_KEY) { /* stop after the first keyframe has been processed */ - if (first == 0) + if (first == 0) { break; + } } else if (mode == POSE_PROPAGATE_LAST_KEY) { /* only affect this frame if it will be the last one */ - if (i != (fcu->totvert - 1)) + if (i != (fcu->totvert - 1)) { continue; + } } else if (mode == POSE_PROPAGATE_SELECTED_MARKERS) { /* only allow if there's a marker on this frame */ @@ -1614,18 +1632,21 @@ static void pose_propagate_fcurve( /* stop on matching marker if there is one */ for (ce = modeData.sel_markers.first; ce; ce = ce->next) { - if (ce->cfra == round_fl_to_int(bezt->vec[1][0])) + if (ce->cfra == round_fl_to_int(bezt->vec[1][0])) { break; + } } /* skip this keyframe if no marker */ - if (ce == NULL) + if (ce == NULL) { continue; + } } else if (mode == POSE_PROPAGATE_SELECTED_KEYS) { /* only allow if this keyframe is already selected - skip otherwise */ - if (BEZT_ISSEL_ANY(bezt) == 0) + if (BEZT_ISSEL_ANY(bezt) == 0) { continue; + } } /* just flatten handles, since values will now be the same either side... */ @@ -1656,7 +1677,8 @@ static int pose_propagate_exec(bContext *C, wmOperator *op) poseAnim_mapping_get(C, &pflinks); if (BLI_listbase_is_empty(&pflinks)) { - /* There is a change the reason the list is empty is that there is no valid object to propagate poses for. + /* There is a change the reason the list is empty is + * that there is no valid object to propagate poses for. * This is very unlikely though, so we focus on the most likely issue. */ BKE_report(op->reports, RPT_ERROR, "No keyframed poses to propagate to"); return OPERATOR_CANCELLED; @@ -1693,8 +1715,9 @@ static int pose_propagate_exec(bContext *C, wmOperator *op) /* free temp data */ poseAnim_mapping_free(&pflinks); - if (mode == POSE_PROPAGATE_SELECTED_MARKERS) + if (mode == POSE_PROPAGATE_SELECTED_MARKERS) { BLI_freelistN(&modeData.sel_markers); + } /* updates + notifiers */ FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob) { @@ -1760,7 +1783,7 @@ void POSE_OT_propagate(wmOperatorType *ot) ot->poll = ED_operator_posemode; /* XXX: needs selected bones! */ /* flag */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; /* properties */ /* TODO: add "fade out" control for tapering off amount of propagation as time goes by? */ diff --git a/source/blender/editors/armature/pose_transform.c b/source/blender/editors/armature/pose_transform.c index 3a4413f8c1d..6207d5412cf 100644 --- a/source/blender/editors/armature/pose_transform.c +++ b/source/blender/editors/armature/pose_transform.c @@ -102,8 +102,9 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op) EditBone *curbone; /* don't check if editmode (should be done by caller) */ - if (ob->type != OB_ARMATURE) + if (ob->type != OB_ARMATURE) { return OPERATOR_CANCELLED; + } if (BKE_object_obdata_is_libdata(ob)) { BKE_report(op->reports, RPT_ERROR, "Cannot apply pose to lib-linked armature"); return OPERATOR_CANCELLED; @@ -111,11 +112,12 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op) /* helpful warnings... */ /* TODO: add warnings to be careful about actions, applying deforms first, etc. */ - if (ob->adt && ob->adt->action) + if (ob->adt && ob->adt->action) { BKE_report(op->reports, RPT_WARNING, "Actions on this armature will be destroyed by this new rest pose as the " "transforms stored are relative to the old rest pose"); + } /* Get editbones of active armature to alter */ ED_armature_to_edit(arm); @@ -160,23 +162,26 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op) */ if (pchan->bone->segments > 1) { /* combine rest/pose values */ - curbone->curveInX += pchan_eval->curveInX; - curbone->curveInY += pchan_eval->curveInY; - curbone->curveOutX += pchan_eval->curveOutX; - curbone->curveOutY += pchan_eval->curveOutY; + curbone->curve_in_x += pchan_eval->curve_in_x; + curbone->curve_in_y += pchan_eval->curve_in_y; + curbone->curve_out_x += pchan_eval->curve_out_x; + curbone->curve_out_y += pchan_eval->curve_out_y; curbone->roll1 += pchan_eval->roll1; curbone->roll2 += pchan_eval->roll2; curbone->ease1 += pchan_eval->ease1; curbone->ease2 += pchan_eval->ease2; - curbone->scaleIn += pchan_eval->scaleIn; - curbone->scaleOut += pchan_eval->scaleOut; + curbone->scale_in_x *= pchan_eval->scale_in_x; + curbone->scale_in_y *= pchan_eval->scale_in_y; + curbone->scale_out_x *= pchan_eval->scale_out_x; + curbone->scale_out_y *= pchan_eval->scale_out_y; /* reset pose values */ - pchan->curveInX = pchan->curveOutX = 0.0f; - pchan->curveInY = pchan->curveOutY = 0.0f; + pchan->curve_in_x = pchan->curve_out_x = 0.0f; + pchan->curve_in_y = pchan->curve_out_y = 0.0f; pchan->roll1 = pchan->roll2 = 0.0f; pchan->ease1 = pchan->ease2 = 0.0f; - pchan->scaleIn = pchan->scaleOut = 1.0f; + pchan->scale_in_x = pchan->scale_in_y = 1.0f; + pchan->scale_out_x = pchan->scale_out_y = 1.0f; } /* clear transform values for pchan */ @@ -244,8 +249,9 @@ static int pose_visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op)) * new raw-transform components, don't recalc the poses yet, otherwise IK result will * change, thus changing the result we may be trying to record. */ - /* XXX For some reason, we can't use pchan->chan_mat here, gives odd rotation/offset (see T38251). - * Using pchan->pose_mat and bringing it back in bone space seems to work as expected! + /* XXX For some reason, we can't use pchan->chan_mat here, gives odd rotation/offset + * (see T38251). + * Using pchan->pose_mat and bringing it back in bone space seems to work as expected! */ BKE_armature_mat_pose_to_bone(pchan_eval, pchan_eval->pose_mat, delta_mat); @@ -292,10 +298,12 @@ static void set_pose_keys(Object *ob) if (ob->pose) { for (chan = ob->pose->chanbase.first; chan; chan = chan->next) { Bone *bone = chan->bone; - if ((bone) && (bone->flag & BONE_SELECTED) && (arm->layer & bone->layer)) + if ((bone) && (bone->flag & BONE_SELECTED) && (arm->layer & bone->layer)) { chan->flag |= POSE_KEY; - else + } + else { chan->flag &= ~POSE_KEY; + } } } } @@ -319,21 +327,26 @@ static bPoseChannel *pose_bone_do_paste(Object *ob, short paste_ok; /* get the name - if flipping, we must flip this first */ - if (flip) + if (flip) { BLI_string_flip_side_name(name, chan->name, false, sizeof(name)); - else + } + else { BLI_strncpy(name, chan->name, sizeof(name)); + } /* only copy when: * 1) channel exists - poses are not meant to add random channels to anymore - * 2) if selection-masking is on, channel is selected - only selected bones get pasted on, allowing making both sides symmetrical + * 2) if selection-masking is on, channel is selected - + * only selected bones get pasted on, allowing making both sides symmetrical. */ pchan = BKE_pose_channel_find_name(ob->pose, name); - if (selOnly) + if (selOnly) { paste_ok = ((pchan) && (pchan->bone->flag & BONE_SELECTED)); - else + } + else { paste_ok = (pchan != NULL); + } /* continue? */ if (paste_ok) { @@ -360,45 +373,53 @@ static bPoseChannel *pose_bone_do_paste(Object *ob, } else if (pchan->rotmode > 0) { /* quat/axis-angle to euler */ - if (chan->rotmode == ROT_MODE_AXISANGLE) + if (chan->rotmode == ROT_MODE_AXISANGLE) { axis_angle_to_eulO(pchan->eul, pchan->rotmode, chan->rotAxis, chan->rotAngle); - else + } + else { quat_to_eulO(pchan->eul, pchan->rotmode, chan->quat); + } } else if (pchan->rotmode == ROT_MODE_AXISANGLE) { /* quat/euler to axis angle */ - if (chan->rotmode > 0) + if (chan->rotmode > 0) { eulO_to_axis_angle(pchan->rotAxis, &pchan->rotAngle, chan->eul, chan->rotmode); - else + } + else { quat_to_axis_angle(pchan->rotAxis, &pchan->rotAngle, chan->quat); + } } else { /* euler/axis-angle to quat */ - if (chan->rotmode > 0) + if (chan->rotmode > 0) { eulO_to_quat(pchan->quat, chan->eul, chan->rotmode); - else + } + else { axis_angle_to_quat(pchan->quat, chan->rotAxis, pchan->rotAngle); + } } /* B-Bone posing options should also be included... */ - pchan->curveInX = chan->curveInX; - pchan->curveInY = chan->curveInY; - pchan->curveOutX = chan->curveOutX; - pchan->curveOutY = chan->curveOutY; + pchan->curve_in_x = chan->curve_in_x; + pchan->curve_in_y = chan->curve_in_y; + pchan->curve_out_x = chan->curve_out_x; + pchan->curve_out_y = chan->curve_out_y; pchan->roll1 = chan->roll1; pchan->roll2 = chan->roll2; pchan->ease1 = chan->ease1; pchan->ease2 = chan->ease2; - pchan->scaleIn = chan->scaleIn; - pchan->scaleOut = chan->scaleOut; + pchan->scale_in_x = chan->scale_in_x; + pchan->scale_in_y = chan->scale_in_y; + pchan->scale_out_x = chan->scale_out_x; + pchan->scale_out_y = chan->scale_out_y; /* paste flipped pose? */ if (flip) { pchan->loc[0] *= -1; - pchan->curveInX *= -1; - pchan->curveOutX *= -1; + pchan->curve_in_x *= -1; + pchan->curve_out_x *= -1; pchan->roll1 *= -1; // XXX? pchan->roll2 *= -1; // XXX? @@ -626,28 +647,34 @@ void POSE_OT_paste(wmOperatorType *ot) /* clear scale of pose-channel */ static void pchan_clear_scale(bPoseChannel *pchan) { - if ((pchan->protectflag & OB_LOCK_SCALEX) == 0) + if ((pchan->protectflag & OB_LOCK_SCALEX) == 0) { pchan->size[0] = 1.0f; - if ((pchan->protectflag & OB_LOCK_SCALEY) == 0) + } + if ((pchan->protectflag & OB_LOCK_SCALEY) == 0) { pchan->size[1] = 1.0f; - if ((pchan->protectflag & OB_LOCK_SCALEZ) == 0) + } + if ((pchan->protectflag & OB_LOCK_SCALEZ) == 0) { pchan->size[2] = 1.0f; + } pchan->ease1 = 0.0f; pchan->ease2 = 0.0f; - pchan->scaleIn = 1.0f; - pchan->scaleOut = 1.0f; + pchan->scale_in_x = pchan->scale_in_y = 1.0f; + pchan->scale_out_x = pchan->scale_out_y = 1.0f; } /* clear location of pose-channel */ static void pchan_clear_loc(bPoseChannel *pchan) { - if ((pchan->protectflag & OB_LOCK_LOCX) == 0) + if ((pchan->protectflag & OB_LOCK_LOCX) == 0) { pchan->loc[0] = 0.0f; - if ((pchan->protectflag & OB_LOCK_LOCY) == 0) + } + if ((pchan->protectflag & OB_LOCK_LOCY) == 0) { pchan->loc[1] = 0.0f; - if ((pchan->protectflag & OB_LOCK_LOCZ) == 0) + } + if ((pchan->protectflag & OB_LOCK_LOCZ) == 0) { pchan->loc[2] = 0.0f; + } } /* clear rotation of pose-channel */ @@ -658,38 +685,51 @@ static void pchan_clear_rot(bPoseChannel *pchan) if (pchan->protectflag & OB_LOCK_ROT4D) { /* perform clamping on a component by component basis */ if (pchan->rotmode == ROT_MODE_AXISANGLE) { - if ((pchan->protectflag & OB_LOCK_ROTW) == 0) + if ((pchan->protectflag & OB_LOCK_ROTW) == 0) { pchan->rotAngle = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTX) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTX) == 0) { pchan->rotAxis[0] = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTY) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTY) == 0) { pchan->rotAxis[1] = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTZ) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTZ) == 0) { pchan->rotAxis[2] = 0.0f; + } - /* check validity of axis - axis should never be 0,0,0 (if so, then we make it rotate about y) */ + /* check validity of axis - axis should never be 0,0,0 + * (if so, then we make it rotate about y). */ if (IS_EQF(pchan->rotAxis[0], pchan->rotAxis[1]) && - IS_EQF(pchan->rotAxis[1], pchan->rotAxis[2])) + IS_EQF(pchan->rotAxis[1], pchan->rotAxis[2])) { pchan->rotAxis[1] = 1.0f; + } } else if (pchan->rotmode == ROT_MODE_QUAT) { - if ((pchan->protectflag & OB_LOCK_ROTW) == 0) + if ((pchan->protectflag & OB_LOCK_ROTW) == 0) { pchan->quat[0] = 1.0f; - if ((pchan->protectflag & OB_LOCK_ROTX) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTX) == 0) { pchan->quat[1] = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTY) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTY) == 0) { pchan->quat[2] = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTZ) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTZ) == 0) { pchan->quat[3] = 0.0f; + } } else { /* the flag may have been set for the other modes, so just ignore the extra flag... */ - if ((pchan->protectflag & OB_LOCK_ROTX) == 0) + if ((pchan->protectflag & OB_LOCK_ROTX) == 0) { pchan->eul[0] = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTY) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTY) == 0) { pchan->eul[1] = 0.0f; - if ((pchan->protectflag & OB_LOCK_ROTZ) == 0) + } + if ((pchan->protectflag & OB_LOCK_ROTZ) == 0) { pchan->eul[2] = 0.0f; + } } } else { @@ -710,12 +750,15 @@ static void pchan_clear_rot(bPoseChannel *pchan) eul[0] = eul[1] = eul[2] = 0.0f; - if (pchan->protectflag & OB_LOCK_ROTX) + if (pchan->protectflag & OB_LOCK_ROTX) { eul[0] = oldeul[0]; - if (pchan->protectflag & OB_LOCK_ROTY) + } + if (pchan->protectflag & OB_LOCK_ROTY) { eul[1] = oldeul[1]; - if (pchan->protectflag & OB_LOCK_ROTZ) + } + if (pchan->protectflag & OB_LOCK_ROTZ) { eul[2] = oldeul[2]; + } if (pchan->rotmode == ROT_MODE_QUAT) { eul_to_quat(pchan->quat, eul); @@ -755,10 +798,10 @@ static void pchan_clear_rot(bPoseChannel *pchan) pchan->roll1 = 0.0f; pchan->roll2 = 0.0f; - pchan->curveInX = 0.0f; - pchan->curveInY = 0.0f; - pchan->curveOutX = 0.0f; - pchan->curveOutY = 0.0f; + pchan->curve_in_x = 0.0f; + pchan->curve_in_y = 0.0f; + pchan->curve_out_x = 0.0f; + pchan->curve_out_y = 0.0f; } /* clear loc/rot/scale of pose-channel */ diff --git a/source/blender/editors/armature/pose_utils.c b/source/blender/editors/armature/pose_utils.c index d8793bc2a1e..a1f763ac57d 100644 --- a/source/blender/editors/armature/pose_utils.c +++ b/source/blender/editors/armature/pose_utils.c @@ -91,14 +91,18 @@ static void fcurves_to_pchan_links_get(ListBase *pfLinks, BLI_addtail(pfLinks, pfl); /* set pchan's transform flags */ - if (transFlags & ACT_TRANS_LOC) + if (transFlags & ACT_TRANS_LOC) { pchan->flag |= POSE_LOC; - if (transFlags & ACT_TRANS_ROT) + } + if (transFlags & ACT_TRANS_ROT) { pchan->flag |= POSE_ROT; - if (transFlags & ACT_TRANS_SCALE) + } + if (transFlags & ACT_TRANS_SCALE) { pchan->flag |= POSE_SIZE; - if (transFlags & ACT_TRANS_BBONE) + } + if (transFlags & ACT_TRANS_BBONE) { pchan->flag |= POSE_BBONE_SHAPE; + } /* store current transforms */ copy_v3_v3(pfl->oldloc, pchan->loc); @@ -111,18 +115,21 @@ static void fcurves_to_pchan_links_get(ListBase *pfLinks, /* store current bbone values */ pfl->roll1 = pchan->roll1; pfl->roll2 = pchan->roll2; - pfl->curveInX = pchan->curveInX; - pfl->curveInY = pchan->curveInY; - pfl->curveOutX = pchan->curveOutX; - pfl->curveOutY = pchan->curveOutY; + pfl->curve_in_x = pchan->curve_in_x; + pfl->curve_in_y = pchan->curve_in_y; + pfl->curve_out_x = pchan->curve_out_x; + pfl->curve_out_y = pchan->curve_out_y; pfl->ease1 = pchan->ease1; pfl->ease2 = pchan->ease2; - pfl->scaleIn = pchan->scaleIn; - pfl->scaleOut = pchan->scaleOut; + pfl->scale_in_x = pchan->scale_in_x; + pfl->scale_in_y = pchan->scale_in_y; + pfl->scale_out_x = pchan->scale_out_x; + pfl->scale_out_y = pchan->scale_out_y; /* make copy of custom properties */ - if (pchan->prop && (transFlags & ACT_TRANS_PROP)) + if (pchan->prop && (transFlags & ACT_TRANS_PROP)) { pfl->oldprops = IDP_CopyProperty(pchan->prop); + } } } @@ -148,8 +155,7 @@ void poseAnim_mapping_get(bContext *C, ListBase *pfLinks) prev_ob = NULL; ob_pose_armature = NULL; - CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) - { + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) { if (ob != prev_ob) { prev_ob = ob; ob_pose_armature = poseAnim_object_get(ob); @@ -169,8 +175,7 @@ void poseAnim_mapping_get(bContext *C, ListBase *pfLinks) if (BLI_listbase_is_empty(pfLinks)) { prev_ob = NULL; ob_pose_armature = NULL; - CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob) - { + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob) { if (ob != prev_ob) { prev_ob = ob; ob_pose_armature = poseAnim_object_get(ob); @@ -215,22 +220,9 @@ void poseAnim_mapping_free(ListBase *pfLinks) /* ------------------------- */ /* helper for apply() / reset() - refresh the data */ -void poseAnim_mapping_refresh(bContext *C, Scene *scene, Object *ob) +void poseAnim_mapping_refresh(bContext *C, Scene *UNUSED(scene), Object *ob) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); - bArmature *arm = (bArmature *)ob->data; - - /* old optimize trick... this enforces to bypass the depgraph - * - note: code copied from transform_generics.c -> recalcData() - */ - /* FIXME: shouldn't this use the builtin stuff? */ - if ((arm->flag & ARM_DELAYDEFORM) == 0) - DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); /* sets recalc flags */ - else - BKE_pose_where_is(depsgraph, scene, ob); - - /* otherwise animation doesn't get updated */ - DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); + DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob); } @@ -254,18 +246,21 @@ void poseAnim_mapping_reset(ListBase *pfLinks) /* store current bbone values */ pchan->roll1 = pfl->roll1; pchan->roll2 = pfl->roll2; - pchan->curveInX = pfl->curveInX; - pchan->curveInY = pfl->curveInY; - pchan->curveOutX = pfl->curveOutX; - pchan->curveOutY = pfl->curveOutY; + pchan->curve_in_x = pfl->curve_in_x; + pchan->curve_in_y = pfl->curve_in_y; + pchan->curve_out_x = pfl->curve_out_x; + pchan->curve_out_y = pfl->curve_out_y; pchan->ease1 = pfl->ease1; pchan->ease2 = pfl->ease2; - pchan->scaleIn = pfl->scaleIn; - pchan->scaleOut = pfl->scaleOut; + pchan->scale_in_x = pfl->scale_in_x; + pchan->scale_in_y = pfl->scale_in_y; + pchan->scale_out_x = pfl->scale_out_x; + pchan->scale_out_y = pfl->scale_out_y; /* just overwrite values of properties from the stored copies (there should be some) */ - if (pfl->oldprops) + if (pfl->oldprops) { IDP_SyncGroupValues(pfl->pchan->prop, pfl->oldprops); + } } } @@ -332,7 +327,7 @@ void poseAnim_mapping_autoKeyframe(bContext *C, Scene *scene, ListBase *pfLinks, FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob) { if (ob->id.tag & LIB_TAG_DOIT) { if (ob->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) { - //ED_pose_clear_paths(C, ob); // XXX for now, don't need to clear + // ED_pose_clear_paths(C, ob); // XXX for now, don't need to clear ED_pose_recalculate_paths(C, scene, ob, false); } } @@ -355,8 +350,9 @@ LinkData *poseAnim_mapping_getNextFCurve(ListBase *fcuLinks, LinkData *prev, con FCurve *fcu = (FCurve *)ld->data; /* check if paths match */ - if (STREQ(path, fcu->rna_path)) + if (STREQ(path, fcu->rna_path)) { return ld; + } } /* none found */ diff --git a/source/blender/editors/curve/CMakeLists.txt b/source/blender/editors/curve/CMakeLists.txt index 3df6f3c97d4..8c9309055c8 100644 --- a/source/blender/editors/curve/CMakeLists.txt +++ b/source/blender/editors/curve/CMakeLists.txt @@ -26,8 +26,8 @@ set(INC ../../makesrna ../../windowmanager ../../../../intern/clog - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ../../../../extern/curve_fit_nd ) diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c index 782b093fab4..3d2ac009072 100644 --- a/source/blender/editors/curve/curve_ops.c +++ b/source/blender/editors/curve/curve_ops.c @@ -147,7 +147,7 @@ void ED_operatormacros_curve(void) OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "CURVE_OT_duplicate"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); ot = WM_operatortype_append_macro("CURVE_OT_extrude_move", @@ -156,7 +156,7 @@ void ED_operatormacros_curve(void) OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "CURVE_OT_extrude"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); } diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index c37ce4cc89d..a787b45c13c 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -104,11 +104,13 @@ void printknots(Object *obedit) if (ED_curve_nurb_select_check(nu) && nu->type == CU_NURBS) { if (nu->knotsu) { num = KNOTSU(nu); - for (a = 0; a < num; a++) printf("knotu %d: %f\n", a, nu->knotsu[a]); + for (a = 0; a < num; a++) + printf("knotu %d: %f\n", a, nu->knotsu[a]); } if (nu->knotsv) { num = KNOTSV(nu); - for (a = 0; a < num; a++) printf("knotv %d: %f\n", a, nu->knotsv[a]); + for (a = 0; a < num; a++) + printf("knotv %d: %f\n", a, nu->knotsv[a]); } } } @@ -731,8 +733,8 @@ static void calc_shapeKeys(Object *obedit, ListBase *newnurbs) nu = editnurb->nurbs.first; /* We need to restore to original curve into newnurb, *not* editcurve's nurbs. - * Otherwise, in case we update obdata *without* leaving editmode (e.g. viewport render), we would - * invalidate editcurve. */ + * Otherwise, in case we update obdata *without* leaving editmode (e.g. viewport render), + * we would invalidate editcurve. */ newnu = newnurbs->first; i = 0; while (nu) { @@ -1273,9 +1275,10 @@ void ED_curve_editnurb_load(Main *bmain, Object *obedit) } } - /* We have to pass also new copied nurbs, since we want to restore original curve (without edited shapekey) - * on obdata, but *not* on editcurve itself (ED_curve_editnurb_load call does not always implies freeing - * of editcurve, e.g. when called to generate render data...). */ + /* We have to pass also new copied nurbs, since we want to restore original curve + * (without edited shapekey) on obdata, but *not* on editcurve itself + * (ED_curve_editnurb_load call does not always implies freeing + * of editcurve, e.g. when called to generate render data). */ calc_shapeKeys(obedit, &newnurb); cu->nurb = newnurb; @@ -2286,7 +2289,8 @@ static void adduplicateflagNurb( } else { if (ED_curve_nurb_select_check(v3d, nu)) { - /* a rectangular area in nurb has to be selected and if splitting must be in U or V direction */ + /* A rectangular area in nurb has to be selected and if splitting + * must be in U or V direction. */ usel = MEM_callocN(nu->pntsu, "adduplicateN3"); bp = nu->bp; for (a = 0; a < nu->pntsv; a++) { @@ -3724,7 +3728,8 @@ void CURVE_OT_subdivide(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, 1000, "Number of cuts", "", 1, 10); - /* avoid re-using last var because it can cause _very_ high poly meshes and annoy users (or worse crash) */ + /* Avoid re-using last var because it can cause _very_ high poly meshes + * and annoy users (or worse crash). */ RNA_def_property_flag(prop, PROP_SKIP_SAVE); } diff --git a/source/blender/editors/gizmo_library/CMakeLists.txt b/source/blender/editors/gizmo_library/CMakeLists.txt index 8b035d3207d..d9503c4e759 100644 --- a/source/blender/editors/gizmo_library/CMakeLists.txt +++ b/source/blender/editors/gizmo_library/CMakeLists.txt @@ -27,9 +27,9 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/eigen ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/gizmo_library/gizmo_geometry.h b/source/blender/editors/gizmo_library/gizmo_geometry.h index 42cb0c0bc1b..ae8ba3c411b 100644 --- a/source/blender/editors/gizmo_library/gizmo_geometry.h +++ b/source/blender/editors/gizmo_library/gizmo_geometry.h @@ -22,8 +22,9 @@ * * \name Gizmo Geometry * - * \brief Prototypes for arrays defining the gizmo geometry. The actual definitions can be found in files usually - * called geom_xxx_gizmo.c + * \brief Prototypes for arrays defining the gizmo geometry. + * The actual definitions can be found in files usually + * called geom_xxx_gizmo.c */ #ifndef __GIZMO_GEOMETRY_H__ diff --git a/source/blender/editors/gizmo_library/gizmo_library_utils.c b/source/blender/editors/gizmo_library/gizmo_library_utils.c index 2e5c3b37542..1f61c45eb80 100644 --- a/source/blender/editors/gizmo_library/gizmo_library_utils.c +++ b/source/blender/editors/gizmo_library/gizmo_library_utils.c @@ -68,9 +68,10 @@ float gizmo_offset_from_value(GizmoCommonData *data, const bool constrained, const bool inverted) { - if (constrained) + if (constrained) { return gizmo_offset_from_value_constr( data->range_fac, data->min, data->range, value, inverted); + } return value; } diff --git a/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c index 77658b8495e..780cca66fb9 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c @@ -573,8 +573,10 @@ static void cage2d_draw_circle_handles(const rctf *r, } if (transform_flag & ED_GIZMO_CAGE2D_XFORM_FLAG_ROTATE) { - const float handle[2] = {BLI_rctf_cent_x(r), - r->ymax + (margin[1] * GIZMO_MARGIN_OFFSET_SCALE)}; + const float handle[2] = { + BLI_rctf_cent_x(r), + r->ymax + (margin[1] * GIZMO_MARGIN_OFFSET_SCALE), + }; circle_fn(pos, handle[0], handle[1], rad[0], rad[1], resolu); } @@ -935,7 +937,8 @@ static int gizmo_cage2d_modal(bContext *C, } /* For transform logic to be manageable we operate in -0.5..0.5 2D space, * no matter the size of the rectangle, mouse coords are scaled to unit space. - * The mouse coords have been projected into the matrix so we don't need to worry about axis alignment. + * The mouse coords have been projected into the matrix + * so we don't need to worry about axis alignment. * * - The cursor offset are multiplied by 'dims'. * - Matrix translation is also multiplied by 'dims'. @@ -1115,8 +1118,9 @@ static void gizmo_cage2d_exit(bContext *C, wmGizmo *gz, const bool cancel) MEM_SAFE_FREE(data->dial); - if (!cancel) + if (!cancel) { return; + } wmGizmoProperty *gz_prop; diff --git a/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c index 3273012930a..e2a86469da1 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c @@ -338,10 +338,10 @@ static void gizmo_cage3d_draw_intern( else { #if 0 const rctf _r = { - .xmin = -size_real[0], - .ymin = -size_real[1], - .xmax = size_real[0], - .ymax = size_real[1], + .xmin = -size_real[0], + .ymin = -size_real[1], + .xmax = size_real[0], + .ymax = size_real[1], }; #endif if (draw_style == ED_GIZMO_CAGE2D_STYLE_BOX) { @@ -470,7 +470,8 @@ static int gizmo_cage3d_modal(bContext *C, } /* For transform logic to be manageable we operate in -0.5..0.5 2D space, * no matter the size of the rectangle, mouse coords are scaled to unit space. - * The mouse coords have been projected into the matrix so we don't need to worry about axis alignment. + * The mouse coords have been projected into the matrix + * so we don't need to worry about axis alignment. * * - The cursor offset are multiplied by 'dims'. * - Matrix translation is also multiplied by 'dims'. @@ -615,8 +616,9 @@ static void gizmo_cage3d_exit(bContext *C, wmGizmo *gz, const bool cancel) { RectTransformInteraction *data = gz->interaction_data; - if (!cancel) + if (!cancel) { return; + } wmGizmoProperty *gz_prop; diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt index 5573c88c710..21f1801f7eb 100644 --- a/source/blender/editors/gpencil/CMakeLists.txt +++ b/source/blender/editors/gpencil/CMakeLists.txt @@ -22,13 +22,13 @@ set(INC ../../blenlib ../../blentranslation ../../depsgraph - ../../imbuf ../../gpu + ../../imbuf ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/gpencil/annotate_draw.c b/source/blender/editors/gpencil/annotate_draw.c index a7fa51350ba..f325422fec7 100644 --- a/source/blender/editors/gpencil/annotate_draw.c +++ b/source/blender/editors/gpencil/annotate_draw.c @@ -91,22 +91,24 @@ typedef enum eDrawStrokeFlags { /* ----- Tool Buffer Drawing ------ */ /* draw stroke defined in buffer (simple ogl lines/points for now, as dotted lines) */ -static void gp_draw_stroke_buffer(const tGPspoint *points, - int totpoints, - short thickness, - short dflag, - short sflag, - float ink[4]) +static void annotation_draw_stroke_buffer(const tGPspoint *points, + int totpoints, + short thickness, + short dflag, + short sflag, + float ink[4]) { int draw_points = 0; /* error checking */ - if ((points == NULL) || (totpoints <= 0)) + if ((points == NULL) || (totpoints <= 0)) { return; + } /* check if buffer can be drawn */ - if (dflag & (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_ONLYV2D)) + if (dflag & (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_ONLYV2D)) { return; + } if (sflag & GP_STROKE_ERASER) { /* don't draw stroke at all! */ @@ -138,8 +140,9 @@ static void gp_draw_stroke_buffer(const tGPspoint *points, immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints); for (int i = 0; i < totpoints; i++, pt++) { - /* if there was a significant pressure change, stop the curve, change the thickness of the stroke, - * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP) + /* If there was a significant pressure change, + * stop the curve, change the thickness of the stroke, + * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP). */ if (fabsf(pt->pressure - oldpressure) > 0.2f) { /* need to have 2 points to avoid immEnd assert error */ @@ -178,7 +181,7 @@ static void gp_draw_stroke_buffer(const tGPspoint *points, /* --------- 2D Stroke Drawing Helpers --------- */ /* change in parameter list */ -static void gp_calc_2d_stroke_fxy( +static void annotation_calc_2d_stroke_fxy( const float pt[3], short sflag, int offsx, int offsy, int winx, int winy, float r_co[2]) { if (sflag & GP_STROKE_2DSPACE) { @@ -204,15 +207,15 @@ static void gp_calc_2d_stroke_fxy( /* ----- Existing Strokes Drawing (3D and Point) ------ */ /* draw a given stroke - just a single dot (only one point) */ -static void gp_draw_stroke_point(const bGPDspoint *points, - short thickness, - short UNUSED(dflag), - short sflag, - int offsx, - int offsy, - int winx, - int winy, - const float ink[4]) +static void annotation_draw_stroke_point(const bGPDspoint *points, + short thickness, + short UNUSED(dflag), + short sflag, + int offsx, + int offsy, + int winx, + int winy, + const float ink[4]) { const bGPDspoint *pt = points; @@ -231,7 +234,7 @@ static void gp_draw_stroke_point(const bGPDspoint *points, /* get 2D coordinates of point */ float co[3] = {0.0f}; - gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co); + annotation_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co); copy_v3_v3(fpt, co); } @@ -249,12 +252,12 @@ static void gp_draw_stroke_point(const bGPDspoint *points, } /* draw a given stroke in 3d (i.e. in 3d-space), using simple ogl lines */ -static void gp_draw_stroke_3d(const bGPDspoint *points, - int totpoints, - short thickness, - short UNUSED(sflag), - const float ink[4], - bool cyclic) +static void annotation_draw_stroke_3d(const bGPDspoint *points, + int totpoints, + short thickness, + short UNUSED(sflag), + const float ink[4], + bool cyclic) { float curpressure = points[0].pressure; float cyclic_fpt[3]; @@ -277,8 +280,9 @@ static void gp_draw_stroke_3d(const bGPDspoint *points, immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints + cyclic_add); const bGPDspoint *pt = points; for (int i = 0; i < totpoints; i++, pt++) { - /* if there was a significant pressure change, stop the curve, change the thickness of the stroke, - * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP) + /* If there was a significant pressure change, stop the curve, + * change the thickness of the stroke, and continue drawing again + * (since line-width cannot change in middle of GL_LINE_STRIP) * Note: we want more visible levels of pressures when thickness is bigger. */ if (fabsf(pt->pressure - curpressure) > 0.2f / (float)thickness) { @@ -332,16 +336,16 @@ static void gp_draw_stroke_3d(const bGPDspoint *points, /* ----- Fancy 2D-Stroke Drawing ------ */ /* draw a given stroke in 2d */ -static void gp_draw_stroke_2d(const bGPDspoint *points, - int totpoints, - short thickness_s, - short dflag, - short sflag, - int offsx, - int offsy, - int winx, - int winy, - const float ink[4]) +static void annotation_draw_stroke_2d(const bGPDspoint *points, + int totpoints, + short thickness_s, + short dflag, + short sflag, + int offsx, + int offsy, + int winx, + int winy, + const float ink[4]) { /* otherwise thickness is twice that of the 3D view */ float thickness = (float)thickness_s * 0.5f; @@ -352,8 +356,9 @@ static void gp_draw_stroke_2d(const bGPDspoint *points, scalefac = 0.001f; } - /* tessellation code - draw stroke as series of connected quads (triangle strips in fact) with connection - * edges rotated to minimize shrinking artifacts, and rounded endcaps + /* Tessellation code - draw stroke as series of connected quads + * (triangle strips in fact) with connection edges rotated to minimize shrinking artifacts, + * and rounded endcaps. */ { const bGPDspoint *pt1, *pt2; @@ -369,7 +374,7 @@ static void gp_draw_stroke_2d(const bGPDspoint *points, immBegin(GPU_PRIM_TRI_STRIP, totpoints * 2 + 4); /* get x and y coordinates from first point */ - gp_calc_2d_stroke_fxy(&points->x, sflag, offsx, offsy, winx, winy, s0); + annotation_calc_2d_stroke_fxy(&points->x, sflag, offsx, offsy, winx, winy, s0); for (i = 0, pt1 = points, pt2 = points + 1; i < (totpoints - 1); i++, pt1++, pt2++) { float t0[2], t1[2]; /* tessellated coordinates */ @@ -377,8 +382,9 @@ static void gp_draw_stroke_2d(const bGPDspoint *points, float mt[2], sc[2]; /* gradient for thickness, point for end-cap */ float pthick; /* thickness at segment point */ - /* get x and y coordinates from point2 (point1 has already been computed in previous iteration). */ - gp_calc_2d_stroke_fxy(&pt2->x, sflag, offsx, offsy, winx, winy, s1); + /* Get x and y coordinates from point2 + * (point1 has already been computed in previous iteration). */ + annotation_calc_2d_stroke_fxy(&pt2->x, sflag, offsx, offsy, winx, winy, s1); /* calculate gradient and normal - 'angle'=(ny/nx) */ m1[1] = s1[1] - s0[1]; @@ -507,52 +513,59 @@ static void gp_draw_stroke_2d(const bGPDspoint *points, /* ----- Strokes Drawing ------ */ /* Helper for doing all the checks on whether a stroke can be drawn */ -static bool gp_can_draw_stroke(const bGPDstroke *gps, const int dflag) +static bool annotation_can_draw_stroke(const bGPDstroke *gps, const int dflag) { /* skip stroke if it isn't in the right display space for this drawing context */ /* 1) 3D Strokes */ - if ((dflag & GP_DRAWDATA_ONLY3D) && !(gps->flag & GP_STROKE_3DSPACE)) + if ((dflag & GP_DRAWDATA_ONLY3D) && !(gps->flag & GP_STROKE_3DSPACE)) { return false; - if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE)) + } + if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE)) { return false; + } /* 2) Screen Space 2D Strokes */ - if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE)) + if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE)) { return false; - if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE)) + } + if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE)) { return false; + } /* 3) Image Space (2D) */ - if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE)) + if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE)) { return false; - if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE)) + } + if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE)) { return false; + } /* skip stroke if it doesn't have any valid data */ - if ((gps->points == NULL) || (gps->totpoints < 1)) + if ((gps->points == NULL) || (gps->totpoints < 1)) { return false; + } /* stroke can be drawn */ return true; } /* draw a set of strokes */ -static void gp_draw_strokes(bGPdata *UNUSED(gpd), - bGPDlayer *UNUSED(gpl), - const bGPDframe *gpf, - int offsx, - int offsy, - int winx, - int winy, - int dflag, - short lthick, - const float color[4]) +static void annotation_draw_strokes(bGPdata *UNUSED(gpd), + bGPDlayer *UNUSED(gpl), + const bGPDframe *gpf, + int offsx, + int offsy, + int winx, + int winy, + int dflag, + short lthick, + const float color[4]) { GPU_enable_program_point_size(); for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { /* check if stroke can be drawn */ - if (gp_can_draw_stroke(gps, dflag) == false) { + if (annotation_can_draw_stroke(gps, dflag) == false) { continue; } @@ -573,11 +586,11 @@ static void gp_draw_strokes(bGPdata *UNUSED(gpd), /* 3D Lines - OpenGL primitives-based */ if (gps->totpoints == 1) { - gp_draw_stroke_point( + annotation_draw_stroke_point( gps->points, lthick, dflag, gps->flag, offsx, offsy, winx, winy, color); } else { - gp_draw_stroke_3d( + annotation_draw_stroke_3d( gps->points, gps->totpoints, lthick, gps->flag, color, gps->flag & GP_STROKE_CYCLIC); } @@ -591,20 +604,20 @@ static void gp_draw_strokes(bGPdata *UNUSED(gpd), else { /* 2D Strokes... */ if (gps->totpoints == 1) { - gp_draw_stroke_point( + annotation_draw_stroke_point( gps->points, lthick, dflag, gps->flag, offsx, offsy, winx, winy, color); } else { - gp_draw_stroke_2d(gps->points, - gps->totpoints, - lthick, - dflag, - gps->flag, - offsx, - offsy, - winx, - winy, - color); + annotation_draw_stroke_2d(gps->points, + gps->totpoints, + lthick, + dflag, + gps->flag, + offsx, + offsy, + winx, + winy, + color); } } } @@ -613,20 +626,21 @@ static void gp_draw_strokes(bGPdata *UNUSED(gpd), } /* Draw selected verts for strokes being edited */ -static void gp_draw_strokes_edit(bGPdata *gpd, - bGPDlayer *gpl, - const bGPDframe *gpf, - int offsx, - int offsy, - int winx, - int winy, - short dflag, - short UNUSED(lflag), - float alpha) +static void annotation_draw_strokes_edit(bGPdata *gpd, + bGPDlayer *gpl, + const bGPDframe *gpf, + int offsx, + int offsy, + int winx, + int winy, + short dflag, + short UNUSED(lflag), + float alpha) { /* if alpha 0 do not draw */ - if (alpha == 0.0f) + if (alpha == 0.0f) { return; + } const bool no_xray = (dflag & GP_DRAWDATA_NO_XRAY) != 0; int mask_orig = 0; @@ -649,15 +663,17 @@ static void gp_draw_strokes_edit(bGPdata *gpd, /* draw stroke verts */ for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { /* check if stroke can be drawn */ - if (gp_can_draw_stroke(gps, dflag) == false) + if (annotation_can_draw_stroke(gps, dflag) == false) { continue; + } /* Optimisation: only draw points for selected strokes * We assume that selected points can only occur in * strokes that are selected too. */ - if ((gps->flag & GP_STROKE_SELECT) == 0) + if ((gps->flag & GP_STROKE_SELECT) == 0) { continue; + } /* Get size of verts: * - The selected state needs to be larger than the unselected state so that @@ -726,7 +742,7 @@ static void gp_draw_strokes_edit(bGPdata *gpd, } else { float co[2]; - gp_calc_2d_stroke_fxy(&pt->x, gps->flag, offsx, offsy, winx, winy, co); + annotation_calc_2d_stroke_fxy(&pt->x, gps->flag, offsx, offsy, winx, winy, co); immVertex2fv(pos, co); } } @@ -754,15 +770,15 @@ static void gp_draw_strokes_edit(bGPdata *gpd, /* ----- General Drawing ------ */ /* draw onion-skinning for a layer */ -static void gp_draw_onionskins(bGPdata *gpd, - bGPDlayer *gpl, - bGPDframe *gpf, - int offsx, - int offsy, - int winx, - int winy, - int UNUSED(cfra), - int dflag) +static void annotation_draw_onionskins(bGPdata *gpd, + bGPDlayer *gpl, + bGPDframe *gpf, + int offsx, + int offsy, + int winx, + int winy, + int UNUSED(cfra), + int dflag) { const float alpha = 1.0f; float color[4]; @@ -781,17 +797,20 @@ static void gp_draw_onionskins(bGPdata *gpd, /* alpha decreases with distance from curframe index */ fac = 1.0f - ((float)(gpf->framenum - gf->framenum) / (float)(gpl->gstep + 1)); color[3] = alpha * fac * 0.66f; - gp_draw_strokes(gpd, gpl, gf, offsx, offsy, winx, winy, dflag, gpl->thickness, color); + annotation_draw_strokes( + gpd, gpl, gf, offsx, offsy, winx, winy, dflag, gpl->thickness, color); } - else + else { break; + } } } else if (gpl->gstep == 0) { /* draw the strokes for the ghost frames (at half of the alpha set by user) */ if (gpf->prev) { color[3] = (alpha / 7); - gp_draw_strokes(gpd, gpl, gpf->prev, offsx, offsy, winx, winy, dflag, gpl->thickness, color); + annotation_draw_strokes( + gpd, gpl, gpf->prev, offsx, offsy, winx, winy, dflag, gpl->thickness, color); } } else { @@ -812,17 +831,20 @@ static void gp_draw_onionskins(bGPdata *gpd, /* alpha decreases with distance from curframe index */ fac = 1.0f - ((float)(gf->framenum - gpf->framenum) / (float)(gpl->gstep_next + 1)); color[3] = alpha * fac * 0.66f; - gp_draw_strokes(gpd, gpl, gf, offsx, offsy, winx, winy, dflag, gpl->thickness, color); + annotation_draw_strokes( + gpd, gpl, gf, offsx, offsy, winx, winy, dflag, gpl->thickness, color); } - else + else { break; + } } } else if (gpl->gstep_next == 0) { /* draw the strokes for the ghost frames (at half of the alpha set by user) */ if (gpf->next) { color[3] = (alpha / 4); - gp_draw_strokes(gpd, gpl, gpf->next, offsx, offsy, winx, winy, dflag, gpl->thickness, color); + annotation_draw_strokes( + gpd, gpl, gpf->next, offsx, offsy, winx, winy, dflag, gpl->thickness, color); } } else { @@ -831,7 +853,7 @@ static void gp_draw_onionskins(bGPdata *gpd, } /* loop over gpencil data layers, drawing them */ -static void gp_draw_data_layers( +static void annotation_draw_data_layers( bGPdata *gpd, int offsx, int offsy, int winx, int winy, int cfra, int dflag, float alpha) { float ink[4]; @@ -846,13 +868,15 @@ static void gp_draw_data_layers( ink[3] = gpl->opacity; /* don't draw layer if hidden */ - if (gpl->flag & GP_LAYER_HIDE) + if (gpl->flag & GP_LAYER_HIDE) { continue; + } /* get frame to draw */ bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra, GP_GETFRAME_USE_PREV); - if (gpf == NULL) + if (gpf == NULL) { continue; + } /* set basic stroke thickness */ GPU_line_width(lthick); @@ -867,23 +891,25 @@ static void gp_draw_data_layers( /* Draw 'onionskins' (frame left + right) */ if (gpl->onion_flag & GP_LAYER_ONIONSKIN) { - gp_draw_onionskins(gpd, gpl, gpf, offsx, offsy, winx, winy, cfra, dflag); + annotation_draw_onionskins(gpd, gpl, gpf, offsx, offsy, winx, winy, cfra, dflag); } /* draw the strokes already in active frame */ - gp_draw_strokes(gpd, gpl, gpf, offsx, offsy, winx, winy, dflag, lthick, ink); + annotation_draw_strokes(gpd, gpl, gpf, offsx, offsy, winx, winy, dflag, lthick, ink); - /* Draw verts of selected strokes + /* Draw verts of selected strokes: * - when doing OpenGL renders, we don't want to be showing these, as that ends up flickering * - locked layers can't be edited, so there's no point showing these verts * as they will have no bearings on what gets edited * - only show when in editmode, since operators shouldn't work otherwise - * (NOTE: doing it this way means that the toggling editmode shows visible change immediately) + * (NOTE: doing it this way means that the toggling editmode + * shows visible change immediately). */ /* XXX: perhaps we don't want to show these when users are drawing... */ if ((G.f & G_FLAG_RENDER_VIEWPORT) == 0 && (gpl->flag & GP_LAYER_LOCKED) == 0 && (gpd->flag & GP_DATA_STROKE_EDITMODE)) { - gp_draw_strokes_edit(gpd, gpl, gpf, offsx, offsy, winx, winy, dflag, gpl->flag, alpha); + annotation_draw_strokes_edit( + gpd, gpl, gpf, offsx, offsy, winx, winy, dflag, gpl->flag, alpha); } /* Check if may need to draw the active stroke cache, only if this layer is the active layer @@ -897,24 +923,25 @@ static void gp_draw_data_layers( * It should also be noted that sbuffer contains temporary point types * i.e. tGPspoints NOT bGPDspoints */ - gp_draw_stroke_buffer(gpd->runtime.sbuffer, - gpd->runtime.sbuffer_size, - lthick, - dflag, - gpd->runtime.sbuffer_sflag, - ink); + annotation_draw_stroke_buffer(gpd->runtime.sbuffer, + gpd->runtime.sbuffer_size, + lthick, + dflag, + gpd->runtime.sbuffer_sflag, + ink); } } } /* draw a short status message in the top-right corner */ -static void gp_draw_status_text(const bGPdata *gpd, ARegion *ar) +static void annotation_draw_status_text(const bGPdata *gpd, ARegion *ar) { rcti rect; /* Cannot draw any status text when drawing OpenGL Renders */ - if (G.f & G_FLAG_RENDER_VIEWPORT) + if (G.f & G_FLAG_RENDER_VIEWPORT) { return; + } /* Get bounds of region - Necessary to avoid problems with region overlap */ ED_region_visible_rect(ar, &rect); @@ -956,7 +983,7 @@ static void gp_draw_status_text(const bGPdata *gpd, ARegion *ar) } /* draw grease-pencil datablock */ -static void gp_draw_data( +static void annotation_draw_data( bGPdata *gpd, int offsx, int offsy, int winx, int winy, int cfra, int dflag, float alpha) { /* turn on smooth lines (i.e. anti-aliasing) */ @@ -968,7 +995,7 @@ static void gp_draw_data( GPU_blend(true); /* draw! */ - gp_draw_data_layers(gpd, offsx, offsy, winx, winy, cfra, dflag, alpha); + annotation_draw_data_layers(gpd, offsx, offsy, winx, winy, cfra, dflag, alpha); /* turn off alpha blending, then smooth lines */ GPU_blend(false); // alpha blending @@ -977,15 +1004,15 @@ static void gp_draw_data( /* if we have strokes for scenes (3d view)/clips (movie clip editor) * and objects/tracks, multiple data blocks have to be drawn */ -static void gp_draw_data_all(Scene *scene, - bGPdata *gpd, - int offsx, - int offsy, - int winx, - int winy, - int cfra, - int dflag, - const char spacetype) +static void annotation_draw_data_all(Scene *scene, + bGPdata *gpd, + int offsx, + int offsy, + int winx, + int winy, + int cfra, + int dflag, + const char spacetype) { bGPdata *gpd_source = NULL; float alpha = 1.0f; @@ -1001,14 +1028,14 @@ static void gp_draw_data_all(Scene *scene, } if (gpd_source) { - gp_draw_data(gpd_source, offsx, offsy, winx, winy, cfra, dflag, alpha); + annotation_draw_data(gpd_source, offsx, offsy, winx, winy, cfra, dflag, alpha); } } /* scene/clip data has already been drawn, only object/track data is drawn here * if gpd_source == gpd, we don't have any object/track data and we can skip */ if (gpd_source == NULL || (gpd_source && gpd_source != gpd)) { - gp_draw_data(gpd, offsx, offsy, winx, winy, cfra, dflag, alpha); + annotation_draw_data(gpd, offsx, offsy, winx, winy, cfra, dflag, alpha); } } @@ -1032,8 +1059,9 @@ void ED_annotation_draw_2dimage(const bContext *C) int dflag = GP_DRAWDATA_NOSTATUS; bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX - if (gpd == NULL) + if (gpd == NULL) { return; + } /* calculate rect */ switch (sa->spacetype) { @@ -1041,7 +1069,8 @@ void ED_annotation_draw_2dimage(const bContext *C) case SPACE_CLIP: /* clip */ { /* just draw using standard scaling (settings here are currently ignored anyways) */ - /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled */ + /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, + * so disabled. */ offsx = 0; offsy = 0; sizex = ar->winx; @@ -1083,12 +1112,16 @@ void ED_annotation_draw_2dimage(const bContext *C) } /* draw it! */ - gp_draw_data_all(scene, gpd, offsx, offsy, sizex, sizey, CFRA, dflag, sa->spacetype); + annotation_draw_data_all(scene, gpd, offsx, offsy, sizex, sizey, CFRA, dflag, sa->spacetype); } -/* draw grease-pencil sketches to specified 2d-view assuming that matrices are already set correctly - * Note: this gets called twice - first time with onlyv2d=true to draw 'canvas' strokes, - * second time with onlyv2d=false for screen-aligned strokes */ +/** + * Draw grease-pencil sketches to specified 2d-view + * assuming that matrices are already set correctly. + * + * \note This gets called twice - first time with onlyv2d=true to draw 'canvas' strokes, + * second time with onlyv2d=false for screen-aligned strokes. + */ void ED_annotation_draw_view2d(const bContext *C, bool onlyv2d) { wmWindowManager *wm = CTX_wm_manager(C); @@ -1098,28 +1131,34 @@ void ED_annotation_draw_view2d(const bContext *C, bool onlyv2d) int dflag = 0; /* check that we have grease-pencil stuff to draw */ - if (sa == NULL) + if (sa == NULL) { return; + } bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX - if (gpd == NULL) + if (gpd == NULL) { return; + } /* special hack for Image Editor */ - /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled */ - if (ELEM(sa->spacetype, SPACE_IMAGE, SPACE_CLIP)) + /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, + * so disabled. */ + if (ELEM(sa->spacetype, SPACE_IMAGE, SPACE_CLIP)) { dflag |= GP_DRAWDATA_IEDITHACK; + } /* draw it! */ - if (onlyv2d) + if (onlyv2d) { dflag |= (GP_DRAWDATA_ONLYV2D | GP_DRAWDATA_NOSTATUS); - if (ED_screen_animation_playing(wm)) + } + if (ED_screen_animation_playing(wm)) { dflag |= GP_DRAWDATA_NO_ONIONS; + } - gp_draw_data_all(scene, gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag, sa->spacetype); + annotation_draw_data_all(scene, gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag, sa->spacetype); /* draw status text (if in screen/pixel-space) */ if (!onlyv2d) { - gp_draw_status_text(gpd, ar); + annotation_draw_status_text(gpd, ar); } } @@ -1136,8 +1175,9 @@ void ED_annotation_draw_view3d( /* check that we have grease-pencil stuff to draw */ /* XXX: Hardcoded reference here may get out of sync if we change how we fetch annotation data */ bGPdata *gpd = scene->gpd; - if (gpd == NULL) + if (gpd == NULL) { return; + } /* when rendering to the offscreen buffer we don't want to * deal with the camera border, otherwise map the coords to the camera border. */ @@ -1172,7 +1212,7 @@ void ED_annotation_draw_view3d( } /* draw it! */ - gp_draw_data_all(scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype); + annotation_draw_data_all(scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype); } void ED_annotation_draw_ex( @@ -1180,7 +1220,7 @@ void ED_annotation_draw_ex( { int dflag = GP_DRAWDATA_NOSTATUS | GP_DRAWDATA_ONLYV2D; - gp_draw_data_all(scene, gpd, 0, 0, winx, winy, cfra, dflag, spacetype); + annotation_draw_data_all(scene, gpd, 0, 0, winx, winy, cfra, dflag, spacetype); } /* ************************************************** */ diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c index 4933f081790..73230e5fb0e 100644 --- a/source/blender/editors/gpencil/annotate_paint.c +++ b/source/blender/editors/gpencil/annotate_paint.c @@ -160,7 +160,8 @@ typedef struct tGPsdata { /* These need to be doubles, as (at least under unix) they are in seconds since epoch, * float (and its 7 digits precision) is definitively not enough here! - * double, with its 15 digits precision, ensures us millisecond precision for a few centuries at least. + * double, with its 15 digits precision, + * ensures us millisecond precision for a few centuries at least. */ /** Used when converting to path. */ double inittime; @@ -231,10 +232,12 @@ static bool gpencil_draw_poll(bContext *C) /* check if current context can support GPencil data */ if (ED_gpencil_data_get_pointers(C, NULL) != NULL) { /* check if Grease Pencil isn't already running */ - if (ED_gpencil_session_active() == 0) + if (ED_gpencil_session_active() == 0) { return true; - else + } + else { CTX_wm_operator_poll_msg_set(C, "Annotation operator is already active"); + } } else { CTX_wm_operator_poll_msg_set(C, "Failed to find Grease Pencil data to draw into"); @@ -278,25 +281,30 @@ static bool gp_stroke_filtermval(tGPsdata *p, const float mval[2], float pmval[2 int dy = (int)fabsf(mval[1] - pmval[1]); /* if buffer is empty, just let this go through (i.e. so that dots will work) */ - if (p->gpd->runtime.sbuffer_size == 0) + if (p->gpd->runtime.sbuffer_size == 0) { return true; - /* check if mouse moved at least certain distance on both axes (best case) - * - aims to eliminate some jitter-noise from input when trying to draw straight lines freehand - */ - else if ((dx > MIN_MANHATTEN_PX) && (dy > MIN_MANHATTEN_PX)) + /* check if mouse moved at least certain distance on both axes (best case) + * - aims to eliminate some jitter-noise from input when trying to draw straight lines freehand + */ + } + else if ((dx > MIN_MANHATTEN_PX) && (dy > MIN_MANHATTEN_PX)) { return true; - /* check if the distance since the last point is significant enough - * - prevents points being added too densely - * - distance here doesn't use sqrt to prevent slowness... we should still be safe from overflows though - */ - else if ((dx * dx + dy * dy) > MIN_EUCLIDEAN_PX * MIN_EUCLIDEAN_PX) + /* Check if the distance since the last point is significant enough: + * - Prevents points being added too densely + * - Distance here doesn't use sqrt to prevent slowness. + * We should still be safe from overflows though. + */ + } + else if ((dx * dx + dy * dy) > MIN_EUCLIDEAN_PX * MIN_EUCLIDEAN_PX) { return true; - /* mouse 'didn't move' */ - else + /* mouse 'didn't move' */ + } + else { return false; + } } /* convert screen-coordinates to buffer-coordinates */ @@ -465,8 +473,9 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure } else if (p->paintmode == GP_PAINTMODE_DRAW) { /* normal drawing */ /* check if still room in buffer */ - if (gpd->runtime.sbuffer_size >= GP_STROKE_BUFFER_MAX) + if (gpd->runtime.sbuffer_size >= GP_STROKE_BUFFER_MAX) { return GP_STROKEADD_OVERFLOW; + } /* get pointer to destination point */ pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_size); @@ -488,10 +497,12 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure } /* check if another operation can still occur */ - if (gpd->runtime.sbuffer_size == GP_STROKE_BUFFER_MAX) + if (gpd->runtime.sbuffer_size == GP_STROKE_BUFFER_MAX) { return GP_STROKEADD_FULL; - else + } + else { return GP_STROKEADD_NORMAL; + } } else if (p->paintmode == GP_PAINTMODE_DRAW_POLY) { /* get pointer to destination point */ @@ -546,8 +557,9 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure } /* increment counters */ - if (gpd->runtime.sbuffer_size == 0) + if (gpd->runtime.sbuffer_size == 0) { gpd->runtime.sbuffer_size++; + } return GP_STROKEADD_NORMAL; } @@ -569,12 +581,14 @@ static void gp_stroke_simplify(tGPsdata *p) short i, j; /* only simplify if simplification is enabled, and we're not doing a straight line */ - if (!(U.gp_settings & GP_PAINT_DOSIMPLIFY) || (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT)) + if (!(U.gp_settings & GP_PAINT_DOSIMPLIFY) || (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT)) { return; + } /* don't simplify if less than 4 points in buffer */ - if ((num_points <= 4) || (old_points == NULL)) + if ((num_points <= 4) || (old_points == NULL)) { return; + } /* clear buffer (but don't free mem yet) so that we can write to it * - firstly set sbuffer to NULL, so a new one is allocated @@ -646,22 +660,26 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) ToolSettings *ts = p->scene->toolsettings; int i, totelem; - /* since strokes are so fine, when using their depth we need a margin otherwise they might get missed */ + /* Since strokes are so fine, when using their depth we need a margin + * otherwise they might get missed. */ int depth_margin = (ts->annotate_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 4 : 0; /* get total number of points to allocate space for * - drawing straight-lines only requires the endpoints */ - if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) + if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) { totelem = (gpd->runtime.sbuffer_size >= 2) ? 2 : gpd->runtime.sbuffer_size; - else + } + else { totelem = gpd->runtime.sbuffer_size; + } /* exit with error if no valid points from this stroke */ if (totelem == 0) { - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: No valid points in stroke buffer to convert (tot=%d)\n", gpd->runtime.sbuffer_size); + } return; } @@ -770,8 +788,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) if (found_depth == false) { /* eeh... not much we can do.. :/, ignore depth in this case, use the 3D cursor */ - for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) + for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) { depth_arr[i] = 0.9999f; + } } else { if (ts->annotate_v3d_align & GP_PROJECT_DEPTH_STROKE_ENDPOINTS) { @@ -780,20 +799,23 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) int last_valid = 0; for (i = 0; i < gpd->runtime.sbuffer_size; i++) { - if (depth_arr[i] != FLT_MAX) + if (depth_arr[i] != FLT_MAX) { break; + } } first_valid = i; for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) { - if (depth_arr[i] != FLT_MAX) + if (depth_arr[i] != FLT_MAX) { break; + } } last_valid = i; /* invalidate non-endpoints, so only blend between first and last */ - for (i = first_valid + 1; i < last_valid; i++) + for (i = first_valid + 1; i < last_valid; i++) { depth_arr[i] = FLT_MAX; + } interp_depth = true; } @@ -819,8 +841,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) pt->time = ptc->time; } - if (depth_arr) + if (depth_arr) { MEM_freeN(depth_arr); + } } /* add stroke to frame */ @@ -946,8 +969,9 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p, pt2 = gps->points + i + 1; /* only process if it hasn't been masked out... */ - if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT)) + if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT)) { continue; + } gp_point_to_xy(&p->gsc, gps, pt1, &pc1[0], &pc1[1]); gp_point_to_xy(&p->gsc, gps, pt2, &pc2[0], &pc2[1]); @@ -1058,8 +1082,9 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p) /* make sure the active view (at the starting time) is a 3d-view */ if (curarea == NULL) { p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: No active view for painting\n"); + } return 0; } @@ -1088,10 +1113,11 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p) if (ar->regiondata == NULL) { p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf( "Error: 3D-View active region doesn't have any region data, so cannot be " "drawable\n"); + } return 0; } break; @@ -1118,8 +1144,9 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p) /* check that gpencil data is allowed to be drawn */ if (sseq->mainb == SEQ_DRAW_SEQUENCE) { p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: In active view (sequencer), active mode doesn't support Grease Pencil\n"); + } return 0; } break; @@ -1179,8 +1206,9 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p) /* unsupported views */ default: { p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: Annotations are not supported in this editor\n"); + } return 0; } } @@ -1189,8 +1217,9 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p) gpd_ptr = ED_gpencil_data_get_pointers(C, &p->ownerPtr); if ((gpd_ptr == NULL) || !ED_gpencil_data_owner_is_annotation(&p->ownerPtr)) { p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: Current context doesn't allow for any Annotation data\n"); + } return 0; } else { @@ -1254,8 +1283,9 @@ static void gp_session_cleanup(tGPsdata *p) bGPdata *gpd = (p) ? p->gpd : NULL; /* error checking */ - if (gpd == NULL) + if (gpd == NULL) { return; + } /* free stroke buffer */ if (gpd->runtime.sbuffer) { @@ -1288,13 +1318,15 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps p->gpd->flag |= GP_DATA_ANNOTATIONS; p->gpl = BKE_gpencil_layer_addnew(p->gpd, DATA_("Note"), true); - if (p->custom_color[3]) + if (p->custom_color[3]) { copy_v3_v3(p->gpl->color, p->custom_color); + } } if (p->gpl->flag & GP_LAYER_LOCKED) { p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: Cannot paint on locked layer\n"); + } return; } @@ -1329,7 +1361,7 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps if (has_layer_to_erase == false) { p->status = GP_STATUS_CAPTURE; - //if (G.debug & G_DEBUG) + // if (G.debug & G_DEBUG) printf("Error: Eraser will not be affecting anything (gpencil_paint_init)\n"); return; } @@ -1338,17 +1370,20 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps /* Drawing Modes - Add a new frame if needed on the active layer */ short add_frame_mode = GP_GETFRAME_ADD_NEW; - if (ts->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST) + if (ts->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST) { add_frame_mode = GP_GETFRAME_ADD_COPY; - else + } + else { add_frame_mode = GP_GETFRAME_ADD_NEW; + } p->gpf = BKE_gpencil_layer_getframe(p->gpl, CFRA, add_frame_mode); if (p->gpf == NULL) { p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: No frame created (gpencil_paint_init)\n"); + } return; } else { @@ -1471,8 +1506,9 @@ static void gp_paint_cleanup(tGPsdata *p) } /* "unlock" frame */ - if (p->gpf) + if (p->gpf) { p->gpf->flag &= ~GP_FRAME_PAINT; + } } /* ------------------------------- */ @@ -1508,14 +1544,13 @@ static void gpencil_draw_eraser(bContext *UNUSED(C), int x, int y, void *p_ptr) immUniform1f("dash_width", 12.0f); immUniform1f("dash_factor", 0.5f); - imm_draw_circle_wire_2d( - shdr_pos, - x, - y, - p->radius, - /* XXX Dashed shader gives bad results with sets of small segments currently, - * temp hack around the issue. :( */ - max_ii(8, p->radius / 2)); /* was fixed 40 */ + imm_draw_circle_wire_2d(shdr_pos, + x, + y, + p->radius, + /* XXX Dashed shader gives bad results with sets of small segments + * currently, temp hack around the issue. :( */ + max_ii(8, p->radius / 2)); /* was fixed 40 */ immUnbindProgram(); @@ -1634,10 +1669,12 @@ static int gpencil_draw_init(bContext *C, wmOperator *op, const wmEvent *event) /* ensure that the correct cursor icon is set */ static void gpencil_draw_cursor_set(tGPsdata *p) { - if (p->paintmode == GP_PAINTMODE_ERASER) + if (p->paintmode == GP_PAINTMODE_ERASER) { WM_cursor_modal_set(p->win, BC_CROSSCURSOR); /* XXX need a better cursor */ - else + } + else { WM_cursor_modal_set(p->win, BC_PAINTBRUSHCURSOR); + } } /* update UI indicators of status, including cursor and header prints */ @@ -1718,7 +1755,8 @@ static void gpencil_draw_apply(wmOperator *op, tGPsdata *p, Depsgraph *depsgraph p->mvalo[1] = p->mval[1]; p->opressure = p->pressure; } - /* only add current point to buffer if mouse moved (even though we got an event, it might be just noise) */ + /* Only add current point to buffer if mouse moved + * (even though we got an event, it might be just noise). */ else if (gp_stroke_filtermval(p, p->mval, p->mvalo)) { /* try to add point */ short ok = gp_stroke_addpoint(p, p->mval, p->pressure, p->curtime); @@ -1747,8 +1785,9 @@ static void gpencil_draw_apply(wmOperator *op, tGPsdata *p, Depsgraph *depsgraph BKE_report(op->reports, RPT_ERROR, "Cannot paint stroke"); p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: Grease-Pencil Paint - Add Point Invalid\n"); + } return; } @@ -1839,8 +1878,9 @@ static void annotation_draw_apply_event( /* special exception here for too high pressure values on first touch in * windows for some tablets, then we just skip first touch... */ - if (tablet && (p->pressure >= 0.99f)) + if (tablet && (p->pressure >= 0.99f)) { return; + } } /* check if alt key is pressed and limit to straight lines */ @@ -1886,13 +1926,15 @@ static int gpencil_draw_exec(bContext *C, wmOperator *op) /* try to initialize context data needed while drawing */ if (!gpencil_draw_init(C, op, NULL)) { - if (op->customdata) + if (op->customdata) { MEM_freeN(op->customdata); + } /* printf("\tGP - no valid data\n"); */ return OPERATOR_CANCELLED; } - else + else { p = op->customdata; + } /* printf("\tGP - Start redrawing stroke\n"); */ @@ -1984,19 +2026,23 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event } } - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("GPencil - Starting Drawing\n"); + } /* try to initialize context data needed while drawing */ if (!gpencil_draw_init(C, op, event)) { - if (op->customdata) + if (op->customdata) { MEM_freeN(op->customdata); - if (G.debug & G_DEBUG) + } + if (G.debug & G_DEBUG) { printf("\tGP - no valid data\n"); + } return OPERATOR_CANCELLED; } - else + else { p = op->customdata; + } /* if empty erase capture and finish */ if (p->status == GP_STATUS_CAPTURE) { @@ -2068,8 +2114,9 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op) /* XXX: watch it with the paintmode! in future, * it'd be nice to allow changing paint-mode when in sketching-sessions */ - if (gp_session_initdata(C, p)) + if (gp_session_initdata(C, p)) { gp_paint_initstroke(p, p->paintmode, CTX_data_depsgraph(C)); + } if (p->status != GP_STATUS_ERROR) { p->status = GP_STATUS_PAINTING; @@ -2157,7 +2204,8 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) p->ar = ar; } - /* we don't pass on key events, GP is used with key-modifiers - prevents Dkey to insert drivers */ + /* We don't pass on key events, GP is used with key-modifiers - + * prevents Dkey to insert drivers. */ if (ISKEYBOARD(event->type)) { if (ELEM(event->type, LEFTARROWKEY, DOWNARROWKEY, RIGHTARROWKEY, UPARROWKEY, ZKEY)) { /* allow some keys: @@ -2185,10 +2233,12 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) } } - //printf("\tGP - handle modal event...\n"); + // printf("\tGP - handle modal event...\n"); - /* exit painting mode (and/or end current stroke) - * NOTE: cannot do RIGHTMOUSE (as is standard for canceling) as that would break polyline [#32647] + /* Exit painting mode (and/or end current stroke) + * + * NOTE: cannot do RIGHTMOUSE (as is standard for canceling) + * as that would break polyline T32647. */ if (ELEM(event->type, RETKEY, PADENTER, ESCKEY, SPACEKEY, EKEY)) { /* exit() ends the current stroke before cleaning up */ @@ -2286,8 +2336,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) p->status = GP_STATUS_ERROR; estate = OPERATOR_CANCELLED; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("%s: Region under cursor is out of bounds, so cannot be drawn on\n", __func__); + } } } else if (p->ar) { @@ -2302,8 +2353,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) p->status = GP_STATUS_ERROR; estate = OPERATOR_CANCELLED; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("%s: No active region found in GP Paint session data\n", __func__); + } } if (in_bounds) { @@ -2382,8 +2434,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) case PADMINUS: p->radius -= 5; - if (p->radius <= 0) + if (p->radius <= 0) { p->radius = 1; + } break; } @@ -2404,8 +2457,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) } /* gpencil modal operator stores area, which can be removed while using it (like fullscreen) */ - if (0 == gpencil_area_exists(C, p->sa)) + if (0 == gpencil_area_exists(C, p->sa)) { estate = OPERATOR_CANCELLED; + } else { /* update status indicators - cursor, header, etc. */ gpencil_draw_status_indicators(C, p); @@ -2429,7 +2483,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) /* event doesn't need to be handled */ #if 0 printf("unhandled event -> %d (mmb? = %d | mmv? = %d)\n", - event->type, event->type == MIDDLEMOUSE, event->type==MOUSEMOVE); + event->type, + event->type == MIDDLEMOUSE, + event->type == MOUSEMOVE); #endif break; } diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index 24bdbcc4cba..ef74aa28b63 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -121,9 +121,15 @@ static void gp_set_point_uniform_color(const bGPDspoint *pt, const float ink[4]) immUniformColor3fvAlpha(ink, alpha); } -static void gp_set_point_varying_color(const bGPDspoint *pt, const float ink[4], uint attr_id) +static void gp_set_point_varying_color(const bGPDspoint *pt, + const float ink[4], + uint attr_id, + bool fix_strength) { float alpha = ink[3] * pt->strength; + if ((fix_strength) && (alpha >= 0.1f)) { + alpha = 1.0f; + } CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f); immAttr4ub(attr_id, F2UB(ink[0]), F2UB(ink[1]), F2UB(ink[2]), F2UB(alpha)); } @@ -186,7 +192,7 @@ static void gp_draw_stroke_volumetric_2d(const bGPDspoint *points, mul_v3_m4v3(fpt, diff_mat, &pt->x); gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co); - gp_set_point_varying_color(pt, ink, color); + gp_set_point_varying_color(pt, ink, color, false); immAttr1f(size, pt->pressure * thickness); /* TODO: scale based on view transform */ immVertex2f(pos, co[0], co[1]); } @@ -214,7 +220,7 @@ static void gp_draw_stroke_volumetric_3d(const bGPDspoint *points, const bGPDspoint *pt = points; for (int i = 0; i < totpoints && pt; i++, pt++) { - gp_set_point_varying_color(pt, ink, color); + gp_set_point_varying_color(pt, ink, color, false); /* TODO: scale based on view transform */ immAttr1f(size, pt->pressure * thickness); /* we can adjust size in vertex shader based on view/projection! */ @@ -274,7 +280,8 @@ static void gp_calc_stroke_text_coordinates( } } -/* Triangulate stroke for high quality fill (this is done only if cache is null or stroke was modified) */ +/* Triangulate stroke for high quality fill + * (this is done only if cache is null or stroke was modified). */ static void gp_triangulate_stroke_fill(bGPDstroke *gps) { BLI_assert(gps->totpoints >= 3); @@ -324,8 +331,9 @@ static void gp_triangulate_stroke_fill(bGPDstroke *gps) } else { /* No triangles needed - Free anything allocated previously */ - if (gps->triangles) + if (gps->triangles) { MEM_freeN(gps->triangles); + } gps->triangles = NULL; } @@ -375,7 +383,7 @@ static int gp_set_filling_texture(Image *image, short flag) ImBuf *ibuf; uint *bind = &image->bindcode[TEXTARGET_TEXTURE_2D]; int error = GL_NO_ERROR; - ImageUser iuser = { NULL }; + ImageUser iuser = {NULL}; void *lock; iuser.ok = true; @@ -388,8 +396,7 @@ static int gp_set_filling_texture(Image *image, short flag) } GPU_create_gl_tex( - bind, ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, GL_TEXTURE_2D, - false, false, image); + bind, ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, GL_TEXTURE_2D, false, false, image); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -448,11 +455,12 @@ static void gp_draw_stroke_fill(bGPdata *gpd, immUniform2fv("texture_scale", gp_style->texture_scale); immUniform2fv("texture_offset", gp_style->texture_offset); immUniform1f("texture_opacity", gp_style->texture_opacity); - immUniform1i("t_mix", (gp_style->flag & GP_STYLE_COLOR_TEX_MIX) != 0); + immUniform1i("t_mix", (gp_style->flag & GP_STYLE_FILL_TEX_MIX) != 0); immUniform1i("t_flip", (gp_style->flag & GP_STYLE_COLOR_FLIP_FILL) != 0); #if 0 /* GPXX disabled, not used in annotations */ /* image texture */ - if ((gp_style->fill_style == GP_STYLE_FILL_STYLE_TEXTURE) || (gp_style->flag & GP_STYLE_COLOR_TEX_MIX)) { + if ((gp_style->fill_style == GP_STYLE_FILL_STYLE_TEXTURE) || + (gp_style->flag & GP_STYLE_COLOR_TEX_MIX)) { gp_set_filling_texture(gp_style->ima, gp_style->flag); } #endif @@ -574,7 +582,7 @@ static void gp_draw_stroke_3d(tGPDdraw *tgpw, short thickness, const float ink[4 for (int i = 0; i < totpoints; i++, pt++) { /* first point for adjacency (not drawn) */ if (i == 0) { - gp_set_point_varying_color(points, ink, attr_id.color); + gp_set_point_varying_color(points, ink, attr_id.color, (bool)tgpw->is_fill_stroke); if ((cyclic) && (totpoints > 2)) { immAttr1f(attr_id.thickness, max_ff((points + totpoints - 1)->pressure * thickness, 1.0f)); @@ -587,7 +595,7 @@ static void gp_draw_stroke_3d(tGPDdraw *tgpw, short thickness, const float ink[4 immVertex3fv(attr_id.pos, fpt); } /* set point */ - gp_set_point_varying_color(pt, ink, attr_id.color); + gp_set_point_varying_color(pt, ink, attr_id.color, (bool)tgpw->is_fill_stroke); immAttr1f(attr_id.thickness, max_ff(pt->pressure * thickness, 1.0f)); mul_v3_m4v3(fpt, tgpw->diff_mat, &pt->x); immVertex3fv(attr_id.pos, fpt); @@ -606,7 +614,9 @@ static void gp_draw_stroke_3d(tGPDdraw *tgpw, short thickness, const float ink[4 } /* last adjacency point (not drawn) */ else { - gp_set_point_varying_color(points + totpoints - 2, ink, attr_id.color); + gp_set_point_varying_color( + points + totpoints - 2, ink, attr_id.color, (bool)tgpw->is_fill_stroke); + immAttr1f(attr_id.thickness, max_ff((points + totpoints - 2)->pressure * thickness, 1.0f)); mul_v3_m4v3(fpt, tgpw->diff_mat, &(points + totpoints - 2)->x); immVertex3fv(attr_id.pos, fpt); @@ -643,8 +653,8 @@ static void gp_draw_stroke_2d(const bGPDspoint *points, /* TODO: fancy++ with the magic of shaders */ - /* tessellation code - draw stroke as series of connected quads (triangle strips in fact) with connection - * edges rotated to minimize shrinking artifacts, and rounded endcaps + /* tessellation code - draw stroke as series of connected quads (triangle strips in fact) + * with connection edges rotated to minimize shrinking artifacts, and rounded endcaps. */ { const bGPDspoint *pt1, *pt2; @@ -675,7 +685,8 @@ static void gp_draw_stroke_2d(const bGPDspoint *points, float mt[2], sc[2]; /* gradient for thickness, point for end-cap */ float pthick; /* thickness at segment point */ - /* get x and y coordinates from point2 (point1 has already been computed in previous iteration). */ + /* Get x and y coordinates from point2 + * (point1 has already been computed in previous iteration). */ mul_v3_m4v3(fpt, diff_mat, &pt2->x); gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, s1); @@ -690,7 +701,7 @@ static void gp_draw_stroke_2d(const bGPDspoint *points, pthick = (pt1->pressure * thickness * scalefac); /* color of point */ - gp_set_point_varying_color(pt1, ink, attr_id.color); + gp_set_point_varying_color(pt1, ink, attr_id.color, false); /* if the first segment, start of segment is segment's normal */ if (i == 0) { @@ -765,7 +776,7 @@ static void gp_draw_stroke_2d(const bGPDspoint *points, pthick = (pt2->pressure * thickness * scalefac); /* color of point */ - gp_set_point_varying_color(pt2, ink, attr_id.color); + gp_set_point_varying_color(pt2, ink, attr_id.color, false); /* calculate points for end of segment */ mt[0] = m2[0] * pthick; @@ -816,26 +827,33 @@ static bool gp_can_draw_stroke(const bGPDstroke *gps, const int dflag) { /* skip stroke if it isn't in the right display space for this drawing context */ /* 1) 3D Strokes */ - if ((dflag & GP_DRAWDATA_ONLY3D) && !(gps->flag & GP_STROKE_3DSPACE)) + if ((dflag & GP_DRAWDATA_ONLY3D) && !(gps->flag & GP_STROKE_3DSPACE)) { return false; - if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE)) + } + if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE)) { return false; + } /* 2) Screen Space 2D Strokes */ - if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE)) + if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE)) { return false; - if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE)) + } + if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE)) { return false; + } /* 3) Image Space (2D) */ - if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE)) + if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE)) { return false; - if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE)) + } + if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE)) { return false; + } /* skip stroke if it doesn't have any valid data */ - if ((gps->points == NULL) || (gps->totpoints < 1)) + if ((gps->points == NULL) || (gps->totpoints < 1)) { return false; + } /* stroke can be drawn */ return true; @@ -851,7 +869,9 @@ static void gp_draw_strokes(tGPDdraw *tgpw) GPU_enable_program_point_size(); - for (bGPDstroke *gps = tgpw->t_gpf->strokes.first; gps; gps = gps->next) { + bGPDstroke *gps_init = (tgpw->gps) ? tgpw->gps : tgpw->t_gpf->strokes.first; + + for (bGPDstroke *gps = gps_init; gps; gps = gps->next) { /* check if stroke can be drawn */ if (gp_can_draw_stroke(gps, tgpw->dflag) == false) { continue; @@ -899,7 +919,7 @@ static void gp_draw_strokes(tGPDdraw *tgpw) } /* 3D Fill */ - //if ((dflag & GP_DRAWDATA_FILL) && (gps->totpoints >= 3)) { + // if ((dflag & GP_DRAWDATA_FILL) && (gps->totpoints >= 3)) { if ((gps->totpoints >= 3) && (tgpw->disable_fill != 1)) { /* set color using material, tint color and opacity */ interp_v3_v3v3(tfill, gp_style->fill_rgba, tgpw->tintcolor, tgpw->tintcolor[3]); @@ -945,6 +965,14 @@ static void gp_draw_strokes(tGPDdraw *tgpw) copy_v4_v4(ink, tcolor); } } + + /* if used for fill, set opacity to 1 */ + if (tgpw->is_fill_stroke) { + if (ink[3] >= GPENCIL_ALPHA_OPACITY_THRESH) { + ink[3] = 1.0f; + } + } + if (gp_style->mode == GP_STYLE_MODE_DOTS) { /* volumetric stroke drawing */ if (tgpw->disable_fill != 1) { @@ -1070,6 +1098,10 @@ static void gp_draw_strokes(tGPDdraw *tgpw) } } } + /* if only one stroke, exit from loop */ + if (tgpw->gps) { + break; + } } GPU_disable_program_point_size(); @@ -1116,6 +1148,7 @@ void ED_gp_draw_interpolation(const bContext *C, tGPDinterpolate *tgpi, const in tgpw.gpl = tgpil->gpl; tgpw.gpf = tgpil->interFrame; tgpw.t_gpf = tgpil->interFrame; + tgpw.gps = NULL; tgpw.lthick = tgpil->gpl->line_change; tgpw.opacity = 1.0; @@ -1141,8 +1174,9 @@ static void UNUSED_FUNCTION(gp_draw_status_text)(const bGPdata *gpd, ARegion *ar rcti rect; /* Cannot draw any status text when drawing OpenGL Renders */ - if (G.f & G_FLAG_RENDER_VIEWPORT) + if (G.f & G_FLAG_RENDER_VIEWPORT) { return; + } /* Get bounds of region - Necessary to avoid problems with region overlap */ ED_region_visible_rect(ar, &rect); diff --git a/source/blender/editors/gpencil/editaction_gpencil.c b/source/blender/editors/gpencil/editaction_gpencil.c index 4724dc068b6..d0f44314c95 100644 --- a/source/blender/editors/gpencil/editaction_gpencil.c +++ b/source/blender/editors/gpencil/editaction_gpencil.c @@ -61,14 +61,16 @@ bool ED_gplayer_frames_looper(bGPDlayer *gpl, Scene *scene, short (*gpf_cb)(bGPD bGPDframe *gpf; /* error checker */ - if (gpl == NULL) + if (gpl == NULL) { return false; + } /* do loop */ for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { /* execute callback */ - if (gpf_cb(gpf, scene)) + if (gpf_cb(gpf, scene)) { return true; + } } /* nothing to return */ @@ -85,8 +87,9 @@ void ED_gplayer_make_cfra_list(bGPDlayer *gpl, ListBase *elems, bool onlysel) CfraElem *ce; /* error checking */ - if (ELEM(NULL, gpl, elems)) + if (ELEM(NULL, gpl, elems)) { return; + } /* loop through gp-frames, adding */ for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { @@ -110,13 +113,15 @@ bool ED_gplayer_frame_select_check(bGPDlayer *gpl) bGPDframe *gpf; /* error checking */ - if (gpl == NULL) + if (gpl == NULL) { return false; + } /* stop at the first one found */ for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { - if (gpf->flag & GP_FRAME_SELECT) + if (gpf->flag & GP_FRAME_SELECT) { return true; + } } /* not found */ @@ -126,8 +131,9 @@ bool ED_gplayer_frame_select_check(bGPDlayer *gpl) /* helper function - select gp-frame based on SELECT_* mode */ static void gpframe_select(bGPDframe *gpf, short select_mode) { - if (gpf == NULL) + if (gpf == NULL) { return; + } switch (select_mode) { case SELECT_ADD: @@ -148,8 +154,9 @@ void ED_gpencil_select_frames(bGPDlayer *gpl, short select_mode) bGPDframe *gpf; /* error checking */ - if (gpl == NULL) + if (gpl == NULL) { return; + } /* handle according to mode */ for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { @@ -161,8 +168,9 @@ void ED_gpencil_select_frames(bGPDlayer *gpl, short select_mode) void ED_gplayer_frame_select_set(bGPDlayer *gpl, short mode) { /* error checking */ - if (gpl == NULL) + if (gpl == NULL) { return; + } /* now call the standard function */ ED_gpencil_select_frames(gpl, mode); @@ -173,8 +181,9 @@ void ED_gpencil_select_frame(bGPDlayer *gpl, int selx, short select_mode) { bGPDframe *gpf; - if (gpl == NULL) + if (gpl == NULL) { return; + } gpf = BKE_gpencil_layer_find_frame(gpl, selx); @@ -188,13 +197,15 @@ void ED_gplayer_frames_select_box(bGPDlayer *gpl, float min, float max, short se { bGPDframe *gpf; - if (gpl == NULL) + if (gpl == NULL) { return; + } /* only select those frames which are in bounds */ for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { - if (IN_RANGE(gpf->framenum, min, max)) + if (IN_RANGE(gpf->framenum, min, max)) { gpframe_select(gpf, select_mode); + } } } @@ -206,8 +217,9 @@ void ED_gplayer_frames_select_region(KeyframeEditData *ked, { bGPDframe *gpf; - if (gpl == NULL) + if (gpl == NULL) { return; + } /* only select frames which are within the region */ for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { @@ -220,13 +232,15 @@ void ED_gplayer_frames_select_region(KeyframeEditData *ked, /* check the necessary regions */ if (tool == BEZT_OK_CHANNEL_LASSO) { /* Lasso */ - if (keyframe_region_lasso_test(ked->data, pt)) + if (keyframe_region_lasso_test(ked->data, pt)) { gpframe_select(gpf, select_mode); + } } else if (tool == BEZT_OK_CHANNEL_CIRCLE) { /* Circle */ - if (keyframe_region_circle_test(ked->data, pt)) + if (keyframe_region_circle_test(ked->data, pt)) { gpframe_select(gpf, select_mode); + } } } } @@ -241,8 +255,9 @@ bool ED_gplayer_frames_delete(bGPDlayer *gpl) bool changed = false; /* error checking */ - if (gpl == NULL) + if (gpl == NULL) { return false; + } /* check for frames to delete */ for (gpf = gpl->frames.first; gpf; gpf = gpfn) { @@ -263,8 +278,9 @@ void ED_gplayer_frames_duplicate(bGPDlayer *gpl) bGPDframe *gpf, *gpfn; /* error checking */ - if (gpl == NULL) + if (gpl == NULL) { return; + } /* duplicate selected frames */ for (gpf = gpl->frames.first; gpf; gpf = gpfn) { @@ -290,8 +306,9 @@ void ED_gplayer_frames_keytype_set(bGPDlayer *gpl, short type) { bGPDframe *gpf; - if (gpl == NULL) + if (gpl == NULL) { return; + } for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { if (gpf->flag & GP_FRAME_SELECT) { @@ -301,12 +318,14 @@ void ED_gplayer_frames_keytype_set(bGPDlayer *gpl, short type) } /* -------------------------------------- */ -/* Copy and Paste Tools */ -/* - The copy/paste buffer currently stores a set of GP_Layers, with temporary +/* Copy and Paste Tools: + * - The copy/paste buffer currently stores a set of GP_Layers, with temporary * GP_Frames with the necessary strokes - * - Unless there is only one element in the buffer, names are also tested to check for compatibility. - * - All pasted frames are offset by the same amount. This is calculated as the difference in the times of - * the current frame and the 'first keyframe' (i.e. the earliest one in all channels). + * - Unless there is only one element in the buffer, + * names are also tested to check for compatibility. + * - All pasted frames are offset by the same amount. + * This is calculated as the difference in the times of the current frame and the + * 'first keyframe' (i.e. the earliest one in all channels). * - The earliest frame is calculated per copy operation. */ @@ -362,10 +381,12 @@ bool ED_gpencil_anim_copybuf_copy(bAnimContext *ac) BLI_addtail(&copied_frames, new_frame); /* extend extents for keyframes encountered */ - if (gpf->framenum < gp_anim_copy_firstframe) + if (gpf->framenum < gp_anim_copy_firstframe) { gp_anim_copy_firstframe = gpf->framenum; - if (gpf->framenum > gp_anim_copy_lastframe) + } + if (gpf->framenum > gp_anim_copy_lastframe) { gp_anim_copy_lastframe = gpf->framenum; + } } } @@ -458,8 +479,9 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode) } /* this situation might occur! */ - if (gpls == NULL) + if (gpls == NULL) { continue; + } /* add frames from buffer */ for (gpfs = gpls->frames.first; gpfs; gpfs = gpfs->next) { @@ -493,8 +515,9 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode) } /* if no strokes (i.e. new frame) added, free gpf */ - if (BLI_listbase_is_empty(&gpf->strokes)) + if (BLI_listbase_is_empty(&gpf->strokes)) { BKE_gpencil_layer_delframe(gpld, gpf); + } } /* unapply offset from buffer-frame */ @@ -522,23 +545,26 @@ static short snap_gpf_nearest(bGPDframe *UNUSED(gpf), Scene *UNUSED(scene)) static short snap_gpf_nearestsec(bGPDframe *gpf, Scene *scene) { float secf = (float)FPS; - if (gpf->flag & GP_FRAME_SELECT) + if (gpf->flag & GP_FRAME_SELECT) { gpf->framenum = (int)(floorf(gpf->framenum / secf + 0.5f) * secf); + } return 0; } static short snap_gpf_cframe(bGPDframe *gpf, Scene *scene) { - if (gpf->flag & GP_FRAME_SELECT) + if (gpf->flag & GP_FRAME_SELECT) { gpf->framenum = (int)CFRA; + } return 0; } static short snap_gpf_nearmarker(bGPDframe *gpf, Scene *scene) { - if (gpf->flag & GP_FRAME_SELECT) + if (gpf->flag & GP_FRAME_SELECT) { gpf->framenum = (int)ED_markers_find_nearest_marker_time(&scene->markers, (float)gpf->framenum); + } return 0; } diff --git a/source/blender/editors/gpencil/gpencil_add_stroke.c b/source/blender/editors/gpencil/gpencil_add_stroke.c index d6e068926dd..f6ff5ed4f13 100644 --- a/source/blender/editors/gpencil/gpencil_add_stroke.c +++ b/source/blender/editors/gpencil/gpencil_add_stroke.c @@ -210,7 +210,8 @@ static const ColorTemplate gp_stroke_material_grey = { /* ***************************************************************** */ /* Stroke API */ -/* add a Simple stroke with colors (original design created by Daniel M. Lara and Matias Mendiola) */ +/* Add a Simple stroke with colors + * (original design created by Daniel M. Lara and Matias Mendiola). */ void ED_gpencil_create_stroke(bContext *C, Object *ob, float mat[4][4]) { Main *bmain = CTX_data_main(C); diff --git a/source/blender/editors/gpencil/gpencil_armature.c b/source/blender/editors/gpencil/gpencil_armature.c index d99a630a45c..6ad89d2e38d 100644 --- a/source/blender/editors/gpencil/gpencil_armature.c +++ b/source/blender/editors/gpencil/gpencil_armature.c @@ -287,8 +287,9 @@ static void gpencil_add_verts_to_dgroups( /* count the number of skinnable bones */ numbones = gpencil_bone_looper(ob, arm->bonebase.first, &looper_data, gpencil_bone_skinnable_cb); - if (numbones == 0) + if (numbones == 0) { return; + } /* create an array of pointer to bones that are skinnable * and fill it with all of the skinnable bones */ @@ -366,13 +367,15 @@ static void gpencil_add_verts_to_dgroups( for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) { if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { - if (gpf == NULL) + if (gpf == NULL) { continue; + } for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } BKE_gpencil_dvert_ensure(gps); @@ -477,6 +480,8 @@ static void gpencil_object_vgroup_calc_from_armature(const bContext *C, */ gpencil_add_verts_to_dgroups(C, ob, ob_arm, ratio, decay); } + + DEG_relations_tag_update(CTX_data_main(C)); } bool ED_gpencil_add_armature_weights( @@ -564,8 +569,9 @@ static int gpencil_generate_weights_exec(bContext *C, wmOperator *op) const float decay = RNA_float_get(op->ptr, "decay"); /* sanity checks */ - if (ELEM(NULL, ob, gpd)) + if (ELEM(NULL, ob, gpd)) { return OPERATOR_CANCELLED; + } /* get armature */ const int arm_idx = RNA_enum_get(op->ptr, "armature"); diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c index ef0ebd06d07..9777a8190c1 100644 --- a/source/blender/editors/gpencil/gpencil_brush.c +++ b/source/blender/editors/gpencil/gpencil_brush.c @@ -88,6 +88,7 @@ typedef struct tGP_BrushEditData { /* Current editor/region/etc. */ /* NOTE: This stuff is mainly needed to handle 3D view projection stuff... */ Depsgraph *depsgraph; + struct Main *bmain; Scene *scene; Object *object; @@ -190,8 +191,7 @@ static void gpsculpt_compute_lock_axis(tGP_BrushEditData *gso, break; } case GP_LOCKAXIS_CURSOR: { - /* compute a plane with cursor normal and position of the point - before do the sculpt */ + /* Compute a plane with cursor normal and position of the point before do the sculpt. */ const float scale[3] = {1.0f, 1.0f, 1.0f}; float plane_normal[3] = {0.0f, 0.0f, 1.0f}; float plane[4]; @@ -303,7 +303,8 @@ static float gp_brush_influence_calc(tGP_BrushEditData *gso, const int radius, c /* ----------------------------------------------- */ /* Smooth Brush */ -/* A simple (but slower + inaccurate) smooth-brush implementation to test the algorithm for stroke smoothing */ +/* A simple (but slower + inaccurate) + * smooth-brush implementation to test the algorithm for stroke smoothing. */ static bool gp_brush_smooth_apply( tGP_BrushEditData *gso, bGPDstroke *gps, int pt_index, const int radius, const int co[2]) { @@ -352,7 +353,8 @@ static bool gp_brush_thickness_apply( inf = gp_brush_influence_calc(gso, radius, co) / 10.0f; /* apply */ - // XXX: this is much too strong, and it should probably do some smoothing with the surrounding stuff + /* XXX: this is much too strong, + * and it should probably do some smoothing with the surrounding stuff. */ if (gp_brush_invert_check(gso)) { /* make line thinner - reduce stroke pressure */ pt->pressure -= inf; @@ -367,8 +369,9 @@ static bool gp_brush_thickness_apply( * the upper end of this range. Therefore, we don't actually clamp * down on the upper end. */ - if (pt->pressure < 0.0f) + if (pt->pressure < 0.0f) { pt->pressure = 0.0f; + } return true; } @@ -802,7 +805,16 @@ static bool gp_brush_randomize_apply( mul_v2_fl(svec, fac); } - //printf("%f %f (%f), nco = {%f %f}, co = %d %d\n", svec[0], svec[1], fac, nco[0], nco[1], co[0], co[1]); +#if 0 + printf("%f %f (%f), nco = {%f %f}, co = %d %d\n", + svec[0], + svec[1], + fac, + nco[0], + nco[1], + co[0], + co[1]); +#endif /* convert to dataspace */ if (gps->flag & GP_STROKE_3DSPACE) { @@ -896,6 +908,7 @@ static bool gp_brush_weight_apply( if (gso->vrgroup == -1) { if (gso->object) { BKE_object_defgroup_add(gso->object); + DEG_relations_tag_update(gso->bmain); gso->vrgroup = 0; } } @@ -927,8 +940,9 @@ static bool gp_brush_weight_apply( } /* weight should stay within [0.0, 1.0] */ - if (pt->pressure < 0.0f) + if (pt->pressure < 0.0f) { pt->pressure = 0.0f; + } return true; } @@ -957,7 +971,7 @@ typedef struct tGPSB_CloneBrushData { /* for "stamp" mode, the currently pasted brushes */ bGPDstroke **new_strokes; - /* mapping from colors referenced per stroke, to the new colours in the "pasted" strokes */ + /** Mapping from colors referenced per stroke, to the new colors in the "pasted" strokes. */ GHash *new_colors; } tGPSB_CloneBrushData; @@ -1005,7 +1019,7 @@ static void gp_brush_clone_init(bContext *C, tGP_BrushEditData *gso) } /* Init colormap for mapping between the pasted stroke's source color (names) - * and the final colours that will be used here instead. + * and the final colors that will be used here instead. */ data->new_colors = gp_copybuf_validate_colormap(C); } @@ -1107,7 +1121,8 @@ static void gp_brush_clone_adjust(tGP_BrushEditData *gso) gp_brush_grab_calc_dvec(gso); /* For each of the stored strokes, apply the offset to each point */ - /* NOTE: Again this assumes that in the 3D view, we only have 3d space and not screenspace strokes... */ + /* NOTE: Again this assumes that in the 3D view, + * we only have 3d space and not screenspace strokes... */ for (snum = 0; snum < data->totitems; snum++) { bGPDstroke *gps = data->new_strokes[snum]; bGPDspoint *pt; @@ -1154,7 +1169,8 @@ static bool gpsculpt_brush_apply_clone(bContext *C, tGP_BrushEditData *gso) } else { /* Continuous - Just keep pasting everytime we move */ - /* TODO: The spacing of repeat should be controlled using a "stepsize" or similar property? */ + /* TODO: The spacing of repeat should be controlled using a + * "stepsize" or similar property? */ gp_brush_clone_add(C, gso); } } @@ -1206,6 +1222,7 @@ static bool gpsculpt_brush_init(bContext *C, wmOperator *op) op->customdata = gso; gso->depsgraph = CTX_data_depsgraph(C); + gso->bmain = CTX_data_main(C); /* store state */ gso->settings = gpsculpt_get_settings(scene); gso->gp_brush = gpsculpt_get_brush(scene, is_weight_mode); @@ -1309,7 +1326,7 @@ static bool gpsculpt_brush_init(bContext *C, wmOperator *op) gpsculpt_brush_header_set(C, gso); /* setup cursor drawing */ - //WM_cursor_modal_set(CTX_wm_window(C), BC_CROSSCURSOR); + // WM_cursor_modal_set(CTX_wm_window(C), BC_CROSSCURSOR); if (gso->sa->spacetype != SPACE_VIEW3D) { ED_gpencil_toggle_brush_cursor(C, true, NULL); } @@ -1383,8 +1400,9 @@ static void gpsculpt_brush_init_stroke(tGP_BrushEditData *gso) int cfra_eval = (int)DEG_get_ctime(gso->depsgraph); /* only try to add a new frame if this is the first stroke, or the frame has changed */ - if ((gpd == NULL) || (cfra_eval == gso->cfra)) + if ((gpd == NULL) || (cfra_eval == gso->cfra)) { return; + } /* go through each layer, and ensure that we've got a valid frame to use */ for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { @@ -1392,9 +1410,10 @@ static void gpsculpt_brush_init_stroke(tGP_BrushEditData *gso) if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) { bGPDframe *gpf = gpl->actframe; - /* Make a new frame to work on if the layer's frame and the current scene frame don't match up + /* Make a new frame to work on if the layer's frame + * and the current scene frame don't match up: * - This is useful when animating as it saves that "uh-oh" moment when you realize you've - * spent too much time editing the wrong frame... + * spent too much time editing the wrong frame. */ // XXX: should this be allowed when framelock is enabled? if (gpf->framenum != cfra_eval) { @@ -1454,7 +1473,8 @@ static bool gpsculpt_brush_do_stroke(tGP_BrushEditData *gso, pt1 = gps->points + i; pt2 = gps->points + i + 1; - /* Skip if neither one is selected (and we are only allowed to edit/consider selected points) */ + /* Skip if neither one is selected + * (and we are only allowed to edit/consider selected points) */ if (gso->settings->flag & GP_SCULPT_SETT_FLAG_SELECT_MASK) { if (!(pt1->flag & GP_SPOINT_SELECT) && !(pt2->flag & GP_SPOINT_SELECT)) { include_last = false; @@ -1502,9 +1522,10 @@ static bool gpsculpt_brush_do_stroke(tGP_BrushEditData *gso, changed |= ok; } else if (include_last) { - /* This case is for cases where for whatever reason the second vert (1st here) doesn't get included - * because the whole edge isn't in bounds, but it would've qualified since it did with the - * previous step (but wasn't added then, to avoid double-ups) + /* This case is for cases where for whatever reason the second vert (1st here) + * doesn't get included because the whole edge isn't in bounds, + * but it would've qualified since it did with the previous step + * (but wasn't added then, to avoid double-ups). */ changed |= apply(gso, gps, i, radius, pc1); include_last = false; @@ -1722,10 +1743,12 @@ static void gpsculpt_brush_apply(bContext *C, wmOperator *op, PointerRNA *itempt gso->pressure = RNA_float_get(itemptr, "pressure"); - if (RNA_boolean_get(itemptr, "pen_flip")) + if (RNA_boolean_get(itemptr, "pen_flip")) { gso->flag |= GP_SCULPT_FLAG_INVERT; - else + } + else { gso->flag &= ~GP_SCULPT_FLAG_INVERT; + } /* Store coordinates as reference, if operator just started running */ if (gso->first) { @@ -1825,8 +1848,9 @@ static void gpsculpt_brush_apply_event(bContext *C, wmOperator *op, const wmEven /* reapply */ static int gpsculpt_brush_exec(bContext *C, wmOperator *op) { - if (!gpsculpt_brush_init(C, op)) + if (!gpsculpt_brush_init(C, op)) { return OPERATOR_CANCELLED; + } RNA_BEGIN (op->ptr, itemptr, "stroke") { gpsculpt_brush_apply(C, op, &itemptr); @@ -1855,8 +1879,9 @@ static int gpsculpt_brush_invoke(bContext *C, wmOperator *op, const wmEvent *eve } /* init painting data */ - if (!gpsculpt_brush_init(C, op)) + if (!gpsculpt_brush_init(C, op)) { return OPERATOR_CANCELLED; + } gso = op->customdata; @@ -1982,7 +2007,7 @@ static int gpsculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *even /* Painting mbut release = Stop painting (back to idle) */ case LEFTMOUSE: - //BLI_assert(event->val == KM_RELEASE); + // BLI_assert(event->val == KM_RELEASE); if (is_modal) { /* go back to idling... */ gso->is_painting = false; diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c index c1c797b15be..5afa379e04f 100644 --- a/source/blender/editors/gpencil/gpencil_convert.c +++ b/source/blender/editors/gpencil/gpencil_convert.c @@ -79,6 +79,7 @@ #include "ED_view3d.h" #include "ED_clip.h" #include "ED_keyframing.h" +#include "ED_object.h" #include "gpencil_intern.h" @@ -328,9 +329,9 @@ static int gp_find_end_of_stroke_idx(tGpTimingData *gtd, else { float delta, min, max; - /* This code ensures that if the first gaps have been shorter than average gap_duration, - * next gaps will tend to be longer (i.e. try to recover the lateness), and vice-versa! - */ + /* This code ensures that if the first gaps + * have been shorter than average gap_duration, next gaps + * will tend to be longer (i.e. try to recover the lateness), and vice-versa! */ delta = delta_time - (gtd->gap_duration * (*nbr_done_gaps)); /* Clamp min between [-gap_randomness, 0.0], with lower delta giving higher min */ @@ -501,8 +502,9 @@ static void gp_stroke_path_animation(bContext *C, PropertyRNA *prop = NULL; int nbr_gaps = 0, i; - if (gtd->mode == GP_STROKECONVERT_TIMING_NONE) + if (gtd->mode == GP_STROKECONVERT_TIMING_NONE) { return; + } /* gap_duration and gap_randomness are in frames, but we need seconds!!! */ gtd->gap_duration = FRA2TIME(gtd->gap_duration); @@ -693,8 +695,10 @@ static void gp_stroke_to_path(bContext *C, * the last segment to get the first point (p1) position and timing. * - If we do not have those (quite odd, but may happen), we linearly interpolate the last point * with the first point of the current stroke. - * The same goes for the second point, first segment of the current stroke is "negatively" extrapolated - * if it exists, else (if the stroke is a single point), linear interpolation with last curve point... + * + * The same goes for the second point, first segment of the current stroke is "negatively" + * extrapolated if it exists, else (if the stroke is a single point), + * linear interpolation with last curve point. */ if (curnu && !stitch && old_nbp) { float p1[3], p2[3], p[3], next_p[3]; @@ -774,8 +778,9 @@ static void gp_stroke_to_path(bContext *C, dt = -GAP_DFAC; /* Rather arbitrary too! */ } bp = &nu->bp[old_nbp]; - /* Note we can't give anything else than 0.0 as time here, since a negative one (which would be expected value) - * would not work (it would be *before* gtd->inittime, which is not supported currently). + /* Note we can't give anything else than 0.0 as time here, since a negative one + * (which would be expected value) would not work + * (it would be *before* gtd->inittime, which is not supported currently). */ gp_stroke_to_path_add_point( gtd, bp, p, p, do_gtd, gps->inittime, dt, 0.0f, rad_fac, minmax_weights); @@ -907,9 +912,10 @@ static void gp_stroke_to_bezier(bContext *C, /* create new 'nurb' or extend current one within the curve */ if (nu) { old_nbezt = nu->pntsu; - /* If we do stitch, first point of current stroke is assumed the same as last point of previous stroke, - * so no need to add it. - * If no stitch, we want to add two additional points to make a "zero-radius" link between both strokes. + /* If we do stitch, first point of current stroke is assumed the same as last point of + * previous stroke, so no need to add it. + * If no stitch, we want to add two additional points to make a "zero-radius" + * link between both strokes. */ BKE_nurb_bezierPoints_add(nu, gps->totpoints + ((stitch) ? -1 : 2) + add_start_end_points); } @@ -958,12 +964,15 @@ static void gp_stroke_to_bezier(bContext *C, /* Create "link points" */ /* About "zero-radius" point interpolations: - * - If we have at least two points in current curve (most common case), we linearly extrapolate - * the last segment to get the first point (p1) position and timing. - * - If we do not have those (quite odd, but may happen), we linearly interpolate the last point - * with the first point of the current stroke. - * The same goes for the second point, first segment of the current stroke is "negatively" extrapolated - * if it exists, else (if the stroke is a single point), linear interpolation with last curve point... + * - If we have at least two points in current curve (most common case), + * we linearly extrapolate the last segment to get the first point (p1) position and timing. + * - If we do not have those (quite odd, but may happen), + * we linearly interpolate the last point with the first point of the current stroke. + * + * The same goes for the second point, + * first segment of the current stroke is "negatively" extrapolated + * if it exists, else (if the stroke is a single point), + * linear interpolation with last curve point. */ else { float p1[3], p2[3]; @@ -1133,7 +1142,8 @@ static void gp_stroke_to_bezier(bContext *C, /* The end point */ interp_v3_v3v3(h1, p, prev_bezt->vec[1], BEZT_HANDLE_FAC); interp_v3_v3v3(h2, p, prev_bezt->vec[1], -BEZT_HANDLE_FAC); - /* Note bezt has already been incremented in main loop above, so it points to the right place. */ + /* Note bezt has already been incremented in main loop above, + * so it points to the right place. */ gp_stroke_to_bezier_add_point(gtd, bezt, p, @@ -1206,10 +1216,12 @@ static void gp_stroke_norm_curve_weights(Curve *cu, const float minmax_weights[2 int i; /* when delta == minmax_weights[0] == minmax_weights[1], we get div by zero [#35686] */ - if (IS_EQF(delta, minmax_weights[1])) + if (IS_EQF(delta, minmax_weights[1])) { fac = 1.0f; - else + } + else { fac = 1.0f / (minmax_weights[1] - delta); + } for (nu = cu->nurb.first; nu; nu = nu->next) { if (nu->bezt) { @@ -1277,12 +1289,14 @@ static void gp_layer_to_curve(bContext *C, rctf subrect, *subrect_ptr = NULL; /* error checking */ - if (ELEM(NULL, gpd, gpl, gpf)) + if (ELEM(NULL, gpd, gpl, gpf)) { return; + } /* only convert if there are any strokes on this layer's frame to convert */ - if (BLI_listbase_is_empty(&gpf->strokes)) + if (BLI_listbase_is_empty(&gpf->strokes)) { return; + } /* initialize camera framing */ if (gp_camera_view_subrect(C, &subrect)) { @@ -1382,9 +1396,7 @@ static void gp_layer_to_curve(bContext *C, } } - /* set the layer and select */ - base_new->flag |= SELECT; - BKE_scene_object_base_flag_sync_from_base(base_new); + ED_object_base_select(base_new, BA_SELECT); } /* --- */ @@ -1405,8 +1417,9 @@ static bool gp_convert_check_has_valid_timing(bContext *C, bGPDlayer *gpl, wmOpe bool valid = true; if (!gpl || !(gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV)) || - !(gps = gpf->strokes.first)) + !(gps = gpf->strokes.first)) { return false; + } do { base_time = cur_time = gps->inittime; @@ -1572,13 +1585,15 @@ static bool gp_convert_poll_property(const bContext *UNUSED(C), } /* Never show this prop */ - if (STREQ(prop_id, "use_timing_data")) + if (STREQ(prop_id, "use_timing_data")) { return false; + } if (link_strokes) { /* Only show when link_stroke is true */ - if (STREQ(prop_id, "timing_mode")) + if (STREQ(prop_id, "timing_mode")) { return true; + } if (timing_mode != GP_STROKECONVERT_TIMING_NONE) { /* Only show when link_stroke is true and stroke timing is enabled */ @@ -1587,25 +1602,30 @@ static bool gp_convert_poll_property(const bContext *UNUSED(C), } /* Only show if we have valid timing data! */ - if (valid_timing && STREQ(prop_id, "use_realtime")) + if (valid_timing && STREQ(prop_id, "use_realtime")) { return true; + } /* Only show if realtime or valid_timing is false! */ - if ((!realtime || !valid_timing) && STREQ(prop_id, "end_frame")) + if ((!realtime || !valid_timing) && STREQ(prop_id, "end_frame")) { return true; + } if (valid_timing && timing_mode == GP_STROKECONVERT_TIMING_CUSTOMGAP) { /* Only show for custom gaps! */ - if (STREQ(prop_id, "gap_duration")) + if (STREQ(prop_id, "gap_duration")) { return true; + } /* Only show randomness for non-null custom gaps! */ - if (STREQ(prop_id, "gap_randomness") && (gap_duration > 0.0f)) + if (STREQ(prop_id, "gap_randomness") && (gap_duration > 0.0f)) { return true; + } /* Only show seed for randomize action! */ - if (STREQ(prop_id, "seed") && (gap_duration > 0.0f) && (gap_randomness > 0.0f)) + if (STREQ(prop_id, "seed") && (gap_duration > 0.0f) && (gap_randomness > 0.0f)) { return true; + } } } } diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c index c91c543e746..f44c90001e1 100644 --- a/source/blender/editors/gpencil/gpencil_data.c +++ b/source/blender/editors/gpencil/gpencil_data.c @@ -124,7 +124,8 @@ static int gp_data_add_exec(bContext *C, wmOperator *op) id_us_min(&gpd->id); } - /* add new datablock, with a single layer ready to use (so users don't have to perform an extra step) */ + /* Add new datablock, with a single layer ready to use + * (so users don't have to perform an extra step). */ if (is_annotation) { bGPdata *gpd = BKE_gpencil_data_addnew(bmain, DATA_("Annotations")); *gpd_ptr = gpd; @@ -297,8 +298,9 @@ static int gp_layer_remove_exec(bContext *C, wmOperator *op) bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); /* sanity checks */ - if (ELEM(NULL, gpd, gpl)) + if (ELEM(NULL, gpd, gpl)) { return OPERATOR_CANCELLED; + } if (gpl->flag & GP_LAYER_LOCKED) { BKE_report(op->reports, RPT_ERROR, "Cannot delete locked layers"); @@ -309,10 +311,12 @@ static int gp_layer_remove_exec(bContext *C, wmOperator *op) * - use the one after if this is the first * - if this is the only layer, this naturally becomes NULL */ - if (gpl->prev) + if (gpl->prev) { BKE_gpencil_layer_setactive(gpd, gpl->prev); - else + } + else { BKE_gpencil_layer_setactive(gpd, gpl->next); + } /* delete the layer now... */ BKE_gpencil_layer_delete(gpd, gpl); @@ -353,8 +357,9 @@ static int gp_layer_move_exec(bContext *C, wmOperator *op) const int direction = RNA_enum_get(op->ptr, "type") * -1; /* sanity checks */ - if (ELEM(NULL, gpd, gpl)) + if (ELEM(NULL, gpd, gpl)) { return OPERATOR_CANCELLED; + } BLI_assert(ELEM(direction, -1, 0, 1)); /* we use value below */ if (BLI_listbase_link_move(&gpd->layers, gpl, direction)) { @@ -397,8 +402,9 @@ static int gp_layer_copy_exec(bContext *C, wmOperator *UNUSED(op)) bGPDlayer *new_layer; /* sanity checks */ - if (ELEM(NULL, gpd, gpl)) + if (ELEM(NULL, gpd, gpl)) { return OPERATOR_CANCELLED; + } /* make copy of layer, and add it immediately after the existing layer */ new_layer = BKE_gpencil_layer_duplicate(gpl); @@ -445,19 +451,22 @@ static bool gp_layer_duplicate_object_poll(bContext *C) { ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = CTX_data_active_object(C); - if ((ob == NULL) || (ob->type != OB_GPENCIL)) + if ((ob == NULL) || (ob->type != OB_GPENCIL)) { return false; + } bGPdata *gpd = (bGPdata *)ob->data; bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); - if (gpl == NULL) + if (gpl == NULL) { return false; + } /* check there are more grease pencil objects */ for (Base *base = view_layer->object_bases.first; base; base = base->next) { - if ((base->object != ob) && (base->object->type == OB_GPENCIL)) + if ((base->object != ob) && (base->object->type == OB_GPENCIL)) { return true; + } } return false; @@ -590,8 +599,9 @@ static int gp_frame_duplicate_exec(bContext *C, wmOperator *op) int mode = RNA_enum_get(op->ptr, "mode"); /* sanity checks */ - if (ELEM(NULL, gpd, gpl)) + if (ELEM(NULL, gpd, gpl)) { return OPERATOR_CANCELLED; + } if (mode == 0) { BKE_gpencil_frame_addcopy(gpl, cfra_eval); @@ -655,16 +665,18 @@ static int gp_frame_clean_fill_exec(bContext *C, wmOperator *op) if ((gpf == gpl->actframe) || (mode == GP_FRAME_CLEAN_FILL_ALL)) { bGPDstroke *gps, *gpsn; - if (gpf == NULL) + if (gpf == NULL) { continue; + } /* simply delete strokes which are no fill */ for (gps = gpf->strokes.first; gps; gps = gpsn) { gpsn = gps->next; /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } /* free stroke */ if (gps->flag & GP_STROKE_NOFILL) { @@ -737,16 +749,18 @@ static int gp_frame_clean_loose_exec(bContext *C, wmOperator *op) for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) { if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { - if (gpf == NULL) + if (gpf == NULL) { continue; + } /* simply delete strokes which are no loose */ for (gps = gpf->strokes.first; gps; gps = gpsn) { gpsn = gps->next; /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } /* free stroke */ if (gps->totpoints <= limit) { @@ -817,8 +831,9 @@ static int gp_hide_exec(bContext *C, wmOperator *op) bool unselected = RNA_boolean_get(op->ptr, "unselected"); /* sanity checks */ - if (ELEM(NULL, gpd, layer)) + if (ELEM(NULL, gpd, layer)) { return OPERATOR_CANCELLED; + } if (unselected) { bGPDlayer *gpl; @@ -897,8 +912,9 @@ static int gp_reveal_exec(bContext *C, wmOperator *op) const bool select = RNA_boolean_get(op->ptr, "select"); /* sanity checks */ - if (gpd == NULL) + if (gpd == NULL) { return OPERATOR_CANCELLED; + } for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { @@ -957,8 +973,9 @@ static int gp_lock_all_exec(bContext *C, wmOperator *UNUSED(op)) bGPDlayer *gpl; /* sanity checks */ - if (gpd == NULL) + if (gpd == NULL) { return OPERATOR_CANCELLED; + } /* make all layers non-editable */ for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { @@ -996,8 +1013,9 @@ static int gp_unlock_all_exec(bContext *C, wmOperator *UNUSED(op)) bGPDlayer *gpl; /* sanity checks */ - if (gpd == NULL) + if (gpd == NULL) { return OPERATOR_CANCELLED; + } /* make all layers editable again */ for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { @@ -1036,8 +1054,9 @@ static int gp_isolate_layer_exec(bContext *C, wmOperator *op) int flags = GP_LAYER_LOCKED; bool isolate = false; - if (RNA_boolean_get(op->ptr, "affect_visibility")) + if (RNA_boolean_get(op->ptr, "affect_visibility")) { flags |= GP_LAYER_HIDE; + } if (ELEM(NULL, gpd, layer)) { BKE_report(op->reports, RPT_ERROR, "No active layer to isolate"); @@ -1047,8 +1066,9 @@ static int gp_isolate_layer_exec(bContext *C, wmOperator *op) /* Test whether to isolate or clear all flags */ for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { /* Skip if this is the active layer */ - if (gpl == layer) + if (gpl == layer) { continue; + } /* If the flags aren't set, that means that the layer is * not alone, so we have some layers to isolate still @@ -1064,10 +1084,12 @@ static int gp_isolate_layer_exec(bContext *C, wmOperator *op) if (isolate) { /* Set flags on all "other" layers */ for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { - if (gpl == layer) + if (gpl == layer) { continue; - else + } + else { gpl->flag |= flags; + } } } else { @@ -1424,18 +1446,21 @@ static int gp_stroke_change_color_exec(bContext *C, wmOperator *op) for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) { if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { - if (gpf == NULL) + if (gpf == NULL) { continue; + } for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { /* only if selected */ if (gps->flag & GP_STROKE_SELECT) { /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } /* check if the color is editable */ - if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) + if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) { continue; + } /* assign new color */ gps->mat_nr = idx; @@ -1485,8 +1510,9 @@ static int gp_stroke_lock_color_exec(bContext *C, wmOperator *UNUSED(op)) short *totcol = give_totcolp(ob); /* sanity checks */ - if (ELEM(NULL, gpd)) + if (ELEM(NULL, gpd)) { return OPERATOR_CANCELLED; + } /* first lock all colors */ for (short i = 0; i < *totcol; i++) { @@ -1609,8 +1635,9 @@ static int gpencil_vertex_group_assign_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = CTX_data_active_object(C); /* sanity checks */ - if (ELEM(NULL, ts, ob, ob->data)) + if (ELEM(NULL, ts, ob, ob->data)) { return OPERATOR_CANCELLED; + } ED_gpencil_vgroup_assign(C, ob, ts->vgroup_weight); @@ -1643,8 +1670,9 @@ static int gpencil_vertex_group_remove_from_exec(bContext *C, wmOperator *UNUSED Object *ob = CTX_data_active_object(C); /* sanity checks */ - if (ELEM(NULL, ob, ob->data)) + if (ELEM(NULL, ob, ob->data)) { return OPERATOR_CANCELLED; + } ED_gpencil_vgroup_remove(C, ob); @@ -1676,8 +1704,9 @@ static int gpencil_vertex_group_select_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = CTX_data_active_object(C); /* sanity checks */ - if (ELEM(NULL, ob, ob->data)) + if (ELEM(NULL, ob, ob->data)) { return OPERATOR_CANCELLED; + } ED_gpencil_vgroup_select(C, ob); @@ -1709,8 +1738,9 @@ static int gpencil_vertex_group_deselect_exec(bContext *C, wmOperator *UNUSED(op Object *ob = CTX_data_active_object(C); /* sanity checks */ - if (ELEM(NULL, ob, ob->data)) + if (ELEM(NULL, ob, ob->data)) { return OPERATOR_CANCELLED; + } ED_gpencil_vgroup_deselect(C, ob); @@ -2091,7 +2121,10 @@ typedef struct tJoinGPencil_AdtFixData { GHash *names_map; } tJoinGPencil_AdtFixData; -/* Callback to pass to BKE_fcurves_main_cb() for RNA Paths attached to each F-Curve used in the AnimData */ +/** + * Callback to pass to #BKE_fcurves_main_cb() + * for RNA Paths attached to each F-Curve used in the #AnimData. + */ static void joined_gpencil_fix_animdata_cb(ID *id, FCurve *fcu, void *user_data) { tJoinGPencil_AdtFixData *afd = (tJoinGPencil_AdtFixData *)user_data; @@ -2168,8 +2201,9 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) bool ok = false; /* Ensure we're in right mode and that the active object is correct */ - if (!ob_active || ob_active->type != OB_GPENCIL) + if (!ob_active || ob_active->type != OB_GPENCIL) { return OPERATOR_CANCELLED; + } bGPdata *gpd = (bGPdata *)ob_active->data; if ((!gpd) || GPENCIL_ANY_MODE(gpd)) { @@ -2374,7 +2408,7 @@ static bool gpencil_active_color_poll(bContext *C) return false; } -/* ******************* Lock and hide any color non used in current layer ************************** */ +/* **************** Lock and hide any color non used in current layer ************************** */ static int gpencil_lock_layer_exec(bContext *C, wmOperator *UNUSED(op)) { bGPdata *gpd = ED_gpencil_data_get_active(C); @@ -2382,14 +2416,16 @@ static int gpencil_lock_layer_exec(bContext *C, wmOperator *UNUSED(op)) MaterialGPencilStyle *gp_style = NULL; /* sanity checks */ - if (ELEM(NULL, gpd)) + if (ELEM(NULL, gpd)) { return OPERATOR_CANCELLED; + } /* first lock and hide all colors */ Material *ma = NULL; short *totcol = give_totcolp(ob); - if (totcol == 0) + if (totcol == 0) { return OPERATOR_CANCELLED; + } for (short i = 0; i < *totcol; i++) { ma = give_current_material(ob, i + 1); @@ -2406,8 +2442,9 @@ static int gpencil_lock_layer_exec(bContext *C, wmOperator *UNUSED(op)) (gpl->flag & GP_LAYER_ACTIVE)) { for (bGPDstroke *gps = gpl->actframe->strokes.last; gps; gps = gps->prev) { /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } ma = give_current_material(ob, gps->mat_nr + 1); DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE); @@ -2459,8 +2496,9 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op) int flags = GP_STYLE_COLOR_LOCKED; bool isolate = false; - if (RNA_boolean_get(op->ptr, "affect_visibility")) + if (RNA_boolean_get(op->ptr, "affect_visibility")) { flags |= GP_STYLE_COLOR_HIDE; + } if (ELEM(NULL, gpd, active_color)) { BKE_report(op->reports, RPT_ERROR, "No active color to isolate"); @@ -2473,8 +2511,9 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op) for (short i = 0; i < *totcol; i++) { ma = give_current_material(ob, i + 1); /* Skip if this is the active one */ - if (ma == active_ma) + if (ma == active_ma) { continue; + } /* If the flags aren't set, that means that the color is * not alone, so we have some colors to isolate still @@ -2492,10 +2531,12 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op) for (short i = 0; i < *totcol; i++) { ma = give_current_material(ob, i + 1); gp_style = ma->gp_style; - if (gp_style == active_color) + if (gp_style == active_color) { continue; - else + } + else { gp_style->flag |= flags; + } DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE); } } @@ -2556,8 +2597,9 @@ static int gpencil_color_hide_exec(bContext *C, wmOperator *op) Material *ma = NULL; short *totcol = give_totcolp(ob); - if (totcol == 0) + if (totcol == 0) { return OPERATOR_CANCELLED; + } if (unselected) { /* hide unselected */ @@ -2616,8 +2658,9 @@ static int gpencil_color_reveal_exec(bContext *C, wmOperator *UNUSED(op)) Material *ma = NULL; short *totcol = give_totcolp(ob); - if (totcol == 0) + if (totcol == 0) { return OPERATOR_CANCELLED; + } /* make all colors visible */ MaterialGPencilStyle *gp_style = NULL; @@ -2666,8 +2709,9 @@ static int gpencil_color_lock_all_exec(bContext *C, wmOperator *UNUSED(op)) Material *ma = NULL; short *totcol = give_totcolp(ob); - if (totcol == 0) + if (totcol == 0) { return OPERATOR_CANCELLED; + } /* make all layers non-editable */ MaterialGPencilStyle *gp_style = NULL; @@ -2716,8 +2760,9 @@ static int gpencil_color_unlock_all_exec(bContext *C, wmOperator *UNUSED(op)) Material *ma = NULL; short *totcol = give_totcolp(ob); - if (totcol == 0) + if (totcol == 0) { return OPERATOR_CANCELLED; + } /* make all layers editable again*/ MaterialGPencilStyle *gp_style = NULL; @@ -2767,8 +2812,9 @@ static int gpencil_color_select_exec(bContext *C, wmOperator *op) const bool deselected = RNA_boolean_get(op->ptr, "deselect"); /* sanity checks */ - if (ELEM(NULL, gpd, gp_style)) + if (ELEM(NULL, gpd, gp_style)) { return OPERATOR_CANCELLED; + } /* read all strokes and select*/ CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { @@ -2782,11 +2828,13 @@ static int gpencil_color_select_exec(bContext *C, wmOperator *op) /* verify something to do */ for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } /* check if the color is editable */ - if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) + if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) { continue; + } /* select */ if (ob->actcol == gps->mat_nr + 1) { diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 40e1e483f41..463c2144276 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -286,8 +286,9 @@ static int gpencil_paintmode_toggle_exec(bContext *C, wmOperator *op) is_object = true; } - if (gpd == NULL) + if (gpd == NULL) { return OPERATOR_CANCELLED; + } /* Just toggle paintmode flag... */ gpd->flag ^= GP_DATA_STROKE_PAINTMODE; @@ -386,8 +387,9 @@ static int gpencil_sculptmode_toggle_exec(bContext *C, wmOperator *op) is_object = true; } - if (gpd == NULL) + if (gpd == NULL) { return OPERATOR_CANCELLED; + } /* Just toggle sculptmode flag... */ gpd->flag ^= GP_DATA_STROKE_SCULPTMODE; @@ -475,8 +477,9 @@ static int gpencil_weightmode_toggle_exec(bContext *C, wmOperator *op) is_object = true; } - if (gpd == NULL) + if (gpd == NULL) { return OPERATOR_CANCELLED; + } /* Just toggle weightmode flag... */ gpd->flag ^= GP_DATA_STROKE_WEIGHTMODE; @@ -545,8 +548,9 @@ void GPENCIL_OT_weightmode_toggle(wmOperatorType *ot) static int gpencil_hideselect_toggle_exec(bContext *C, wmOperator *UNUSED(op)) { View3D *v3d = CTX_wm_view3d(C); - if (v3d == NULL) + if (v3d == NULL) { return OPERATOR_CANCELLED; + } /* Just toggle alpha... */ if (v3d->vertex_opacity > 0.0f) { @@ -615,7 +619,7 @@ static void gp_duplicate_points(const bGPDstroke *gps, else if (i == gps->totpoints - 1) { len = i - start_idx + 1; } - //printf("copying from %d to %d = %d\n", start_idx, i, len); + // printf("copying from %d to %d = %d\n", start_idx, i, len); /* make copies of the relevant data */ if (len) { @@ -685,8 +689,9 @@ static int gp_duplicate_exec(bContext *C, wmOperator *op) bGPDframe *gpf = gpl->actframe; bGPDstroke *gps; - if (gpf == NULL) + if (gpf == NULL) { continue; + } /* make copies of selected strokes, and deselect these once we're done */ for (gps = gpf->strokes.first; gps; gps = gps->next) { @@ -931,13 +936,15 @@ static int gp_extrude_exec(bContext *C, wmOperator *op) for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) { if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { - if (gpf == NULL) + if (gpf == NULL) { continue; + } for (gps = gpf->strokes.first; gps; gps = gps->next) { /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } if (gps->flag & GP_STROKE_SELECT) { gpencil_add_move_points(gpf, gps); @@ -1062,7 +1069,8 @@ void ED_gpencil_strokes_copybuf_free(void) gp_strokes_copypastebuf.first = gp_strokes_copypastebuf.last = NULL; } -/* Ensure that destination datablock has all the colours the pasted strokes need +/** + * Ensure that destination datablock has all the colors the pasted strokes need. * Helper function for copy-pasting strokes */ GHash *gp_copybuf_validate_colormap(bContext *C) @@ -1123,14 +1131,16 @@ static int gp_strokes_copy_exec(bContext *C, wmOperator *op) bGPDframe *gpf = gpl->actframe; bGPDstroke *gps; - if (gpf == NULL) + if (gpf == NULL) { continue; + } /* make copies of selected strokes, and deselect these once we're done */ for (gps = gpf->strokes.first; gps; gps = gps->next) { /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } if (gps->flag & GP_STROKE_SELECT) { if (gps->totpoints == 1) { @@ -1202,7 +1212,7 @@ void GPENCIL_OT_copy(wmOperatorType *ot) ot->poll = gp_stroke_edit_poll; /* flags */ - //ot->flag = OPTYPE_REGISTER; + // ot->flag = OPTYPE_REGISTER; } /* --------------------- */ @@ -1212,8 +1222,9 @@ static bool gp_strokes_paste_poll(bContext *C) { /* 1) Must have GP datablock to paste to * - We don't need to have an active layer though, as that can easily get added - * - If the active layer is locked, we can't paste there, but that should prompt a warning instead - * 2) Copy buffer must at least have something (though it may be the wrong sort...) + * - If the active layer is locked, we can't paste there, + * but that should prompt a warning instead. + * 2) Copy buffer must at least have something (though it may be the wrong sort...). */ return (ED_gpencil_data_get_active(C) != NULL) && (!BLI_listbase_is_empty(&gp_strokes_copypastebuf)); @@ -1273,13 +1284,16 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op) } if (ok == false) { - /* XXX: this check is not 100% accurate (i.e. image editor is incompatible with normal 2D strokes), - * but should be enough to give users a good idea of what's going on + /* XXX: this check is not 100% accurate + * (i.e. image editor is incompatible with normal 2D strokes), + * but should be enough to give users a good idea of what's going on. */ - if (CTX_wm_area(C)->spacetype == SPACE_VIEW3D) + if (CTX_wm_area(C)->spacetype == SPACE_VIEW3D) { BKE_report(op->reports, RPT_ERROR, "Cannot paste 2D strokes in 3D View"); - else + } + else { BKE_report(op->reports, RPT_ERROR, "Cannot paste 3D strokes in 2D editors"); + } return OPERATOR_CANCELLED; } @@ -1442,16 +1456,18 @@ static int gp_move_to_layer_exec(bContext *C, wmOperator *op) bGPDstroke *gps, *gpsn; /* skip if no frame with strokes, or if this is the layer we're moving strokes to */ - if ((gpl == target_layer) || (gpf == NULL)) + if ((gpl == target_layer) || (gpf == NULL)) { continue; + } /* make copies of selected strokes, and deselect these once we're done */ for (gps = gpf->strokes.first; gps; gps = gpsn) { gpsn = gps->next; /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } /* TODO: Don't just move entire strokes - instead, only copy the selected portions... */ if (gps->flag & GP_STROKE_SELECT) { @@ -1541,7 +1557,8 @@ static int gp_blank_frame_add_exec(bContext *C, wmOperator *op) /* Initialise datablock and an active layer if nothing exists yet */ if (ELEM(NULL, gpd, active_gpl)) { - /* let's just be lazy, and call the "Add New Layer" operator, which sets everything up as required */ + /* Let's just be lazy, and call the "Add New Layer" operator, + * which sets everything up as required. */ WM_operator_name_call(C, "GPENCIL_OT_layer_add", WM_OP_EXEC_DEFAULT, NULL); } @@ -1676,8 +1693,9 @@ static int gp_actframe_delete_all_exec(bContext *C, wmOperator *op) /* try to get the "active" frame - but only if it actually occurs on this frame */ bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV); - if (gpf == NULL) + if (gpf == NULL) { continue; + } /* delete it... */ BKE_gpencil_layer_delframe(gpl, gpf); @@ -1752,16 +1770,18 @@ static int gp_delete_selected_strokes(bContext *C) if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { bGPDstroke *gps, *gpsn; - if (gpf == NULL) + if (gpf == NULL) { continue; + } /* simply delete strokes which are selected */ for (gps = gpf->strokes.first; gps; gps = gpsn) { gpsn = gps->next; /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } /* free stroke if selected */ if (gps->flag & GP_STROKE_SELECT) { @@ -1817,8 +1837,9 @@ static int gp_dissolve_selected_points(bContext *C, eGP_DissolveMode mode) bGPDstroke *gps, *gpsn; - if (gpf == NULL) + if (gpf == NULL) { continue; + } /* simply delete points from selected strokes * NOTE: we may still have to remove the stroke if it ends up having no points! @@ -1827,11 +1848,13 @@ static int gp_dissolve_selected_points(bContext *C, eGP_DissolveMode mode) gpsn = gps->next; /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } /* check if the color is editable */ - if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) + if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) { continue; + } /* the stroke must have at least one point selected for any operator */ if (gps->flag & GP_STROKE_SELECT) { @@ -2189,7 +2212,8 @@ void gp_stroke_delete_tagged_points(bGPDframe *gpf, /* Watch out for special case where No islands = All points selected = Delete Stroke only */ if (num_islands) { - /* there are islands, so create a series of new strokes, adding them before the "next" stroke */ + /* There are islands, so create a series of new strokes, + * adding them before the "next" stroke. */ int idx; bGPDstroke *new_stroke = NULL; @@ -2239,13 +2263,13 @@ void gp_stroke_delete_tagged_points(bGPDframe *gpf, e++; } } - /* Each island corresponds to a new stroke. We must adjust the - * timings of these new strokes: + /* Each island corresponds to a new stroke. + * We must adjust the timings of these new strokes: * - * Each point's timing data is a delta from stroke's inittime, so as we erase some points from - * the start of the stroke, we have to offset this inittime and all remaining points' delta values. - * This way we get a new stroke with exactly the same timing as if user had started drawing from - * the first non-removed point... + * Each point's timing data is a delta from stroke's inittime, so as we erase some points + * from the start of the stroke, we have to offset this inittime and all remaining points' + * delta values. This way we get a new stroke with exactly the same timing as if user had + * started drawing from the first non-removed point. */ { bGPDspoint *pts; @@ -2310,19 +2334,22 @@ static int gp_delete_selected_points(bContext *C) if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { bGPDstroke *gps, *gpsn; - if (gpf == NULL) + if (gpf == NULL) { continue; + } /* simply delete strokes which are selected */ for (gps = gpf->strokes.first; gps; gps = gpsn) { gpsn = gps->next; /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } /* check if the color is editable */ - if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) + if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) { continue; + } if (gps->flag & GP_STROKE_SELECT) { /* deselect old stroke, since it will be used as template for the new strokes */ @@ -2496,11 +2523,13 @@ static int gp_snap_to_grid(bContext *C, wmOperator *UNUSED(op)) int i; /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } /* check if the color is editable */ - if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) + if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) { continue; + } // TODO: if entire stroke is selected, offset entire stroke by same amount? for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { @@ -2571,14 +2600,17 @@ static int gp_snap_to_cursor(bContext *C, wmOperator *op) int i; /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } /* check if the color is editable */ - if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) + if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) { continue; + } /* only continue if this stroke is selected (editable doesn't guarantee this)... */ - if ((gps->flag & GP_STROKE_SELECT) == 0) + if ((gps->flag & GP_STROKE_SELECT) == 0) { continue; + } if (use_offset) { float offset[3]; @@ -2666,14 +2698,17 @@ static int gp_snap_cursor_to_sel(bContext *C, wmOperator *UNUSED(op)) int i; /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } /* check if the color is editable */ - if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) + if (ED_gpencil_stroke_color_use(obact, gpl, gps) == false) { continue; + } /* only continue if this stroke is selected (editable doesn't guarantee this)... */ - if ((gps->flag & GP_STROKE_SELECT) == 0) + if ((gps->flag & GP_STROKE_SELECT) == 0) { continue; + } for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { if (pt->flag & GP_SPOINT_SELECT) { @@ -2728,8 +2763,9 @@ static int gp_stroke_apply_thickness_exec(bContext *C, wmOperator *UNUSED(op)) bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); /* sanity checks */ - if (ELEM(NULL, gpd, gpl, gpl->frames.first)) + if (ELEM(NULL, gpd, gpl, gpl->frames.first)) { return OPERATOR_CANCELLED; + } /* loop all strokes */ for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { @@ -2782,24 +2818,28 @@ static int gp_stroke_cyclical_set_exec(bContext *C, wmOperator *op) const int type = RNA_enum_get(op->ptr, "type"); /* sanity checks */ - if (ELEM(NULL, gpd)) + if (ELEM(NULL, gpd)) { return OPERATOR_CANCELLED; + } /* loop all selected strokes */ CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { - if (gpl->actframe == NULL) + if (gpl->actframe == NULL) { continue; + } for (bGPDstroke *gps = gpl->actframe->strokes.last; gps; gps = gps->prev) { MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1); /* skip strokes that are not selected or invalid for current view */ - if (((gps->flag & GP_STROKE_SELECT) == 0) || ED_gpencil_stroke_can_use(C, gps) == false) + if (((gps->flag & GP_STROKE_SELECT) == 0) || ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } /* skip hidden or locked colors */ if (!gp_style || (gp_style->flag & GP_STYLE_COLOR_HIDE) || - (gp_style->flag & GP_STYLE_COLOR_LOCKED)) + (gp_style->flag & GP_STYLE_COLOR_LOCKED)) { continue; + } switch (type) { case GP_STROKE_CYCLIC_CLOSE: @@ -2875,13 +2915,15 @@ static int gp_stroke_caps_set_exec(bContext *C, wmOperator *op) const int type = RNA_enum_get(op->ptr, "type"); /* sanity checks */ - if (ELEM(NULL, gpd)) + if (ELEM(NULL, gpd)) { return OPERATOR_CANCELLED; + } /* loop all selected strokes */ CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { - if (gpl->actframe == NULL) + if (gpl->actframe == NULL) { continue; + } for (bGPDstroke *gps = gpl->actframe->strokes.last; gps; gps = gps->prev) { MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1); @@ -3044,11 +3086,13 @@ static void gpencil_stroke_join_strokes(bGPDstroke *gps_a, float deltatime = 0.0f; /* sanity checks */ - if (ELEM(NULL, gps_a, gps_b)) + if (ELEM(NULL, gps_a, gps_b)) { return; + } - if ((gps_a->totpoints == 0) || (gps_b->totpoints == 0)) + if ((gps_a->totpoints == 0) || (gps_b->totpoints == 0)) { return; + } /* define start and end points of each stroke */ float sa[3], sb[3], ea[3], eb[3]; @@ -3109,11 +3153,13 @@ static int gp_stroke_join_exec(bContext *C, wmOperator *op) const bool leave_gaps = RNA_boolean_get(op->ptr, "leave_gaps"); /* sanity checks */ - if (ELEM(NULL, gpd)) + if (ELEM(NULL, gpd)) { return OPERATOR_CANCELLED; + } - if (activegpl->flag & GP_LAYER_LOCKED) + if (activegpl->flag & GP_LAYER_LOCKED) { return OPERATOR_CANCELLED; + } BLI_assert(ELEM(type, GP_STROKE_JOIN, GP_STROKE_JOINCOPY)); @@ -3121,8 +3167,9 @@ static int gp_stroke_join_exec(bContext *C, wmOperator *op) bool first = false; CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { bGPDframe *gpf = gpl->actframe; - if (gpf == NULL) + if (gpf == NULL) { continue; + } for (gps = gpf->strokes.first; gps; gps = gpsn) { gpsn = gps->next; @@ -3193,8 +3240,9 @@ static int gp_stroke_join_exec(bContext *C, wmOperator *op) if (type == GP_STROKE_JOINCOPY) { if (new_stroke) { /* Add a new frame if needed */ - if (activegpl->actframe == NULL) + if (activegpl->actframe == NULL) { activegpl->actframe = BKE_gpencil_frame_addnew(activegpl, gpf_a->framenum); + } BLI_addtail(&activegpl->actframe->strokes, new_stroke); } @@ -3244,14 +3292,16 @@ static int gp_stroke_flip_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = CTX_data_active_object(C); /* sanity checks */ - if (ELEM(NULL, gpd)) + if (ELEM(NULL, gpd)) { return OPERATOR_CANCELLED; + } /* read all selected strokes */ CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { bGPDframe *gpf = gpl->actframe; - if (gpf == NULL) + if (gpf == NULL) { continue; + } for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { if (gps->flag & GP_STROKE_SELECT) { @@ -3566,8 +3616,9 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op) int i2; /* sanity checks */ - if (ELEM(NULL, gpd)) + if (ELEM(NULL, gpd)) { return OPERATOR_CANCELLED; + } /* Go through each editable + selected stroke */ GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) { @@ -3728,8 +3779,9 @@ static int gp_stroke_simplify_exec(bContext *C, wmOperator *op) float factor = RNA_float_get(op->ptr, "factor"); /* sanity checks */ - if (ELEM(NULL, gpd)) + if (ELEM(NULL, gpd)) { return OPERATOR_CANCELLED; + } /* Go through each editable + selected stroke */ GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) { @@ -3776,8 +3828,9 @@ static int gp_stroke_simplify_fixed_exec(bContext *C, wmOperator *op) int steps = RNA_int_get(op->ptr, "step"); /* sanity checks */ - if (ELEM(NULL, gpd)) + if (ELEM(NULL, gpd)) { return OPERATOR_CANCELLED; + } /* Go through each editable + selected stroke */ GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) { @@ -3825,8 +3878,9 @@ static int gp_stroke_trim_exec(bContext *C, wmOperator *UNUSED(op)) bGPdata *gpd = ED_gpencil_data_get_active(C); /* sanity checks */ - if (ELEM(NULL, gpd)) + if (ELEM(NULL, gpd)) { return OPERATOR_CANCELLED; + } /* Go through each editable + selected stroke */ const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd); @@ -3841,15 +3895,17 @@ static int gp_stroke_trim_exec(bContext *C, wmOperator *UNUSED(op)) if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { bGPDstroke *gps, *gpsn; - if (gpf == NULL) + if (gpf == NULL) { continue; + } for (gps = gpf->strokes.first; gps; gps = gpsn) { gpsn = gps->next; /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } if (gps->flag & GP_STROKE_SELECT) { BKE_gpencil_trim_stroke(gps); @@ -4202,8 +4258,9 @@ static int gp_stroke_smooth_exec(bContext *C, wmOperator *op) bGPdata *gpd = ED_gpencil_data_get_active(C); /* sanity checks */ - if (ELEM(NULL, gpd)) + if (ELEM(NULL, gpd)) { return OPERATOR_CANCELLED; + } gp_smooth_stroke(C, op); @@ -4424,8 +4481,9 @@ static bool gpencil_cutter_poll(bContext *C) bGPdata *gpd = ED_gpencil_data_get_active(C); if (GPENCIL_PAINT_MODE(gpd)) { - if (gpd->layers.first) + if (gpd->layers.first) { return true; + } } return false; diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c index 8d3137ed3db..96f405fab2f 100644 --- a/source/blender/editors/gpencil/gpencil_fill.c +++ b/source/blender/editors/gpencil/gpencil_fill.c @@ -250,8 +250,9 @@ static void gp_draw_datablock(tGPDfill *tgpf, const float ink[4]) ED_gpencil_parent_location(tgpw.depsgraph, ob, gpd, gpl, tgpw.diff_mat); /* do not draw layer if hidden */ - if (gpl->flag & GP_LAYER_HIDE) + if (gpl->flag & GP_LAYER_HIDE) { continue; + } /* if active layer and no keyframe, create a new one */ if (gpl == tgpf->gpl) { @@ -262,8 +263,9 @@ static void gp_draw_datablock(tGPDfill *tgpf, const float ink[4]) /* get frame to draw */ bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV); - if (gpf == NULL) + if (gpf == NULL) { continue; + } for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { /* check if stroke can be drawn */ @@ -453,7 +455,7 @@ static void get_pixel(const ImBuf *ibuf, const int idx, float r_col[4]) /* set pixel data (rgba) at index */ static void set_pixel(ImBuf *ibuf, int idx, const float col[4]) { - //BLI_assert(idx <= ibuf->x * ibuf->y); + // BLI_assert(idx <= ibuf->x * ibuf->y); if (ibuf->rect) { uint *rrect = &ibuf->rect[idx]; uchar ccol[4]; @@ -930,7 +932,8 @@ static void gpencil_get_depth_array(tGPDfill *tgpf) view3d_region_operator_needs_opengl(tgpf->win, tgpf->ar); ED_view3d_autodist_init(tgpf->depsgraph, tgpf->ar, tgpf->v3d, 0); - /* since strokes are so fine, when using their depth we need a margin otherwise they might get missed */ + /* Since strokes are so fine, when using their depth we need a margin + * otherwise they might get missed. */ int depth_margin = 0; /* get an array of depths, far depths are blended */ @@ -959,8 +962,9 @@ static void gpencil_get_depth_array(tGPDfill *tgpf) if (found_depth == false) { /* eeh... not much we can do.. :/, ignore depth in this case */ - for (i = totpoints - 1; i >= 0; i--) + for (i = totpoints - 1; i >= 0; i--) { tgpf->depth_arr[i] = 0.9999f; + } } else { if (interp_depth) { @@ -1346,8 +1350,9 @@ static int gpencil_fill_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE /* try to initialize context data needed */ if (!gpencil_fill_init(C, op)) { gpencil_fill_exit(C, op); - if (op->customdata) + if (op->customdata) { MEM_freeN(op->customdata); + } return OPERATOR_CANCELLED; } else { diff --git a/source/blender/editors/gpencil/gpencil_interpolate.c b/source/blender/editors/gpencil/gpencil_interpolate.c index 5c9b9416330..d83cc7858bd 100644 --- a/source/blender/editors/gpencil/gpencil_interpolate.c +++ b/source/blender/editors/gpencil/gpencil_interpolate.c @@ -541,8 +541,9 @@ static int gpencil_interpolate_invoke(bContext *C, wmOperator *op, const wmEvent /* try to initialize context data needed */ if (!gpencil_interpolate_init(C, op)) { - if (op->customdata) + if (op->customdata) { MEM_freeN(op->customdata); + } return OPERATOR_CANCELLED; } else { @@ -1129,8 +1130,9 @@ static int gpencil_interpolate_reverse_exec(bContext *C, wmOperator *UNUSED(op)) bGPDframe *gpf, *gpfn; /* Only continue if we're currently on a breakdown keyframe */ - if ((gpl->actframe == NULL) || (gpl->actframe->key_type != BEZT_KEYTYPE_BREAKDOWN)) + if ((gpl->actframe == NULL) || (gpl->actframe->key_type != BEZT_KEYTYPE_BREAKDOWN)) { continue; + } /* Search left for "start_key" (i.e. the first breakdown to remove) */ gpf = gpl->actframe; diff --git a/source/blender/editors/gpencil/gpencil_merge.c b/source/blender/editors/gpencil/gpencil_merge.c index 48c761919e5..9d3c2a6e271 100644 --- a/source/blender/editors/gpencil/gpencil_merge.c +++ b/source/blender/editors/gpencil/gpencil_merge.c @@ -66,10 +66,12 @@ static int gpencil_sort_points(const void *a1, const void *a2) { const tGPencilPointCache *ps1 = a1, *ps2 = a2; - if (ps1->factor < ps2->factor) + if (ps1->factor < ps2->factor) { return -1; - else if (ps1->factor > ps2->factor) + } + else if (ps1->factor > ps2->factor) { return 1; + } return 0; } diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c index fce8fa79217..db4c601709c 100644 --- a/source/blender/editors/gpencil/gpencil_ops.c +++ b/source/blender/editors/gpencil/gpencil_ops.c @@ -362,7 +362,7 @@ void ED_operatormacros_gpencil(void) WM_operatortype_macro_define(ot, "GPENCIL_OT_duplicate"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); RNA_boolean_set(otmacro->ptr, "gpencil_strokes", true); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); /* Extrude + Move = Interactively add new points */ @@ -373,7 +373,7 @@ void ED_operatormacros_gpencil(void) WM_operatortype_macro_define(ot, "GPENCIL_OT_extrude"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); RNA_boolean_set(otmacro->ptr, "gpencil_strokes", true); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); } diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index bfdfe64ed54..b1b29356060 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -178,7 +178,8 @@ typedef struct tGPsdata { /* These need to be doubles, as (at least under unix) they are in seconds since epoch, * float (and its 7 digits precision) is definitively not enough here! - * double, with its 15 digits precision, ensures us millisecond precision for a few centuries at least. + * double, with its 15 digits precision, + * ensures us millisecond precision for a few centuries at least. */ /** Used when converting to path. */ double inittime; @@ -367,19 +368,23 @@ static bool gp_stroke_filtermval(tGPsdata *p, const float mval[2], float mvalo[2 /* check if mouse moved at least certain distance on both axes (best case) * - aims to eliminate some jitter-noise from input when trying to draw straight lines freehand */ - else if ((dx > MIN_MANHATTEN_PX) && (dy > MIN_MANHATTEN_PX)) + else if ((dx > MIN_MANHATTEN_PX) && (dy > MIN_MANHATTEN_PX)) { return true; - /* check if the distance since the last point is significant enough - * - prevents points being added too densely - * - distance here doesn't use sqrt to prevent slowness... we should still be safe from overflows though - */ - else if ((dx * dx + dy * dy) > MIN_EUCLIDEAN_PX * MIN_EUCLIDEAN_PX) + /* Check if the distance since the last point is significant enough: + * - Prevents points being added too densely + * - Distance here doesn't use sqrt to prevent slowness. + * We should still be safe from overflows though. + */ + } + else if ((dx * dx + dy * dy) > MIN_EUCLIDEAN_PX * MIN_EUCLIDEAN_PX) { return true; - /* mouse 'didn't move' */ - else + /* mouse 'didn't move' */ + } + else { return false; + } } /* reproject stroke to plane locked to axis in 3d cursor location */ @@ -657,8 +662,9 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure } else if (p->paintmode == GP_PAINTMODE_DRAW) { /* normal drawing */ /* check if still room in buffer */ - if (gpd->runtime.sbuffer_size >= GP_STROKE_BUFFER_MAX) + if (gpd->runtime.sbuffer_size >= GP_STROKE_BUFFER_MAX) { return GP_STROKEADD_OVERFLOW; + } /* get pointer to destination point */ pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_size); @@ -793,10 +799,12 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure } /* check if another operation can still occur */ - if (gpd->runtime.sbuffer_size == GP_STROKE_BUFFER_MAX) + if (gpd->runtime.sbuffer_size == GP_STROKE_BUFFER_MAX) { return GP_STROKEADD_FULL; - else + } + else { return GP_STROKEADD_NORMAL; + } } else if (p->paintmode == GP_PAINTMODE_DRAW_POLY) { @@ -881,8 +889,9 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure } /* increment counters */ - if (gpd->runtime.sbuffer_size == 0) + if (gpd->runtime.sbuffer_size == 0) { gpd->runtime.sbuffer_size++; + } return GP_STROKEADD_NORMAL; } @@ -913,22 +922,26 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) (!is_depth); int i, totelem; - /* since strokes are so fine, when using their depth we need a margin otherwise they might get missed */ + /* Since strokes are so fine, + * when using their depth we need a margin otherwise they might get missed. */ int depth_margin = (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 4 : 0; /* get total number of points to allocate space for * - drawing straight-lines only requires the endpoints */ - if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) + if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) { totelem = (gpd->runtime.sbuffer_size >= 2) ? 2 : gpd->runtime.sbuffer_size; - else + } + else { totelem = gpd->runtime.sbuffer_size; + } /* exit with error if no valid points from this stroke */ if (totelem == 0) { - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: No valid points in stroke buffer to convert (tot=%d)\n", gpd->runtime.sbuffer_size); + } return; } @@ -1112,8 +1125,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) if (found_depth == false) { /* eeh... not much we can do.. :/, ignore depth in this case, use the 3D cursor */ - for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) + for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) { depth_arr[i] = 0.9999f; + } } else { if ((ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE_ENDPOINTS) || @@ -1123,8 +1137,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) /* find first valid contact point */ for (i = 0; i < gpd->runtime.sbuffer_size; i++) { - if (depth_arr[i] != FLT_MAX) + if (depth_arr[i] != FLT_MAX) { break; + } } first_valid = i; @@ -1134,8 +1149,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) } else { for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) { - if (depth_arr[i] != FLT_MAX) + if (depth_arr[i] != FLT_MAX) { break; + } } last_valid = i; } @@ -1189,10 +1205,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) gp_randomize_stroke(gps, brush, p->rng); } - /* smooth stroke after subdiv - only if there's something to do - * for each iteration, the factor is reduced to get a better smoothing without changing too much - * the original stroke - */ + /* Smooth stroke after subdiv - only if there's something to do for each iteration, + * the factor is reduced to get a better smoothing + * without changing too much the original stroke. */ if ((brush->gpencil_settings->flag & GP_BRUSH_GROUP_SETTINGS) && (brush->gpencil_settings->draw_smoothfac > 0.0f)) { float reduce = 0.0f; @@ -1223,8 +1238,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) ED_gpencil_project_stroke_to_view(p->C, p->gpl, gps); } - if (depth_arr) + if (depth_arr) { MEM_freeN(depth_arr); + } } /* Save material index */ @@ -1233,9 +1249,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) /* calculate UVs along the stroke */ ED_gpencil_calc_stroke_uv(obact, gps); - /* add stroke to frame, usually on tail of the listbase, but if on back is enabled the stroke is added on listbase head - * because the drawing order is inverse and the head stroke is the first to draw. This is very useful for artist - * when drawing the background + /* add stroke to frame, usually on tail of the listbase, but if on back is enabled the stroke + * is added on listbase head because the drawing order is inverse and the head stroke is the + * first to draw. This is very useful for artist when drawing the background. */ if ((ts->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK) && (p->paintmode != GP_PAINTMODE_DRAW_POLY)) { @@ -1362,8 +1378,9 @@ static void gp_free_stroke(bGPdata *gpd, bGPDframe *gpf, bGPDstroke *gps) MEM_freeN(gps->dvert); } - if (gps->triangles) + if (gps->triangles) { MEM_freeN(gps->triangles); + } BLI_freelinkN(&gpf->strokes, gps); gp_update_cache(gpd); } @@ -1458,8 +1475,9 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p, for (i = 0; (i + 1) < gps->totpoints; i++) { /* only process if it hasn't been masked out... */ - if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT)) + if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT)) { continue; + } /* get points to work with */ pt1 = gps->points + i; @@ -1510,8 +1528,9 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p, pt2 = gps->points + i + 1; /* only process if it hasn't been masked out... */ - if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT)) + if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT)) { continue; + } bGPDspoint npt; if (pt0) { @@ -1881,8 +1900,9 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p) /* make sure the active view (at the starting time) is a 3d-view */ if (curarea == NULL) { p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: No active view for painting\n"); + } return 0; } @@ -1913,10 +1933,11 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p) if (ar->regiondata == NULL) { p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf( "Error: 3D-View active region doesn't have any region data, so cannot be " "drawable\n"); + } return 0; } @@ -1941,8 +1962,9 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p) /* unsupported views */ default: { p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: Active view not appropriate for Grease Pencil drawing\n"); + } return 0; } } @@ -1951,14 +1973,16 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p) gpd_ptr = ED_gpencil_data_get_pointers(C, &p->ownerPtr); if ((gpd_ptr == NULL) || ED_gpencil_data_owner_is_annotation(&p->ownerPtr)) { p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: Current context doesn't allow for any Grease Pencil data\n"); + } return 0; } else { /* if no existing GPencil block exists, add one */ - if (*gpd_ptr == NULL) + if (*gpd_ptr == NULL) { *gpd_ptr = BKE_gpencil_data_addnew(bmain, "GPencil"); + } p->gpd = *gpd_ptr; } @@ -2033,8 +2057,9 @@ static void gp_session_cleanup(tGPsdata *p) bGPdata *gpd = (p) ? p->gpd : NULL; /* error checking */ - if (gpd == NULL) + if (gpd == NULL) { return; + } /* free stroke buffer */ if (gpd->runtime.sbuffer) { @@ -2076,8 +2101,9 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps } if ((paintmode != GP_PAINTMODE_ERASER) && (p->gpl->flag & GP_LAYER_LOCKED)) { p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: Cannot paint on locked layer\n"); + } return; } @@ -2092,8 +2118,9 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps for (bGPDlayer *gpl = p->gpd->layers.first; gpl; gpl = gpl->next) { /* Skip if layer not editable */ - if (gpencil_layer_is_editable(gpl) == false) + if (gpencil_layer_is_editable(gpl) == false) { continue; + } /* Add a new frame if needed (and based off the active frame, * as we need some existing strokes to erase) @@ -2134,17 +2161,20 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps /* Drawing Modes - Add a new frame if needed on the active layer */ short add_frame_mode; - if (ts->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST) + if (ts->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST) { add_frame_mode = GP_GETFRAME_ADD_COPY; - else + } + else { add_frame_mode = GP_GETFRAME_ADD_NEW; + } p->gpf = BKE_gpencil_layer_getframe(p->gpl, cfra_eval, add_frame_mode); if (p->gpf == NULL) { p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: No frame created (gpencil_paint_init)\n"); + } return; } else { @@ -2251,8 +2281,9 @@ static void gp_paint_cleanup(tGPsdata *p) } /* "unlock" frame */ - if (p->gpf) + if (p->gpf) { p->gpf->flag &= ~GP_FRAME_PAINT; + } } /* ------------------------------- */ @@ -2288,14 +2319,13 @@ static void gpencil_draw_eraser(bContext *UNUSED(C), int x, int y, void *p_ptr) immUniform1f("dash_width", 12.0f); immUniform1f("dash_factor", 0.5f); - imm_draw_circle_wire_2d( - shdr_pos, - x, - y, - p->radius, - /* XXX Dashed shader gives bad results with sets of small segments currently, - * temp hack around the issue. :( */ - max_ii(8, p->radius / 2)); /* was fixed 40 */ + imm_draw_circle_wire_2d(shdr_pos, + x, + y, + p->radius, + /* XXX Dashed shader gives bad results with sets of small segments + * currently, temp hack around the issue. :( */ + max_ii(8, p->radius / 2)); /* was fixed 40 */ immUnbindProgram(); @@ -2544,7 +2574,8 @@ static void gpencil_draw_apply(bContext *C, wmOperator *op, tGPsdata *p, Depsgra copy_v2_v2(p->mvalo, p->mval); p->opressure = p->pressure; } - /* only add current point to buffer if mouse moved (even though we got an event, it might be just noise) */ + /* Only add current point to buffer if mouse moved + * (even though we got an event, it might be just noise). */ else if (gp_stroke_filtermval(p, p->mval, p->mvalo)) { /* if lazy mouse, interpolate the last and current mouse positions */ @@ -2584,8 +2615,9 @@ static void gpencil_draw_apply(bContext *C, wmOperator *op, tGPsdata *p, Depsgra BKE_report(op->reports, RPT_ERROR, "Cannot paint stroke"); p->status = GP_STATUS_ERROR; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: Grease-Pencil Paint - Add Point Invalid\n"); + } return; } @@ -2684,6 +2716,8 @@ static void gpencil_draw_apply_event( PointerRNA itemptr; float mousef[2]; int tablet = 0; + bool is_speed_guide = ((guide->use_guide) && + (p->brush && (p->brush->gpencil_tool == GPAINT_TOOL_DRAW))); /* convert from window-space to area-space mouse coordinates * add any x,y override position for fake events @@ -2693,7 +2727,7 @@ static void gpencil_draw_apply_event( p->shift = event->shift; /* verify direction for straight lines */ - if ((guide->use_guide) || + if ((is_speed_guide) || ((event->alt > 0) && (RNA_boolean_get(op->ptr, "disable_straight") == false))) { if (p->straight == 0) { int dx = (int)fabsf(p->mval[0] - p->mvali[0]); @@ -2791,7 +2825,7 @@ static void gpencil_draw_apply_event( /* special exception for grid snapping * it requires direction which needs at least two points */ - if (!ELEM(p->paintmode, GP_PAINTMODE_ERASER, GP_PAINTMODE_SET_CP) && guide->use_guide && + if (!ELEM(p->paintmode, GP_PAINTMODE_ERASER, GP_PAINTMODE_SET_CP) && is_speed_guide && guide->use_snapping && (guide->type == GP_GUIDE_GRID)) { p->flags |= GP_PAINTFLAG_REQ_VECTOR; } @@ -2819,9 +2853,9 @@ static void gpencil_draw_apply_event( } /* check if stroke is straight or guided */ - if ((p->paintmode != GP_PAINTMODE_ERASER) && ((p->straight) || (guide->use_guide))) { + if ((p->paintmode != GP_PAINTMODE_ERASER) && ((p->straight) || (is_speed_guide))) { /* guided stroke */ - if (guide->use_guide) { + if (is_speed_guide) { switch (guide->type) { default: case GP_GUIDE_CIRCULAR: { @@ -2943,8 +2977,9 @@ static int gpencil_draw_exec(bContext *C, wmOperator *op) /* printf("\tGP - no valid data\n"); */ return OPERATOR_CANCELLED; } - else + else { p = op->customdata; + } /* printf("\tGP - Start redrawing stroke\n"); */ @@ -3082,10 +3117,12 @@ static void gpencil_guide_event_handling(bContext *C, add_notifier = true; float angle = guide->angle; float adjust = (float)M_PI / 180.0f; - if (event->alt) + if (event->alt) { adjust *= 45.0f; - else if (!event->shift) + } + else if (!event->shift) { adjust *= 15.0f; + } angle += (event->type == JKEY) ? adjust : -adjust; angle = angle_compat_rad(angle, M_PI); guide->angle = angle; @@ -3103,8 +3140,9 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event Object *ob = CTX_data_active_object(C); bGPdata *gpd = (bGPdata *)ob->data; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("GPencil - Starting Drawing\n"); + } /* support for tablets eraser pen */ if (gpencil_is_tablet_eraser_active(event)) { @@ -3140,14 +3178,17 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event /* try to initialize context data needed while drawing */ if (!gpencil_draw_init(C, op, event)) { - if (op->customdata) + if (op->customdata) { MEM_freeN(op->customdata); - if (G.debug & G_DEBUG) + } + if (G.debug & G_DEBUG) { printf("\tGP - no valid data\n"); + } return OPERATOR_CANCELLED; } - else + else { p = op->customdata; + } /* TODO: set any additional settings that we can take from the events? * TODO? if tablet is erasing, force eraser to be on? */ @@ -3237,8 +3278,9 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op) /* XXX: watch it with the paintmode! in future, * it'd be nice to allow changing paint-mode when in sketching-sessions */ - if (gp_session_initdata(C, op, p)) + if (gp_session_initdata(C, op, p)) { gp_paint_initstroke(p, p->paintmode, CTX_data_depsgraph(C)); + } if (p->status != GP_STATUS_ERROR) { p->status = GP_STATUS_PAINTING; @@ -3266,10 +3308,12 @@ static void gpencil_stroke_end(wmOperator *op) p->gpf = NULL; } -/* Move last stroke in the listbase to the head to be drawn below all previous strokes in the layer */ +/* Move last stroke in the listbase to the head + * to be drawn below all previous strokes in the layer. */ static void gpencil_move_last_stroke_to_back(bContext *C) { - /* move last stroke (the polygon) to head of the listbase stroke to draw on back of all previous strokes */ + /* Move last stroke (the polygon) to head of the listbase stroke + * to draw on back of all previous strokes. */ bGPdata *gpd = ED_gpencil_data_get_active(C); bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); @@ -3430,7 +3474,8 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) } } - /* we don't pass on key events, GP is used with key-modifiers - prevents Dkey to insert drivers */ + /* We don't pass on key events, GP is used with key-modifiers - + * prevents Dkey to insert drivers. */ if (ISKEYBOARD(event->type)) { if (ELEM(event->type, LEFTARROWKEY, DOWNARROWKEY, RIGHTARROWKEY, UPARROWKEY, ZKEY)) { /* allow some keys: @@ -3462,10 +3507,12 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) } } - //printf("\tGP - handle modal event...\n"); + // printf("\tGP - handle modal event...\n"); - /* exit painting mode (and/or end current stroke) - * NOTE: cannot do RIGHTMOUSE (as is standard for canceling) as that would break polyline [#32647] + /* Exit painting mode (and/or end current stroke). + * + * NOTE: cannot do RIGHTMOUSE (as is standard for canceling) + * as that would break polyline T32647. */ /* if polyline and release shift must cancel */ if ((ELEM(event->type, RETKEY, PADENTER, ESCKEY, SPACEKEY, EKEY)) || @@ -3587,8 +3634,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) p->status = GP_STATUS_ERROR; estate = OPERATOR_CANCELLED; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("%s: Region under cursor is out of bounds, so cannot be drawn on\n", __func__); + } } } else if (p->ar) { @@ -3603,8 +3651,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) p->status = GP_STATUS_ERROR; estate = OPERATOR_CANCELLED; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("%s: No active region found in GP Paint session data\n", __func__); + } } if (in_bounds) { @@ -3661,7 +3710,7 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) /* handle drawing event */ /* printf("\t\tGP - add point\n"); */ - if (((p->flags & GP_PAINTFLAG_FIRSTRUN) == 0) || (guide->use_guide)) { + if (((p->flags & GP_PAINTFLAG_FIRSTRUN) == 0)) { gpencil_add_missing_events(C, op, event, p); } @@ -3695,8 +3744,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) case PADMINUS: p->radius -= 5; - if (p->radius <= 0) + if (p->radius <= 0) { p->radius = 1; + } break; } @@ -3717,8 +3767,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) } /* gpencil modal operator stores area, which can be removed while using it (like fullscreen) */ - if (0 == gpencil_area_exists(C, p->sa)) + if (0 == gpencil_area_exists(C, p->sa)) { estate = OPERATOR_CANCELLED; + } else { /* update status indicators - cursor, header, etc. */ gpencil_draw_status_indicators(C, p); @@ -3748,7 +3799,9 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) /* event doesn't need to be handled */ #if 0 printf("unhandled event -> %d (mmb? = %d | mmv? = %d)\n", - event->type, event->type == MIDDLEMOUSE, event->type == MOUSEMOVE); + event->type, + event->type == MIDDLEMOUSE, + event->type == MOUSEMOVE); #endif break; } diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index f178d232376..08fee2bb393 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -129,8 +129,9 @@ static void gp_session_validatebuffer(tGPDprimitive *p) gpd->runtime.sbuffer_sflag = 0; gpd->runtime.sbuffer_sflag |= GP_STROKE_3DSPACE; - if (ELEM(p->type, GP_STROKE_BOX, GP_STROKE_CIRCLE)) + if (ELEM(p->type, GP_STROKE_BOX, GP_STROKE_CIRCLE)) { gpd->runtime.sbuffer_sflag |= GP_STROKE_CYCLIC; + } } static void gp_init_colors(tGPDprimitive *p) @@ -174,16 +175,20 @@ static void gpencil_primitive_to_square(tGPDprimitive *tgpi, const float x, cons float w = fabsf(x); float h = fabsf(y); if ((x > 0 && y > 0) || (x < 0 && y < 0)) { - if (w > h) + if (w > h) { tgpi->end[1] = tgpi->origin[1] + x; - else + } + else { tgpi->end[0] = tgpi->origin[0] + y; + } } else { - if (w > h) + if (w > h) { tgpi->end[1] = tgpi->origin[1] - x; - else + } + else { tgpi->end[0] = tgpi->origin[0] - y; + } } } @@ -289,8 +294,9 @@ static void gpencil_primitive_allocate_memory(tGPDprimitive *tgpi) tgpi->point_count += (tgpi->type == GP_STROKE_BOX) ? (MAX_EDGES * 4 + 1) : (MAX_EDGES + 1); bGPDstroke *gpsf = tgpi->gpf->strokes.first; gpsf->points = MEM_reallocN(gpsf->points, sizeof(bGPDspoint) * tgpi->point_count); - if (gpsf->dvert != NULL) + if (gpsf->dvert != NULL) { gpsf->dvert = MEM_reallocN(gpsf->dvert, sizeof(MDeformVert) * tgpi->point_count); + } tgpi->points = MEM_reallocN(tgpi->points, sizeof(tGPspoint) * tgpi->point_count); } @@ -675,13 +681,16 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) const bool is_camera = (bool)(ts->gp_sculpt.lock_axis == 0) && (tgpi->rv3d->persp == RV3D_CAMOB) && (!is_depth); - if (tgpi->type == GP_STROKE_BOX) + if (tgpi->type == GP_STROKE_BOX) { gps->totpoints = (tgpi->tot_edges * 4 + tgpi->tot_stored_edges); - else + } + else { gps->totpoints = (tgpi->tot_edges + tgpi->tot_stored_edges); + } - if (tgpi->tot_stored_edges) + if (tgpi->tot_stored_edges) { gps->totpoints--; + } tgpi->gpd->runtime.tot_cp_points = 0; @@ -778,8 +787,9 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) /* find first valid contact point */ for (i = 0; i < gps->totpoints; i++) { - if (depth_arr[i] != FLT_MAX) + if (depth_arr[i] != FLT_MAX) { break; + } } first_valid = i; @@ -789,8 +799,9 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) } else { for (i = gps->totpoints - 1; i >= 0; i--) { - if (depth_arr[i] != FLT_MAX) + if (depth_arr[i] != FLT_MAX) { break; + } } last_valid = i; } @@ -1325,16 +1336,18 @@ static void gpencil_primitive_edit_event_handling( float dy = (tgpi->mval[1] - tgpi->mvalo[1]); tgpi->cp1[0] += dx; tgpi->cp1[1] += dy; - if (event->shift) + if (event->shift) { copy_v2_v2(tgpi->cp2, tgpi->cp1); + } } else if (tgpi->sel_cp == SELECT_CP2) { float dx = (tgpi->mval[0] - tgpi->mvalo[0]); float dy = (tgpi->mval[1] - tgpi->mvalo[1]); tgpi->cp2[0] += dx; tgpi->cp2[1] += dy; - if (event->shift) + if (event->shift) { copy_v2_v2(tgpi->cp1, tgpi->cp2); + } } /* update screen */ gpencil_primitive_update(C, op, tgpi); @@ -1344,12 +1357,15 @@ static void gpencil_primitive_edit_event_handling( case LEFTMOUSE: { if ((event->val == KM_PRESS)) { /* find nearest cp based on stroke end points */ - if (move == MOVE_ENDS) + if (move == MOVE_ENDS) { tgpi->sel_cp = (a < b) ? SELECT_START : SELECT_END; - else if (move == MOVE_CP) + } + else if (move == MOVE_CP) { tgpi->sel_cp = (c < d) ? SELECT_CP1 : SELECT_CP2; - else + } + else { tgpi->sel_cp = SELECT_NONE; + } break; } else if ((event->val == KM_RELEASE) && (tgpi->flag == IN_PROGRESS)) { diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index ef7a198111b..ba806022d3e 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -74,8 +74,9 @@ static bool gpencil_select_poll(bContext *C) /* we just need some visible strokes, and to be in editmode or other modes only to catch event */ if (GPENCIL_ANY_MODE(gpd)) { /* TODO: include a check for visible strokes? */ - if (gpd->layers.first) + if (gpd->layers.first) { return true; + } } return false; @@ -291,8 +292,9 @@ typedef enum eGP_SelectGrouped { /* Select strokes with the same color */ GP_SEL_SAME_MATERIAL = 1, - /* TODO: All with same prefix - Useful for isolating all layers for a particular character for instance */ - /* TODO: All with same appearance - colour/opacity/volumetric/fills ? */ + /* TODO: All with same prefix - + * Useful for isolating all layers for a particular character for instance. */ + /* TODO: All with same appearance - color/opacity/volumetric/fills ? */ } eGP_SelectGrouped; /* ----------------------------------- */ @@ -308,8 +310,9 @@ static void gp_select_same_layer(bContext *C) bGPDstroke *gps; bool found = false; - if (gpf == NULL) + if (gpf == NULL) { continue; + } /* Search for a selected stroke */ for (gps = gpf->strokes.first; gps; gps = gps->next) { @@ -621,7 +624,8 @@ static int gpencil_select_more_exec(bContext *C, wmOperator *UNUSED(op)) int i; bool prev_sel; - /* First Pass: Go in forward order, expanding selection if previous was selected (pre changes)... + /* First Pass: Go in forward order, + * expanding selection if previous was selected (pre changes). * - This pass covers the "after" edges of selection islands */ prev_sel = false; @@ -705,7 +709,8 @@ static int gpencil_select_less_exec(bContext *C, wmOperator *UNUSED(op)) int i; bool prev_sel; - /* First Pass: Go in forward order, shrinking selection if previous was not selected (pre changes)... + /* First Pass: Go in forward order, shrinking selection + * if previous was not selected (pre changes). * - This pass covers the "after" edges of selection islands */ prev_sel = false; @@ -776,9 +781,12 @@ void GPENCIL_OT_select_less(wmOperatorType *ot) /** \name Circle Select Operator * \{ */ -/* Helper to check if a given stroke is within the area */ -/* NOTE: Code here is adapted (i.e. copied directly) from gpencil_paint.c::gp_stroke_eraser_dostroke() - * It would be great to de-duplicate the logic here sometime, but that can wait... +/** + * Helper to check if a given stroke is within the area. + * + * \note Code here is adapted (i.e. copied directly) + * from gpencil_paint.c #gp_stroke_eraser_dostroke(). + * It would be great to de-duplicate the logic here sometime, but that can wait. */ static bool gp_stroke_do_circle_sel(bGPDlayer *gpl, bGPDstroke *gps, @@ -1290,6 +1298,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op) bool deselect = RNA_boolean_get(op->ptr, "deselect"); bool toggle = RNA_boolean_get(op->ptr, "toggle"); bool whole = RNA_boolean_get(op->ptr, "entire_strokes"); + const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all"); int mval[2] = {0}; @@ -1352,15 +1361,18 @@ static int gpencil_select_exec(bContext *C, wmOperator *op) /* Abort if nothing hit... */ if (ELEM(NULL, hit_stroke, hit_point)) { + if (deselect_all) { + /* since left mouse select change, deselect all if click outside any hit */ + deselect_all_selected(C); - /* since left mouse select change, deselect all if click outside any hit */ - deselect_all_selected(C); + /* copy on write tag is needed, or else no refresh happens */ + DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY); + DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE); + WM_event_add_notifier(C, NC_GPENCIL | NA_SELECTED, NULL); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL); - /* copy on write tag is needed, or else no refresh happens */ - DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY); - DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE); - WM_event_add_notifier(C, NC_GPENCIL | NA_SELECTED, NULL); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL); + return OPERATOR_FINISHED; + } return OPERATOR_CANCELLED; } @@ -1382,17 +1394,21 @@ static int gpencil_select_exec(bContext *C, wmOperator *op) /* entire stroke's points */ for (i = 0, pt = hit_stroke->points; i < hit_stroke->totpoints; i++, pt++) { - if (deselect == false) + if (deselect == false) { pt->flag |= GP_SPOINT_SELECT; - else + } + else { pt->flag &= ~GP_SPOINT_SELECT; + } } /* stroke too... */ - if (deselect == false) + if (deselect == false) { hit_stroke->flag |= GP_STROKE_SELECT; - else + } + else { hit_stroke->flag &= ~GP_STROKE_SELECT; + } } else { /* just the point (and the stroke) */ diff --git a/source/blender/editors/gpencil/gpencil_undo.c b/source/blender/editors/gpencil/gpencil_undo.c index d91977bc0da..7b57dacd3e4 100644 --- a/source/blender/editors/gpencil/gpencil_undo.c +++ b/source/blender/editors/gpencil/gpencil_undo.c @@ -68,7 +68,7 @@ int ED_undo_gpencil_step(bContext *C, int step, const char *name) gpd_ptr = ED_gpencil_data_get_pointers(C, NULL); if (step == 1) { /* undo */ - //printf("\t\tGP - undo step\n"); + // printf("\t\tGP - undo step\n"); if (cur_node->prev) { if (!name || STREQ(cur_node->name, name)) { cur_node = cur_node->prev; @@ -77,7 +77,7 @@ int ED_undo_gpencil_step(bContext *C, int step, const char *name) } } else if (step == -1) { - //printf("\t\tGP - redo step\n"); + // printf("\t\tGP - redo step\n"); if (cur_node->next) { if (!name || STREQ(cur_node->name, name)) { cur_node = cur_node->next; @@ -134,7 +134,7 @@ void gpencil_undo_push(bGPdata *gpd) { bGPundonode *undo_node; - //printf("\t\tGP - undo push\n"); + // printf("\t\tGP - undo push\n"); if (cur_node) { /* remove all un-done nodes from stack */ @@ -154,7 +154,8 @@ void gpencil_undo_push(bGPdata *gpd) * - to prevent running out of memory during **really** * long drawing sessions (triggering swapping) */ - /* TODO: Undo-memory constraint is not respected yet, but can be added if we have any need for it */ + /* TODO: Undo-memory constraint is not respected yet, + * but can be added if we have any need for it. */ if (U.undosteps && !BLI_listbase_is_empty(&undo_nodes)) { /* remove anything older than n-steps before cur_node */ int steps = 0; diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index 858415061b1..129bd01574c 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -85,7 +85,9 @@ /* ******************************************************** */ /* Context Wrangling... */ -/* Get pointer to active Grease Pencil datablock, and an RNA-pointer to trace back to whatever owns it, +/** + * Get pointer to active Grease Pencil datablock, + * and an RNA-pointer to trace back to whatever owns it, * when context info is not available. */ bGPdata **ED_gpencil_data_get_pointers_direct( @@ -104,8 +106,9 @@ bGPdata **ED_gpencil_data_get_pointers_direct( { if (ob && (ob->type == OB_GPENCIL)) { /* GP Object */ - if (r_ptr) + if (r_ptr) { RNA_id_pointer_create(&ob->id, r_ptr); + } return (bGPdata **)&ob->data; } else { @@ -120,15 +123,17 @@ bGPdata **ED_gpencil_data_get_pointers_direct( { if (ob && (ob->type == OB_GPENCIL)) { /* GP Object */ - if (r_ptr) + if (r_ptr) { RNA_id_pointer_create(&ob->id, r_ptr); + } return (bGPdata **)&ob->data; } else { /* Annotations */ /* XXX: */ - if (r_ptr) + if (r_ptr) { RNA_id_pointer_create(&scene->id, r_ptr); + } return &scene->gpd; } @@ -142,8 +147,9 @@ bGPdata **ED_gpencil_data_get_pointers_direct( if (snode && snode->nodetree) { /* for now, as long as there's an active node tree, * default to using that in the Nodes Editor */ - if (r_ptr) + if (r_ptr) { RNA_id_pointer_create(&snode->nodetree->id, r_ptr); + } return &snode->nodetree->gpd; } @@ -154,10 +160,12 @@ bGPdata **ED_gpencil_data_get_pointers_direct( { SpaceSeq *sseq = (SpaceSeq *)sl; - /* for now, Grease Pencil data is associated with the space (actually preview region only) */ + /* For now, Grease Pencil data is associated with the space + * (actually preview region only). */ /* XXX our convention for everything else is to link to data though... */ - if (r_ptr) + if (r_ptr) { RNA_pointer_create(screen_id, &RNA_SpaceSequenceEditor, sseq, r_ptr); + } return &sseq->gpd; } case SPACE_IMAGE: /* Image/UV Editor */ @@ -166,8 +174,9 @@ bGPdata **ED_gpencil_data_get_pointers_direct( /* for now, Grease Pencil data is associated with the space... */ /* XXX our convention for everything else is to link to data though... */ - if (r_ptr) + if (r_ptr) { RNA_pointer_create(screen_id, &RNA_SpaceImageEditor, sima, r_ptr); + } return &sima->gpd; } case SPACE_CLIP: /* Nodes Editor */ @@ -179,16 +188,19 @@ bGPdata **ED_gpencil_data_get_pointers_direct( if (sc->gpencil_src == SC_GPENCIL_SRC_TRACK) { MovieTrackingTrack *track = BKE_tracking_track_get_active(&clip->tracking); - if (!track) + if (!track) { return NULL; + } - if (r_ptr) + if (r_ptr) { RNA_pointer_create(&clip->id, &RNA_MovieTrackingTrack, track, r_ptr); + } return &track->gpd; } else { - if (r_ptr) + if (r_ptr) { RNA_id_pointer_create(&clip->id, r_ptr); + } return &clip->gpd; } } @@ -202,7 +214,8 @@ bGPdata **ED_gpencil_data_get_pointers_direct( return NULL; } -/* Get pointer to active Grease Pencil datablock, and an RNA-pointer to trace back to whatever owns it */ +/* Get pointer to active Grease Pencil datablock, + * and an RNA-pointer to trace back to whatever owns it. */ bGPdata **ED_gpencil_data_get_pointers(const bContext *C, PointerRNA *r_ptr) { ID *screen_id = (ID *)CTX_wm_screen(C); @@ -251,7 +264,11 @@ bGPdata *ED_gpencil_data_get_active_evaluated(const bContext *C) Object *ob = CTX_data_active_object(C); Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); - /* if (ob && ob->type == OB_GPENCIL) BLI_assert(ob_eval->data == DEG_get_evaluated_id(ob->data)); */ +#if 0 + if (ob && ob->type == OB_GPENCIL) { + BLI_assert(ob_eval->data == DEG_get_evaluated_id(ob->data)); + } +#endif return ED_gpencil_data_get_active_direct(screen_id, sa, scene_eval, ob_eval); } @@ -350,10 +367,12 @@ const EnumPropertyItem *ED_gpencil_layers_enum_itemf(bContext *C, item_tmp.name = gpl->info; item_tmp.value = i; - if (gpl->flag & GP_LAYER_ACTIVE) + if (gpl->flag & GP_LAYER_ACTIVE) { item_tmp.icon = ICON_GREASEPENCIL; - else + } + else { item_tmp.icon = ICON_NONE; + } RNA_enum_item_add(&item, &totitem, &item_tmp); } @@ -400,10 +419,12 @@ const EnumPropertyItem *ED_gpencil_layers_with_new_enum_itemf(bContext *C, item_tmp.name = gpl->info; item_tmp.value = tot - i - 1; - if (gpl->flag & GP_LAYER_ACTIVE) + if (gpl->flag & GP_LAYER_ACTIVE) { item_tmp.icon = ICON_GREASEPENCIL; - else + } + else { item_tmp.icon = ICON_NONE; + } RNA_enum_item_add(&item, &totitem, &item_tmp); } @@ -450,8 +471,9 @@ bool gp_stroke_inside_circle( bool ED_gpencil_stroke_can_use_direct(const ScrArea *sa, const bGPDstroke *gps) { /* sanity check */ - if (ELEM(NULL, sa, gps)) + if (ELEM(NULL, sa, gps)) { return false; + } /* filter stroke types by flags + spacetype */ if (gps->flag & GP_STROKE_3DSPACE) { @@ -486,10 +508,12 @@ bool ED_gpencil_stroke_color_use(Object *ob, const bGPDlayer *gpl, const bGPDstr MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1); if (gp_style != NULL) { - if (gp_style->flag & GP_STYLE_COLOR_HIDE) + if (gp_style->flag & GP_STYLE_COLOR_HIDE) { return false; - if (((gpl->flag & GP_LAYER_UNLOCK_COLOR) == 0) && (gp_style->flag & GP_STYLE_COLOR_LOCKED)) + } + if (((gpl->flag & GP_LAYER_UNLOCK_COLOR) == 0) && (gp_style->flag & GP_STYLE_COLOR_LOCKED)) { return false; + } } return true; @@ -606,7 +630,8 @@ void gp_apply_parent_point( * \param[out] r_x The screen-space x-coordinate of the point * \param[out] r_y The screen-space y-coordinate of the point * - * \warning This assumes that the caller has already checked whether the stroke in question can be drawn. + * \warning This assumes that the caller has already checked + * whether the stroke in question can be drawn. */ void gp_point_to_xy( const GP_SpaceConversion *gsc, const bGPDstroke *gps, const bGPDspoint *pt, int *r_x, int *r_y) @@ -650,15 +675,17 @@ void gp_point_to_xy( } /** - * Convert a Grease Pencil coordinate (i.e. can be 2D or 3D) to screenspace (2D) + * Convert a Grease Pencil coordinate (i.e. can be 2D or 3D) to screenspace (2D). * * Just like #gp_point_to_xy(), except the resulting coordinates are floats not ints. - * Use this version to solve "stair-step" artifacts which may arise when roundtripping the calculations. + * Use this version to solve "stair-step" artifacts which may arise when + * roundtripping the calculations. * - * \param r_x: [out] The screen-space x-coordinate of the point. - * \param r_y: [out] The screen-space y-coordinate of the point. + * \param r_x[out]: The screen-space x-coordinate of the point. + * \param r_y[out]: The screen-space y-coordinate of the point. * - * \warning This assumes that the caller has already checked whether the stroke in question can be drawn. + * \warning This assumes that the caller has already checked + * whether the stroke in question can be drawn. */ void gp_point_to_xy_fl(const GP_SpaceConversion *gsc, const bGPDstroke *gps, @@ -1079,7 +1106,9 @@ void ED_gp_project_point_to_plane(const Scene *scene, /* ******************************************************** */ /* Stroke Operations */ -// XXX: Check if these functions duplicate stuff in blenkernel, and/or whether we should just deduplicate + +/* XXX: Check if these functions duplicate stuff in blenkernel, + * and/or whether we should just deduplicate. */ /** * Subdivide a stroke once, by adding a point half way between each pair of existing points @@ -1259,6 +1288,7 @@ void ED_gpencil_parent_location(const Depsgraph *depsgraph, else { if ((gpl->partype == PAROBJECT) || (gpl->partype == PARSKEL)) { mul_m4_m4m4(diff_mat, obparent_eval->obmat, gpl->inverse); + add_v3_v3(diff_mat[3], ob_eval->obmat[3]); return; } else if (gpl->partype == PARBONE) { @@ -1267,10 +1297,12 @@ void ED_gpencil_parent_location(const Depsgraph *depsgraph, float tmp_mat[4][4]; mul_m4_m4m4(tmp_mat, obparent_eval->obmat, pchan->pose_mat); mul_m4_m4m4(diff_mat, tmp_mat, gpl->inverse); + add_v3_v3(diff_mat[3], ob_eval->obmat[3]); } else { /* if bone not found use object (armature) */ mul_m4_m4m4(diff_mat, obparent_eval->obmat, gpl->inverse); + add_v3_v3(diff_mat[3], ob_eval->obmat[3]); } return; } @@ -1287,12 +1319,15 @@ void ED_gpencil_reset_layers_parent(Depsgraph *depsgraph, Object *obact, bGPdata int i; float diff_mat[4][4]; float cur_mat[4][4]; + float gpl_loc[3]; + zero_v3(gpl_loc); for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { if (gpl->parent != NULL) { /* calculate new matrix */ if ((gpl->partype == PAROBJECT) || (gpl->partype == PARSKEL)) { invert_m4_m4(cur_mat, gpl->parent->obmat); + copy_v3_v3(gpl_loc, obact->obmat[3]); } else if (gpl->partype == PARBONE) { bPoseChannel *pchan = BKE_pose_channel_find_name(gpl->parent->pose, gpl->parsubstr); @@ -1300,6 +1335,7 @@ void ED_gpencil_reset_layers_parent(Depsgraph *depsgraph, Object *obact, bGPdata float tmp_mat[4][4]; mul_m4_m4m4(tmp_mat, gpl->parent->obmat, pchan->pose_mat); invert_m4_m4(cur_mat, tmp_mat); + copy_v3_v3(gpl_loc, obact->obmat[3]); } } @@ -1307,6 +1343,9 @@ void ED_gpencil_reset_layers_parent(Depsgraph *depsgraph, Object *obact, bGPdata if (!equals_m4m4(gpl->inverse, cur_mat)) { /* first apply current transformation to all strokes */ ED_gpencil_parent_location(depsgraph, obact, gpd, gpl, diff_mat); + /* undo local object */ + sub_v3_v3(diff_mat[3], gpl_loc); + for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { @@ -1377,8 +1416,9 @@ void ED_gpencil_vgroup_assign(bContext *C, Object *ob, float weight) bGPdata *gpd = (bGPdata *)ob->data; const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd); const int def_nr = ob->actdef - 1; - if (!BLI_findlink(&ob->defbase, def_nr)) + if (!BLI_findlink(&ob->defbase, def_nr)) { return; + } CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { bGPDframe *init_gpf = gpl->actframe; @@ -1389,14 +1429,16 @@ void ED_gpencil_vgroup_assign(bContext *C, Object *ob, float weight) for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) { if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { - if (gpf == NULL) + if (gpf == NULL) { continue; + } for (gps = gpf->strokes.first; gps; gps = gps->next) { /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } if (gps->flag & GP_STROKE_SELECT) { /* verify the weight array is created */ @@ -1431,8 +1473,9 @@ void ED_gpencil_vgroup_remove(bContext *C, Object *ob) bGPdata *gpd = (bGPdata *)ob->data; const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd); const int def_nr = ob->actdef - 1; - if (!BLI_findlink(&ob->defbase, def_nr)) + if (!BLI_findlink(&ob->defbase, def_nr)) { return; + } CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { bGPDframe *init_gpf = gpl->actframe; @@ -1443,14 +1486,16 @@ void ED_gpencil_vgroup_remove(bContext *C, Object *ob) for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) { if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { - if (gpf == NULL) + if (gpf == NULL) { continue; + } for (gps = gpf->strokes.first; gps; gps = gps->next) { /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } for (int i = 0; i < gps->totpoints; i++) { bGPDspoint *pt = &gps->points[i]; @@ -1484,8 +1529,9 @@ void ED_gpencil_vgroup_select(bContext *C, Object *ob) bGPdata *gpd = (bGPdata *)ob->data; const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd); const int def_nr = ob->actdef - 1; - if (!BLI_findlink(&ob->defbase, def_nr)) + if (!BLI_findlink(&ob->defbase, def_nr)) { return; + } CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { bGPDframe *init_gpf = gpl->actframe; @@ -1496,14 +1542,16 @@ void ED_gpencil_vgroup_select(bContext *C, Object *ob) for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) { if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { - if (gpf == NULL) + if (gpf == NULL) { continue; + } for (gps = gpf->strokes.first; gps; gps = gps->next) { /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } for (int i = 0; i < gps->totpoints; i++) { bGPDspoint *pt = &gps->points[i]; @@ -1535,8 +1583,9 @@ void ED_gpencil_vgroup_deselect(bContext *C, Object *ob) bGPdata *gpd = (bGPdata *)ob->data; const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd); const int def_nr = ob->actdef - 1; - if (!BLI_findlink(&ob->defbase, def_nr)) + if (!BLI_findlink(&ob->defbase, def_nr)) { return; + } CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { bGPDframe *init_gpf = gpl->actframe; @@ -1547,14 +1596,16 @@ void ED_gpencil_vgroup_deselect(bContext *C, Object *ob) for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) { if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) { - if (gpf == NULL) + if (gpf == NULL) { continue; + } for (gps = gpf->strokes.first; gps; gps = gps->next) { /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } for (int i = 0; i < gps->totpoints; i++) { bGPDspoint *pt = &gps->points[i]; @@ -1638,14 +1689,13 @@ void ED_gpencil_brush_draw_eraser(Brush *brush, int x, int y) immUniform1f("dash_width", 12.0f); immUniform1f("dash_factor", 0.5f); - imm_draw_circle_wire_2d( - shdr_pos, - x, - y, - radius, - /* XXX Dashed shader gives bad results with sets of small segments currently, - * temp hack around the issue. :( */ - max_ii(8, radius / 2)); /* was fixed 40 */ + imm_draw_circle_wire_2d(shdr_pos, + x, + y, + radius, + /* XXX Dashed shader gives bad results with sets of small segments + * currently, temp hack around the issue. :( */ + max_ii(8, radius / 2)); /* was fixed 40 */ immUnbindProgram(); @@ -2463,7 +2513,7 @@ void ED_gpencil_select_toggle_all(bContext *C, int action) case SEL_SELECT: pt->flag |= GP_SPOINT_SELECT; break; - //case SEL_DESELECT: + // case SEL_DESELECT: // pt->flag &= ~GP_SPOINT_SELECT; // break; case SEL_INVERT: @@ -2471,15 +2521,18 @@ void ED_gpencil_select_toggle_all(bContext *C, int action) break; } - if (pt->flag & GP_SPOINT_SELECT) + if (pt->flag & GP_SPOINT_SELECT) { selected = true; + } } /* Change status of stroke */ - if (selected) + if (selected) { gps->flag |= GP_STROKE_SELECT; - else + } + else { gps->flag &= ~GP_STROKE_SELECT; + } } CTX_DATA_END; } diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h index a2e8d6afd4b..7d4b6dbeea2 100644 --- a/source/blender/editors/include/BIF_glutil.h +++ b/source/blender/editors/include/BIF_glutil.h @@ -32,35 +32,6 @@ struct ColorManagedViewSettings; struct ImBuf; struct bContext; -/* A few functions defined here are being DEPRECATED for Blender 2.8 - * - * Do not use them in new code, and you are encouraged to - * convert existing code to draw without these. - * - * These will be deleted before we ship 2.8! - * - merwin - */ - -/** - * Returns a float value as obtained by glGetFloatv. - * The param must cause only one value to be gotten from GL. - */ -float glaGetOneFloat(int param); -int glaGetOneInt(int param); - -/** - * Functions like glRasterPos2i, except ensures that the resulting - * raster position is valid. \a known_good_x and \a known_good_y - * should be coordinates of a point known to be within the current - * view frustum. - * \attention This routine should be used when the distance of \a x - * and \a y away from the known good point is small (ie. for small icons - * and for bitmap characters), when drawing large+zoomed images it is - * possible for overflow to occur, the glaDrawPixelsSafe routine should - * be used instead. - */ -void glaRasterPosSafe2f(float x, float y, float known_good_x, float known_good_y); - typedef struct IMMDrawPixelsTexState { struct GPUShader *shader; unsigned int pos; @@ -148,29 +119,47 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, float yzoom, float color[4]); -void set_inverted_drawing(int enable); - -/* own working polygon offset */ -float bglPolygonOffsetCalc(const float winmat[16], float viewdist, float dist); -void bglPolygonOffset(float viewdist, float dist); - -/* **** Color management helper functions for GLSL display/transform ***** */ - -/* Draw imbuf on a screen, preferably using GLSL display transform */ -void glaDrawImBuf_glsl(struct ImBuf *ibuf, +/* Image buffer drawing functions, with display transform + * + * The view and display settings can either be specified manually, + * or retrieved from the context with the '_ctx' variations. + * + * For better performance clipping coordinates can be specified so parts of the + * image outside the view are skipped. */ + +void ED_draw_imbuf(struct ImBuf *ibuf, + float x, + float y, + int zoomfilter, + struct ColorManagedViewSettings *view_settings, + struct ColorManagedDisplaySettings *display_settings, + float zoom_x, + float zoom_y); +void ED_draw_imbuf_clipping(struct ImBuf *ibuf, + float x, + float y, + int zoomfilter, + struct ColorManagedViewSettings *view_settings, + struct ColorManagedDisplaySettings *display_settings, + float clip_min_x, + float clip_min_y, + float clip_max_x, + float clip_max_y, + float zoom_x, + float zoom_y); + +void ED_draw_imbuf_ctx(const struct bContext *C, + struct ImBuf *ibuf, float x, float y, int zoomfilter, - struct ColorManagedViewSettings *view_settings, - struct ColorManagedDisplaySettings *display_settings, float zoom_x, float zoom_y); -void glaDrawImBuf_glsl_clipping(struct ImBuf *ibuf, +void ED_draw_imbuf_ctx_clipping(const struct bContext *C, + struct ImBuf *ibuf, float x, float y, int zoomfilter, - struct ColorManagedViewSettings *view_settings, - struct ColorManagedDisplaySettings *display_settings, float clip_min_x, float clip_min_y, float clip_max_x, @@ -178,25 +167,16 @@ void glaDrawImBuf_glsl_clipping(struct ImBuf *ibuf, float zoom_x, float zoom_y); -/* Draw imbuf on a screen, preferably using GLSL display transform */ -void glaDrawImBuf_glsl_ctx(const struct bContext *C, - struct ImBuf *ibuf, - float x, - float y, - int zoomfilter, - float zoom_x, - float zoom_y); -void glaDrawImBuf_glsl_ctx_clipping(const struct bContext *C, - struct ImBuf *ibuf, - float x, - float y, - int zoomfilter, - float clip_min_x, - float clip_min_y, - float clip_max_x, - float clip_max_y, - float zoom_x, - float zoom_y); +int ED_draw_imbuf_method(struct ImBuf *ibuf); + +/* OpenGL drawing utility functions. Do not use these in new code, these + * are intended to be moved or removed in the future. */ + +void set_inverted_drawing(int enable); + +/* own working polygon offset */ +float bglPolygonOffsetCalc(const float winmat[16], float viewdist, float dist); +void bglPolygonOffset(float viewdist, float dist); void immDrawBorderCorners(unsigned int pos, const struct rcti *border, float zoomx, float zoomy); diff --git a/source/blender/editors/include/ED_anim_api.h b/source/blender/editors/include/ED_anim_api.h index 3a9539ee52c..d947322f708 100644 --- a/source/blender/editors/include/ED_anim_api.h +++ b/source/blender/editors/include/ED_anim_api.h @@ -276,7 +276,8 @@ typedef enum eAnim_Update_Flags { typedef enum eAnimFilter_Flags { /** data which channel represents is fits the dopesheet filters * (i.e. scene visibility criteria) */ - // XXX: it's hard to think of any examples where this *ISN'T* the case... perhaps becomes implicit? + /* XXX: it's hard to think of any examples where this *ISN'T* the case... + * perhaps becomes implicit?. */ ANIMFILTER_DATA_VISIBLE = (1 << 0), /** channel is visible within the channel-list hierarchy * (i.e. F-Curves within Groups in ActEdit) */ @@ -611,6 +612,9 @@ void ANIM_set_active_channel(bAnimContext *ac, * as appropriate according to animation context */ void ANIM_fcurve_delete_from_animdata(bAnimContext *ac, struct AnimData *adt, struct FCurve *fcu); +/* Unlink the action from animdata if it's empty. */ +bool ANIM_remove_empty_action_from_animdata(struct AnimData *adt); + /* ************************************************ */ /* DRAWING API */ /* anim_draw.c */ diff --git a/source/blender/editors/include/ED_armature.h b/source/blender/editors/include/ED_armature.h index 9fb8f1b1b04..3eb277ad776 100644 --- a/source/blender/editors/include/ED_armature.h +++ b/source/blender/editors/include/ED_armature.h @@ -82,10 +82,11 @@ typedef struct EditBone { /* Bendy-Bone parameters */ float roll1, roll2; - float curveOutX, curveOutY; - float curveInX, curveInY; + float curve_in_x, curve_in_y; + float curve_out_x, curve_out_y; float ease1, ease2; - float scaleIn, scaleOut; + float scale_in_x, scale_in_y; + float scale_out_x, scale_out_y; /** for envelope scaling */ float oldlength; diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h index ac998cbcb71..6af8197aa8f 100644 --- a/source/blender/editors/include/ED_gpencil.h +++ b/source/blender/editors/include/ED_gpencil.h @@ -268,7 +268,7 @@ void ED_gpencil_update_color_uv(struct Main *bmain, struct Material *mat); * 1 - Hit in point A * 2 - Hit in point B * 3 - Hit in point A and B -*/ + */ int ED_gpencil_select_stroke_segment(struct bGPDlayer *gpl, struct bGPDstroke *gps, struct bGPDspoint *pt, diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h index ba5a6a8a339..5bd806b3dbf 100644 --- a/source/blender/editors/include/ED_image.h +++ b/source/blender/editors/include/ED_image.h @@ -71,9 +71,6 @@ void ED_space_image_scopes_update(const struct bContext *C, void ED_space_image_paint_update(struct Main *bmain, struct wmWindowManager *wm, struct Scene *scene); -void ED_space_image_uv_sculpt_update(struct Main *bmain, - struct wmWindowManager *wm, - struct Scene *scene); void ED_image_get_uv_aspect(struct Image *ima, struct ImageUser *iuser, float *aspx, float *aspy); void ED_image_mouse_pos(struct SpaceImage *sima, diff --git a/source/blender/editors/include/ED_keyframing.h b/source/blender/editors/include/ED_keyframing.h index 54570938de1..a893f03bd88 100644 --- a/source/blender/editors/include/ED_keyframing.h +++ b/source/blender/editors/include/ED_keyframing.h @@ -143,8 +143,8 @@ short insert_keyframe(struct Main *bmain, eInsertKeyFlags flag); /* Main Keyframing API call: - * Use this to delete keyframe on current frame for relevant channel. Will perform checks just in case. - */ + * Use this to delete keyframe on current frame for relevant channel. + * Will perform checks just in case. */ short delete_keyframe(struct Main *bmain, struct ReportList *reports, struct ID *id, diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index dcac5301da5..ce8521a1f6a 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -358,7 +358,10 @@ float ED_vgroup_vert_weight(struct Object *ob, struct bDeformGroup *dg, int vert void ED_vgroup_vert_active_mirror(struct Object *ob, int def_nr); /* mesh_data.c */ -// void ED_mesh_geometry_add(struct Mesh *mesh, struct ReportList *reports, int verts, int edges, int faces); +#if 0 +void ED_mesh_geometry_add( + struct Mesh *mesh, struct ReportList *reports, int verts, int edges, int faces); +#endif void ED_mesh_polys_add(struct Mesh *mesh, struct ReportList *reports, int count); void ED_mesh_tessfaces_add(struct Mesh *mesh, struct ReportList *reports, int count); void ED_mesh_edges_add(struct Mesh *mesh, struct ReportList *reports, int count); diff --git a/source/blender/editors/include/ED_numinput.h b/source/blender/editors/include/ED_numinput.h index 697a236341f..b13f228b1ec 100644 --- a/source/blender/editors/include/ED_numinput.h +++ b/source/blender/editors/include/ED_numinput.h @@ -78,12 +78,16 @@ struct UnitSettings; /** * There are important things to note here for code using numinput: - * - Values passed to #applyNumInput() should be valid and are stored as default ones (val_org), if it is not EDITED. - * - bool returned by #applyNumInput should be used to decide whether to apply numinput-specific post-process to data. - * - Once #applyNumInput has been called, #hasNumInput returns a valid value to decide whether to use numinput - * as drawstr source or not (i.e. to call #outputNumInput). + * - Values passed to #applyNumInput() should be valid and are stored as default ones (val_org), + * if it is not EDITED. + * - bool returned by #applyNumInput should be used to decide whether to apply + * numinput-specific post-process to data. + * - Once #applyNumInput has been called, + * #hasNumInput returns a valid value to decide whether to use numinput as drawstr source or not + * (i.e. to call #outputNumInput). * - * Those two steps have to be separated (so do not use a common call to #hasNumInput() to do both in the same time!). + * Those two steps have to be separated + * (so do not use a common call to #hasNumInput() to do both in the same time!). */ void initNumInput(NumInput *n); diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index bcf9cb3fcc0..543b2a5781f 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -100,7 +100,14 @@ void ED_region_header_draw(const struct bContext *C, struct ARegion *ar); void ED_region_cursor_set(struct wmWindow *win, struct ScrArea *sa, struct ARegion *ar); void ED_region_toggle_hidden(struct bContext *C, struct ARegion *ar); -void ED_region_visibility_change_update(struct bContext *C, struct ARegion *ar); +void ED_region_visibility_change_update(struct bContext *C, + struct ScrArea *sa, + struct ARegion *ar); +/* screen_ops.c */ +void ED_region_visibility_change_update_animated(struct bContext *C, + struct ScrArea *sa, + struct ARegion *ar); + void ED_region_info_draw(struct ARegion *ar, const char *text, float fill_color[4], @@ -128,6 +135,14 @@ void ED_area_do_msg_notify_tag_refresh(struct bContext *C, struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val); +void ED_area_do_mgs_subscribe_for_tool_header(const struct bContext *C, + struct WorkSpace *workspace, + struct Scene *scene, + struct bScreen *screen, + struct ScrArea *sa, + struct ARegion *ar, + struct wmMsgBus *mbus); + /* message bus */ void ED_region_message_subscribe(struct bContext *C, struct WorkSpace *workspace, @@ -388,6 +403,21 @@ void ED_region_generic_tools_region_message_subscribe(const struct bContext *C, struct wmMsgBus *mbus); int ED_region_generic_tools_region_snap_size(const struct ARegion *ar, int size, int axis); +/* area_query.c */ +bool ED_region_overlap_isect_x(const ARegion *ar, const int event_x); +bool ED_region_overlap_isect_y(const ARegion *ar, const int event_y); +bool ED_region_overlap_isect_xy(const ARegion *ar, const int event_xy[2]); +bool ED_region_overlap_isect_x_with_margin(const ARegion *ar, const int event_x, const int margin); +bool ED_region_overlap_isect_y_with_margin(const ARegion *ar, const int event_y, const int margin); +bool ED_region_overlap_isect_xy_with_margin(const ARegion *ar, + const int event_xy[2], + const int margin); + +bool ED_region_panel_category_gutter_calc_rect(const ARegion *ar, rcti *r_ar_gutter); +bool ED_region_panel_category_gutter_isect_xy(const ARegion *ar, const int event_xy[2]); + +bool ED_region_contains_xy(const struct ARegion *ar, const int event_xy[2]); + /* interface_region_hud.c */ struct ARegionType *ED_area_type_hud(int space_type); void ED_area_type_hud_clear(struct wmWindowManager *wm, ScrArea *sa_keep); diff --git a/source/blender/editors/include/ED_screen_types.h b/source/blender/editors/include/ED_screen_types.h index 3cbeab247ef..c515d501a8d 100644 --- a/source/blender/editors/include/ED_screen_types.h +++ b/source/blender/editors/include/ED_screen_types.h @@ -108,15 +108,29 @@ typedef struct AZone { float alpha; } AZone; -/* actionzone type */ +/** Action-Zone Type: #AZone.type */ enum { - /* corner widgets for splitting areas */ + /** + * Corner widgets for: + * - Splitting areas. + * - Swapping areas (Ctrl). + * - Copying the area into a new window (Shift). + */ AZONE_AREA = 1, - /* when a region is collapsed, draw a handle to expose */ + /** + * Use for region show/hide state: + * - When a region is collapsed, draw a handle to expose. + * - When a region is expanded, use the action zone to resize the region. + */ AZONE_REGION, - /* when in editor fullscreen draw a corner to go to normal mode */ + /** + * Used when in editor fullscreen draw a corner to return to normal mode. + */ AZONE_FULLSCREEN, - /* Hotspot azone around scrollbars to show/hide them. */ + /** + * Hotspot azone around scroll-bars to show/hide them. + * Only show the scroll-bars when the cursor is close. + */ AZONE_REGION_SCROLL, }; diff --git a/source/blender/editors/include/ED_space_api.h b/source/blender/editors/include/ED_space_api.h index 01de5fd8441..766f2b31192 100644 --- a/source/blender/editors/include/ED_space_api.h +++ b/source/blender/editors/include/ED_space_api.h @@ -62,6 +62,7 @@ void ED_file_exit(void); #define REGION_DRAW_POST_VIEW 0 #define REGION_DRAW_POST_PIXEL 1 #define REGION_DRAW_PRE_VIEW 2 +#define REGION_DRAW_BACKDROP 3 void *ED_region_draw_cb_activate(struct ARegionType *, void (*draw)(const struct bContext *, struct ARegion *, void *), diff --git a/source/blender/editors/include/ED_uvedit.h b/source/blender/editors/include/ED_uvedit.h index 9259afd1d5f..8dd2dab5209 100644 --- a/source/blender/editors/include/ED_uvedit.h +++ b/source/blender/editors/include/ED_uvedit.h @@ -178,7 +178,6 @@ void ED_uvedit_add_simple_uvs(struct Main *bmain, struct Scene *scene, struct Ob /* uvedit_draw.c */ void ED_image_draw_cursor(struct ARegion *ar, const float cursor[2]); void ED_uvedit_draw_main(struct SpaceImage *sima, - struct ARegion *ar, struct Scene *scene, struct ViewLayer *view_layer, struct Object *obedit, diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index e747dda95d4..fd51419a3ee 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -54,6 +54,7 @@ struct RenderEngineType; struct Scene; struct ScrArea; struct View3D; +struct View3DShading; struct ViewContext; struct ViewLayer; struct WorkSpace; @@ -524,8 +525,6 @@ void ED_view3d_viewcontext_init(struct bContext *C, struct ViewContext *vc); void ED_view3d_viewcontext_init_object(struct ViewContext *vc, struct Object *obact); void view3d_operator_needs_opengl(const struct bContext *C); void view3d_region_operator_needs_opengl(struct wmWindow *win, struct ARegion *ar); -void view3d_opengl_read_pixels( - struct ARegion *ar, int x, int y, int w, int h, int format, int type, void *data); /* XXX should move to BLI_math */ bool edge_inside_circle(const float cent[2], @@ -586,16 +585,6 @@ void ED_view3d_draw_setup_view(struct wmWindow *win, float winmat[4][4], const struct rcti *rect); -enum { - V3D_OFSDRAW_NONE = (0), - - V3D_OFSDRAW_USE_FULL_SAMPLE = (1 << 0), - - /* Only works with ED_view3d_draw_offscreen_imbuf_simple(). */ - V3D_OFSDRAW_USE_GPENCIL = (1 << 1), - V3D_OFSDRAW_USE_CAMERA_DOF = (1 << 2), -}; - struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Depsgraph *depsgraph, struct Scene *scene, int drawtype, @@ -612,6 +601,7 @@ struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Depsgraph *depsgraph, char err_out[256]); struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(struct Depsgraph *depsgraph, struct Scene *scene, + struct View3DShading *shading_override, int drawtype, struct Object *camera, int width, @@ -707,7 +697,10 @@ void ED_scene_draw_fps(struct Scene *scene, int xoffset, int *yoffset); #if 0 void ED_view3d_operator_properties_viewmat(struct wmOperatorType *ot); void ED_view3d_operator_properties_viewmat_set(struct bContext *C, struct wmOperator *op); -void ED_view3d_operator_properties_viewmat_get(struct wmOperator *op, int *winx, int *winy, float persmat[4][4]); +void ED_view3d_operator_properties_viewmat_get(struct wmOperator *op, + int *winx, + int *winy, + float persmat[4][4]); #endif /* render */ diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index d3cce4a5dde..18960853011 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -86,6 +86,14 @@ typedef struct uiPopupBlockHandle uiPopupBlockHandle; #define UI_MAX_NAME_STR 128 #define UI_MAX_SHORTCUT_STR 64 +/** + * For #ARegion.overlap regions, pass events though if they don't overlap + * the regions contents (the usable part of the #View2D and buttons). + * + * The margin is needed so it's not possible to accidentally click inbetween buttons. + */ +#define UI_REGION_OVERLAP_MARGIN (U.widget_unit / 3) + /* use for clamping popups within the screen */ #define UI_SCREEN_MARGIN 10 @@ -416,8 +424,16 @@ void UI_draw_roundbox_shade_x(bool filled, const float col[4]); #if 0 /* unused */ -int UI_draw_roundbox_corner_get(void); -void UI_draw_roundbox_shade_y(bool filled, float minx, float miny, float maxx, float maxy, float rad, float shadeleft, float shaderight, const float col[4]); +int UI_draw_roundbox_corner_get(void); +void UI_draw_roundbox_shade_y(bool filled, + float minx, + float miny, + float maxx, + float maxy, + float rad, + float shadeleft, + float shaderight, + const float col[4]); #endif void UI_draw_box_shadow(unsigned char alpha, float minx, float miny, float maxx, float maxy); @@ -504,6 +520,7 @@ bool UI_but_is_tool(const uiBut *but); #define UI_but_is_decorator(but) ((but)->func == ui_but_anim_decorate_cb) bool UI_block_is_empty(const uiBlock *block); +bool UI_block_can_add_separator(const uiBlock *block); /* interface_region_menu_popup.c */ /** @@ -587,7 +604,10 @@ void UI_popup_block_ex(struct bContext *C, void *arg, struct wmOperator *op); #if 0 /* UNUSED */ -void uiPupBlockOperator(struct bContext *C, uiBlockCreateFunc func, struct wmOperator *op, int opcontext); +void uiPupBlockOperator(struct bContext *C, + uiBlockCreateFunc func, + struct wmOperator *op, + int opcontext); #endif void UI_popup_block_close(struct bContext *C, struct wmWindow *win, uiBlock *block); @@ -1603,7 +1623,7 @@ void UI_panels_scale(struct ARegion *ar, float new_width); void UI_panel_label_offset(struct uiBlock *block, int *r_x, int *r_y); int UI_panel_size_y(const struct Panel *pa); -bool UI_panel_category_is_visible(struct ARegion *ar); +bool UI_panel_category_is_visible(const struct ARegion *ar); void UI_panel_category_add(struct ARegion *ar, const char *name); struct PanelCategoryDyn *UI_panel_category_find(struct ARegion *ar, const char *idname); struct PanelCategoryStack *UI_panel_category_active_find(struct ARegion *ar, const char *idname); @@ -2291,6 +2311,7 @@ void UI_context_active_but_prop_get_templateID(struct bContext *C, struct ID *UI_context_active_but_get_tab_ID(struct bContext *C); uiBut *UI_region_active_but_get(struct ARegion *ar); +uiBut *UI_region_but_find_rect_over(const struct ARegion *ar, const struct rcti *isect); /* uiFontStyle.align */ typedef enum eFontStyle_Align { diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h index 1fc1fba4b4a..af94889a1bb 100644 --- a/source/blender/editors/include/UI_resources.h +++ b/source/blender/editors/include/UI_resources.h @@ -92,6 +92,7 @@ typedef enum ThemeColorID { TH_VERTEX_UNREFERENCED, TH_VERTEX_SIZE, TH_OUTLINE_WIDTH, + TH_OBCENTER_DIA, TH_EDGE, TH_EDGE_SELECT, TH_EDGE_SEAM, @@ -341,7 +342,8 @@ void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3]); void UI_GetThemeColorShade3ubv(int colorid, int offset, unsigned char col[3]); void UI_GetThemeColorShade4ubv(int colorid, int offset, unsigned char col[4]); -// get three color values, range 0-255, complete with shading offset for the RGB components and blending +// get three color values, range 0-255, +// complete with shading offset for the RGB components and blending. void UI_GetThemeColorBlendShade3ubv( int colorid1, int colorid2, float fac, int offset, unsigned char col[3]); @@ -355,13 +357,14 @@ void UI_GetThemeColorType4fv(int colorid, int spacetype, float col[4]); void UI_GetThemeColorShade4fv(int colorid, int offset, float col[4]); void UI_GetThemeColorShadeAlpha4fv(int colorid, int coloffset, int alphaoffset, float col[4]); -// get four colour values ranged between 0 and 255; includes the alpha channel +// get four color values ranged between 0 and 255; includes the alpha channel void UI_GetThemeColorShadeAlpha4ubv(int colorid, int coloffset, int alphaoffset, unsigned char col[4]); -// get four color values, range 0.0-1.0, complete with shading offset for the RGB components and blending +// get four color values, range 0.0-1.0, +// complete with shading offset for the RGB components and blending. void UI_GetThemeColorBlendShade3fv( int colorid1, int colorid2, float fac, int offset, float col[3]); void UI_GetThemeColorBlendShade4fv( diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h index fde865d4bba..07dbb49ac07 100644 --- a/source/blender/editors/include/UI_view2d.h +++ b/source/blender/editors/include/UI_view2d.h @@ -56,40 +56,7 @@ enum eView2D_CommonViewTypes { V2D_COMMONVIEW_PANELS_UI, }; -/* ---- Defines for Scroller/Grid Arguments ----- */ - -/* 'dummy' argument to pass when argument is irrelevant */ -#define V2D_ARG_DUMMY -1 - -/* Grid units */ -enum eView2D_Units { - /* for drawing time */ - V2D_UNIT_SECONDS = 0, - V2D_UNIT_FRAMES, - V2D_UNIT_FRAMESCALE, - - /* for drawing values */ - V2D_UNIT_VALUES, -}; - -/* clamping of grid values to whole numbers */ -enum eView2D_Clamp { - V2D_GRID_NOCLAMP = 0, - V2D_GRID_CLAMP, -}; - -/* flags for grid-lines to draw */ -enum eView2D_Gridlines { - V2D_HORIZONTAL_LINES = (1 << 0), - V2D_VERTICAL_LINES = (1 << 1), - V2D_HORIZONTAL_AXIS = (1 << 2), - V2D_VERTICAL_AXIS = (1 << 3), - V2D_HORIZONTAL_FINELINES = (1 << 4), - - V2D_GRIDLINES_MAJOR = (V2D_VERTICAL_LINES | V2D_VERTICAL_AXIS | V2D_HORIZONTAL_LINES | - V2D_HORIZONTAL_AXIS), - V2D_GRIDLINES_ALL = (V2D_GRIDLINES_MAJOR | V2D_HORIZONTAL_FINELINES), -}; +/* ---- Defines for Scroller Arguments ----- */ /* ------ Defines for Scrollers ----- */ @@ -117,11 +84,13 @@ enum eView2D_Gridlines { #define IN_2D_VERT_SCROLL(v2d, co) (BLI_rcti_isect_pt_v(&v2d->vert, co)) #define IN_2D_HORIZ_SCROLL(v2d, co) (BLI_rcti_isect_pt_v(&v2d->hor, co)) +#define IN_2D_VERT_SCROLL_RECT(v2d, rct) (BLI_rcti_isect(&v2d->vert, rct, NULL)) +#define IN_2D_HORIZ_SCROLL_RECT(v2d, rct) (BLI_rcti_isect(&v2d->hor, rct, NULL)) + /* ------------------------------------------ */ /* Type definitions: */ struct View2D; -struct View2DGrid; struct View2DScrollers; struct ARegion; @@ -132,7 +101,6 @@ struct bScreen; struct rctf; struct wmKeyConfig; -typedef struct View2DGrid View2DGrid; typedef struct View2DScrollers View2DScrollers; /* ----------------------------------------- */ @@ -156,49 +124,62 @@ bool UI_view2d_tab_set(struct View2D *v2d, int tab); void UI_view2d_zoom_cache_reset(void); /* view matrix operations */ -void UI_view2d_view_ortho(struct View2D *v2d); +void UI_view2d_view_ortho(const struct View2D *v2d); void UI_view2d_view_orthoSpecial(struct ARegion *ar, struct View2D *v2d, const bool xaxis); void UI_view2d_view_restore(const struct bContext *C); /* grid drawing */ -View2DGrid *UI_view2d_grid_calc(struct Scene *scene, - struct View2D *v2d, - short xunits, - short xclamp, - short yunits, - short yclamp, - int winx, - int winy); -void UI_view2d_grid_draw(struct View2D *v2d, View2DGrid *grid, int flag); void UI_view2d_constant_grid_draw(struct View2D *v2d, float step); void UI_view2d_multi_grid_draw( struct View2D *v2d, int colorid, float step, int level_size, int totlevels); -void UI_view2d_grid_size(View2DGrid *grid, float *r_dx, float *r_dy); -void UI_view2d_grid_draw_numbers_horizontal(const struct Scene *scene, - const struct View2D *v2d, - const View2DGrid *grid, - const struct rcti *rect, - int unit, - bool whole_numbers_only); -void UI_view2d_grid_draw_numbers_vertical(const struct Scene *scene, - const struct View2D *v2d, - const View2DGrid *grid, - const struct rcti *rect, - int unit, - float text_offset); -void UI_view2d_grid_free(View2DGrid *grid); + +void UI_view2d_draw_lines_y__values(const struct View2D *v2d); +void UI_view2d_draw_lines_x__values(const struct View2D *v2d); +void UI_view2d_draw_lines_x__discrete_values(const struct View2D *v2d); +void UI_view2d_draw_lines_x__discrete_time(const struct View2D *v2d, const struct Scene *scene); +void UI_view2d_draw_lines_x__discrete_frames_or_seconds(const struct View2D *v2d, + const struct Scene *scene, + bool display_seconds); +void UI_view2d_draw_lines_x__frames_or_seconds(const struct View2D *v2d, + const struct Scene *scene, + bool display_seconds); + +float UI_view2d_grid_resolution_x__frames_or_seconds(const struct View2D *v2d, + const struct Scene *scene, + bool display_seconds); +float UI_view2d_grid_resolution_y__values(const struct View2D *v2d); + +/* scale indicator text drawing */ +void UI_view2d_draw_scale_y__values(const struct ARegion *ar, + const struct View2D *v2d, + const struct rcti *rect); +void UI_view2d_draw_scale_y__block(const struct ARegion *ar, + const struct View2D *v2d, + const struct rcti *rect); +void UI_view2d_draw_scale_x__values(const struct ARegion *ar, + const struct View2D *v2d, + const struct rcti *rect); +void UI_view2d_draw_scale_x__discrete_values(const struct ARegion *ar, + const struct View2D *v2d, + const struct rcti *rect); +void UI_view2d_draw_scale_x__discrete_time(const struct ARegion *ar, + const struct View2D *v2d, + const struct rcti *rect, + const struct Scene *scene); +void UI_view2d_draw_scale_x__discrete_frames_or_seconds(const struct ARegion *ar, + const struct View2D *v2d, + const struct rcti *rect, + const struct Scene *scene, + bool display_seconds); +void UI_view2d_draw_scale_x__frames_or_seconds(const struct ARegion *ar, + const struct View2D *v2d, + const struct rcti *rect, + const struct Scene *scene, + bool display_seconds); /* scrollbar drawing */ -View2DScrollers *UI_view2d_scrollers_calc(const struct bContext *C, - struct View2D *v2d, - const struct rcti *mask_custom, - short xunits, - short xclamp, - short yunits, - short yclamp); -void UI_view2d_scrollers_draw(const struct bContext *C, - struct View2D *v2d, - View2DScrollers *scrollers); +View2DScrollers *UI_view2d_scrollers_calc(struct View2D *v2d, const struct rcti *mask_custom); +void UI_view2d_scrollers_draw(struct View2D *v2d, View2DScrollers *scrollers); void UI_view2d_scrollers_free(View2DScrollers *scrollers); /* list view tools */ @@ -275,6 +256,13 @@ char UI_view2d_mouse_in_scrollers(const struct ARegion *ar, const struct View2D *v2d, int x, int y); +char UI_view2d_rect_in_scrollers_ex(const struct ARegion *ar, + const struct View2D *v2d, + const struct rcti *rect, + int *r_scroll); +char UI_view2d_rect_in_scrollers(const struct ARegion *ar, + const struct View2D *v2d, + const struct rcti *rect); /* cached text drawing in v2d, to allow pixel-aligned draw as post process */ void UI_view2d_text_cache_add( diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt index 622f89b1f87..6ab1761e7f8 100644 --- a/source/blender/editors/interface/CMakeLists.txt +++ b/source/blender/editors/interface/CMakeLists.txt @@ -30,8 +30,8 @@ set(INC ../../makesrna ../../python ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS @@ -72,6 +72,7 @@ set(SRC interface_widgets.c resources.c view2d.c + view2d_draw.c view2d_ops.c interface_eyedropper_intern.h diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 06b0634f6fb..42f4b4495c3 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -213,6 +213,16 @@ void ui_window_to_block_fl(const ARegion *ar, uiBlock *block, float *x, float *y } } +void ui_window_to_block_rctf(const struct ARegion *ar, + uiBlock *block, + rctf *rct_dst, + const rctf *rct_src) +{ + *rct_dst = *rct_src; + ui_window_to_block_fl(ar, block, &rct_dst->xmin, &rct_dst->ymin); + ui_window_to_block_fl(ar, block, &rct_dst->xmax, &rct_dst->ymax); +} + void ui_window_to_block(const ARegion *ar, uiBlock *block, int *x, int *y) { float fx, fy; @@ -232,6 +242,14 @@ void ui_window_to_region(const ARegion *ar, int *x, int *y) *y -= ar->winrct.ymin; } +void ui_window_to_region_rcti(const ARegion *ar, rcti *rect_dst, const rcti *rct_src) +{ + rect_dst->xmin = rct_src->xmin - ar->winrct.xmin; + rect_dst->xmax = rct_src->xmax - ar->winrct.xmin; + rect_dst->ymin = rct_src->ymin - ar->winrct.ymin; + rect_dst->ymax = rct_src->ymax - ar->winrct.ymin; +} + void ui_region_to_window(const ARegion *ar, int *x, int *y) { *x += ar->winrct.xmin; @@ -1274,16 +1292,17 @@ static bool ui_but_event_property_operator_string(const bContext *C, #if 0 else { printf("ERROR in %s(): Couldn't get path for scene property - %s\n", - __func__, RNA_property_identifier(prop)); + __func__, + RNA_property_identifier(prop)); } #endif } } else { - //puts("other id"); + // puts("other id"); } - //printf("prop shortcut: '%s' (%s)\n", RNA_property_identifier(prop), data_path); + // printf("prop shortcut: '%s' (%s)\n", RNA_property_identifier(prop), data_path); } /* we have a datapath! */ @@ -1374,14 +1393,16 @@ static bool ui_but_event_property_operator_string(const bContext *C, * * --Matt 07/2006 */ -const char ui_radial_dir_order[8] = {UI_RADIAL_W, - UI_RADIAL_E, - UI_RADIAL_S, - UI_RADIAL_N, - UI_RADIAL_NW, - UI_RADIAL_NE, - UI_RADIAL_SW, - UI_RADIAL_SE}; +const char ui_radial_dir_order[8] = { + UI_RADIAL_W, + UI_RADIAL_E, + UI_RADIAL_S, + UI_RADIAL_N, + UI_RADIAL_NW, + UI_RADIAL_NE, + UI_RADIAL_SW, + UI_RADIAL_SE, +}; const char ui_radial_dir_to_numpad[8] = {8, 9, 6, 3, 2, 1, 4, 7}; const short ui_radial_dir_to_angle[8] = {90, 45, 0, 315, 270, 225, 180, 135}; @@ -1594,7 +1615,7 @@ void ui_fontscale(short *points, float aspect) /* for some reason scaling fonts goes too fast compared to widget size */ /* XXX not true anymore? (ton) */ - //aspect = sqrt(aspect); + // aspect = sqrt(aspect); pointsf /= aspect; if (aspect > 1.0f) { @@ -2421,8 +2442,10 @@ static float ui_get_but_step_unit(uiBut *but, float step_default) } /** - * \param float_precision: For number buttons the precision to use or -1 to fallback to the button default. - * \param use_exp_float: Use exponent representation of floats when out of reasonable range (outside of 1e3/1e-3). + * \param float_precision: For number buttons the precision + * to use or -1 to fallback to the button default. + * \param use_exp_float: Use exponent representation of floats + * when out of reasonable range (outside of 1e3/1e-3). */ void ui_but_string_get_ex(uiBut *but, char *str, @@ -2751,10 +2774,10 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str) /* This is kind of hackish, in theory think we could only ever use the second member of * this if/else, since ui_searchbox_apply() is supposed to always set that pointer when - * we are storing pointers... But keeping str search first for now, to try to break as little as - * possible existing code. All this is band-aids anyway. - * Fact remains, using editstr as main 'reference' over whole search button thingy is utterly weak - * and should be redesigned imho, but that's not a simple task. */ + * we are storing pointers... But keeping str search first for now, + * to try to break as little as possible existing code. All this is band-aids anyway. + * Fact remains, using editstr as main 'reference' over whole search button thingy + * is utterly weak and should be redesigned imho, but that's not a simple task. */ if (prop && RNA_property_collection_lookup_string(&ptr, prop, str, &rptr)) { RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr); } @@ -6183,9 +6206,9 @@ static void operator_enum_call_cb(struct bContext *UNUSED(C), void *but, void *a if (ot->prop) { RNA_property_enum_set(opptr, ot->prop, POINTER_AS_INT(arg2)); /* We do not call op from here, will be called by button code. - * ui_apply_but_funcs_after() (in interface_handlers.c) called this func before checking operators, - * because one of its parameters is the button itself! - */ + * ui_apply_but_funcs_after() (in interface_handlers.c) + * called this func before checking operators, + * because one of its parameters is the button itself! */ } else { printf("%s: op->prop for '%s' is NULL\n", __func__, ot->idname); @@ -6194,8 +6217,8 @@ static void operator_enum_call_cb(struct bContext *UNUSED(C), void *but, void *a } /** - * Same parameters as for uiDefSearchBut, with additional operator type and properties, used by callback - * to call again the right op with the right options (properties values). + * Same parameters as for uiDefSearchBut, with additional operator type and properties, + * used by callback to call again the right op with the right options (properties values). */ uiBut *uiDefSearchButO_ptr(uiBlock *block, wmOperatorType *ot, diff --git a/source/blender/editors/interface/interface_align.c b/source/blender/editors/interface/interface_align.c index 61f9005ce44..be02def1693 100644 --- a/source/blender/editors/interface/interface_align.c +++ b/source/blender/editors/interface/interface_align.c @@ -139,10 +139,11 @@ int ui_but_align_opposite_to_area_align_get(const ARegion *ar) } /** - * This function checks a pair of buttons (assumed in a same align group), and if they are neighbors, - * set needed data accordingly. + * This function checks a pair of buttons (assumed in a same align group), + * and if they are neighbors, set needed data accordingly. * - * \note It is designed to be called in total random order of buttons. Order-based optimizations are done by caller. + * \note It is designed to be called in total random order of buttons. + * Order-based optimizations are done by caller. */ static void block_align_proximity_compute(ButAlign *butal, ButAlign *butal_other) { @@ -268,13 +269,15 @@ static void block_align_proximity_compute(ButAlign *butal, ButAlign *butal_other * +-----------+ * </pre> * - * Here, BUT 3 RIGHT side would not get 'dragged' to align with BUT 1 RIGHT side, since BUT 3 has not RIGHT neighbor. - * So, this function, when called with BUT 1, will 'walk' the whole column in \a side_s1 direction (TOP or DOWN when - * called for RIGHT side), and force buttons like BUT 3 to align as needed, if BUT 1 and BUT 3 were detected as needing - * top-right corner stitching in #block_align_proximity_compute() step. + * Here, BUT 3 RIGHT side would not get 'dragged' to align with BUT 1 RIGHT side, + * since BUT 3 has not RIGHT neighbor. + * So, this function, when called with BUT 1, will 'walk' the whole column in \a side_s1 direction + * (TOP or DOWN when called for RIGHT side), and force buttons like BUT 3 to align as needed, + * if BUT 1 and BUT 3 were detected as needing top-right corner stitching in + * #block_align_proximity_compute() step. * - * \note To avoid doing this twice, some stitching flags are cleared to break the 'stitching connection' - * between neighbors. + * \note To avoid doing this twice, some stitching flags are cleared to break the + * 'stitching connection' between neighbors. */ static void block_align_stitch_neighbors(ButAlign *butal, const int side, @@ -290,16 +293,17 @@ static void block_align_stitch_neighbors(ButAlign *butal, const int stitch_s1 = STITCH(side_s1); const int stitch_s2 = STITCH(side_s2); - /* We have to check stitching flags on both sides of the stitching, since we only clear one of them flags to break - * any future loop on same 'columns/side' case. - * Also, if butal is spanning over several rows or columns of neighbors, it may have both of its stitching flags + /* We have to check stitching flags on both sides of the stitching, + * since we only clear one of them flags to break any future loop on same 'columns/side' case. + * Also, if butal is spanning over several rows or columns of neighbors, + * it may have both of its stitching flags * set, but would not be the case of its immediate neighbor! */ while ((butal->flags[side] & stitch_s1) && (butal = butal->neighbors[side_s1]) && (butal->flags[side] & stitch_s2)) { butal_neighbor = butal->neighbors[side]; - /* If we actually do have a neighbor, we directly set its values accordingly, and clear its matching 'dist' - * to prevent it being set again later... */ + /* If we actually do have a neighbor, we directly set its values accordingly, + * and clear its matching 'dist' to prevent it being set again later... */ if (butal_neighbor) { butal->but->drawflag |= align; butal_neighbor->but->drawflag |= align_opp; @@ -389,7 +393,8 @@ static void ui_block_align_but_to_region(uiBut *but, const ARegion *region) /** * Compute the alignment of all 'align groups' of buttons in given block. * - * This is using an order-independent algorithm, i.e. alignment of buttons should be OK regardless of order in which + * This is using an order-independent algorithm, + * i.e. alignment of buttons should be OK regardless of order in which * they are added to the block. */ void ui_block_align_calc(uiBlock *block, const ARegion *region) @@ -404,7 +409,8 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region) int side; int i, j; - /* First loop: we count number of buttons belonging to an align group, and clear their align flag. + /* First loop: we count number of buttons belonging to an align group, + * and clear their align flag. * Tabs get some special treatment here, they get aligned to region border. */ for (but = block->buttons.first; but; but = but->next) { /* special case: tabs need to be aligned to a region border, drawflag tells which one */ diff --git a/source/blender/editors/interface/interface_context_menu.c b/source/blender/editors/interface/interface_context_menu.c index afa1b5c87e1..748d6e6c183 100644 --- a/source/blender/editors/interface/interface_context_menu.c +++ b/source/blender/editors/interface/interface_context_menu.c @@ -148,7 +148,7 @@ static uiBlock *menu_add_shortcut(bContext *C, ARegion *ar, void *arg) if (prop) { prop = IDP_CopyProperty(prop); } - WM_keymap_properties_reset(kmi, prop); + WM_keymap_item_properties_reset(kmi, prop); /* update and get pointers again */ WM_keyconfig_update(wm); @@ -655,12 +655,16 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but) #if 0 /* Disabled for now. */ ot = WM_operatortype_find("UI_OT_override_type_set_button", false); uiItemFullO_ptr( - layout, ot, "Overrides Type", ICON_NONE, - NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); + layout, ot, "Overrides Type", ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); RNA_boolean_set(&op_ptr, "all", true); - uiItemFullO_ptr( - layout, ot, "Single Override Type", ICON_NONE, - NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); + uiItemFullO_ptr(layout, + ot, + "Single Override Type", + ICON_NONE, + NULL, + WM_OP_INVOKE_DEFAULT, + 0, + &op_ptr); RNA_boolean_set(&op_ptr, "all", false); #endif uiItemBooleanO(layout, @@ -678,9 +682,14 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but) } else { #if 0 /* Disabled for now. */ - uiItemFullO( - layout, "UI_OT_override_type_set_button", "Override Type", ICON_NONE, - NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); + uiItemFullO(layout, + "UI_OT_override_type_set_button", + "Override Type", + ICON_NONE, + NULL, + WM_OP_INVOKE_DEFAULT, + 0, + &op_ptr); RNA_boolean_set(&op_ptr, "all", false); #endif uiItemBooleanO(layout, @@ -896,9 +905,15 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but) if (kmi) { if (ISKEYBOARD(kmi->type)) { #if 0 /* would rather use a block but, but gets weirdly positioned... */ - uiDefBlockBut( - block, menu_change_shortcut, but, "Change Shortcut", - 0, 0, uiLayoutGetWidth(layout), UI_UNIT_Y, ""); + uiDefBlockBut(block, + menu_change_shortcut, + but, + "Change Shortcut", + 0, + 0, + uiLayoutGetWidth(layout), + UI_UNIT_Y, + ""); #endif but2 = uiDefIconTextBut(block, @@ -1005,9 +1020,14 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but) /* XXX inactive option, not for public! */ #if 0 - uiItemFullO( - layout, "WM_OT_doc_edit", "Submit Description", ICON_NONE, - NULL, WM_OP_INVOKE_DEFAULT, 0, &ptr_props); + uiItemFullO(layout, + "WM_OT_doc_edit", + "Submit Description", + ICON_NONE, + NULL, + WM_OP_INVOKE_DEFAULT, + 0, + &ptr_props); RNA_string_set(&ptr_props, "doc_id", buf); RNA_string_set(&ptr_props, "doc_new", RNA_property_description(but->rnaprop)); #endif @@ -1044,7 +1064,7 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but) if (!ar) { /* skip */ } - else if (ar->regiontype == RGN_TYPE_HEADER) { + else if (ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER)) { uiItemMenuF(layout, IFACE_("Header"), ICON_NONE, ED_screens_header_tools_menu_create, NULL); } else if (ar->regiontype == RGN_TYPE_NAV_BAR) { diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 0517278a149..640d5127446 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -167,8 +167,13 @@ void UI_draw_roundbox_4fv( { #if 0 float vec[7][2] = { - {0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293}, - {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}, + {0.195, 0.02}, + {0.383, 0.067}, + {0.55, 0.169}, + {0.707, 0.293}, + {0.831, 0.45}, + {0.924, 0.617}, + {0.98, 0.805}, }; int a; @@ -270,13 +275,16 @@ void UI_draw_roundbox_4fv( } #if 0 -static void round_box_shade_col(uint attr, const float col1[3], float const col2[3], const float fac) +static void round_box_shade_col(uint attr, + const float col1[3], + float const col2[3], + const float fac) { float col[4] = { - fac * col1[0] + (1.0f - fac) * col2[0], - fac * col1[1] + (1.0f - fac) * col2[1], - fac * col1[2] + (1.0f - fac) * col2[2], - 1.0f, + fac * col1[0] + (1.0f - fac) * col2[0], + fac * col1[1] + (1.0f - fac) * col2[1], + fac * col1[2] + (1.0f - fac) * col2[2], + 1.0f, }; immAttr4fv(attr, col); } @@ -296,8 +304,13 @@ void UI_draw_roundbox_shade_x(bool filled, { #if 0 float vec[7][2] = { - {0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293}, - {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}, + {0.195, 0.02}, + {0.383, 0.067}, + {0.55, 0.169}, + {0.707, 0.293}, + {0.831, 0.45}, + {0.924, 0.617}, + {0.98, 0.805}, }; const float div = maxy - miny; const float idiv = 1.0f / div; @@ -317,9 +330,9 @@ void UI_draw_roundbox_shade_x(bool filled, } /* 'shade' defines strength of shading */ - coltop[0] = min_ff(1.0f, col[0] + shadetop); - coltop[1] = min_ff(1.0f, col[1] + shadetop); - coltop[2] = min_ff(1.0f, col[2] + shadetop); + coltop[0] = min_ff(1.0f, col[0] + shadetop); + coltop[1] = min_ff(1.0f, col[1] + shadetop); + coltop[2] = min_ff(1.0f, col[2] + shadetop); coldown[0] = max_ff(0.0f, col[0] + shadedown); coldown[1] = max_ff(0.0f, col[1] + shadedown); coldown[2] = max_ff(0.0f, col[2] + shadedown); @@ -440,13 +453,24 @@ void UI_draw_roundbox_shade_x(bool filled, #if 0 /* unused */ /* linear vertical shade within button or in outline */ /* view2d scrollers use it */ -void UI_draw_roundbox_shade_y( - bool filled, float minx, float miny, float maxx, float maxy, - float rad, float shadeleft, float shaderight, const float col[4]) +void UI_draw_roundbox_shade_y(bool filled, + float minx, + float miny, + float maxx, + float maxy, + float rad, + float shadeleft, + float shaderight, + const float col[4]) { float vec[7][2] = { - {0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293}, - {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}, + {0.195, 0.02}, + {0.383, 0.067}, + {0.55, 0.169}, + {0.707, 0.293}, + {0.831, 0.45}, + {0.924, 0.617}, + {0.98, 0.805}, }; const float div = maxx - minx; const float idiv = 1.0f / div; @@ -466,14 +490,13 @@ void UI_draw_roundbox_shade_y( immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); /* 'shade' defines strength of shading */ - colLeft[0] = min_ff(1.0f, col[0] + shadeleft); - colLeft[1] = min_ff(1.0f, col[1] + shadeleft); - colLeft[2] = min_ff(1.0f, col[2] + shadeleft); + colLeft[0] = min_ff(1.0f, col[0] + shadeleft); + colLeft[1] = min_ff(1.0f, col[1] + shadeleft); + colLeft[2] = min_ff(1.0f, col[2] + shadeleft); colRight[0] = max_ff(0.0f, col[0] + shaderight); colRight[1] = max_ff(0.0f, col[1] + shaderight); colRight[2] = max_ff(0.0f, col[2] + shaderight); - vert_count += (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 9 : 1; vert_count += (roundboxtype & UI_CNR_TOP_RIGHT) ? 9 : 1; vert_count += (roundboxtype & UI_CNR_TOP_LEFT) ? 9 : 1; @@ -1310,12 +1333,14 @@ void ui_draw_but_VECTORSCOPE(ARegion *UNUSED(ar), const float skin_rad = DEG2RADF(123.0f); /* angle in radians of the skin tone line */ Scopes *scopes = (Scopes *)but->poin; - const float colors[6][3] = {{0.75, 0.0, 0.0}, - {0.75, 0.75, 0.0}, - {0.0, 0.75, 0.0}, - {0.0, 0.75, 0.75}, - {0.0, 0.0, 0.75}, - {0.75, 0.0, 0.75}}; + const float colors[6][3] = { + {0.75, 0.0, 0.0}, + {0.75, 0.75, 0.0}, + {0.0, 0.75, 0.0}, + {0.0, 0.75, 0.75}, + {0.0, 0.0, 0.75}, + {0.75, 0.0, 0.75}, + }; rctf rect = { .xmin = (float)recti->xmin + 1, @@ -1585,16 +1610,10 @@ void ui_draw_but_COLORBAND(uiBut *but, const uiWidgetColors *UNUSED(wcol), const immBindBuiltinProgram(GPU_SHADER_2D_CHECKER); /* Drawing the checkerboard. */ - immUniform4f("color1", - UI_ALPHA_CHECKER_DARK / 255.0f, - UI_ALPHA_CHECKER_DARK / 255.0f, - UI_ALPHA_CHECKER_DARK / 255.0f, - 1.0f); - immUniform4f("color2", - UI_ALPHA_CHECKER_LIGHT / 255.0f, - UI_ALPHA_CHECKER_LIGHT / 255.0f, - UI_ALPHA_CHECKER_LIGHT / 255.0f, - 1.0f); + const float checker_dark = UI_ALPHA_CHECKER_DARK / 255.0f; + const float checker_light = UI_ALPHA_CHECKER_LIGHT / 255.0f; + immUniform4f("color1", checker_dark, checker_dark, checker_dark, 1.0f); + immUniform4f("color2", checker_light, checker_light, checker_light, 1.0f); immUniform1i("size", 8); immRectf(pos_id, x1, y1, x1 + sizex, rect->ymax); immUnbindProgram(); @@ -1779,12 +1798,12 @@ static void ui_draw_but_curve_grid( 1.0f); immBegin(GPU_PRIM_LINES, (int)line_count * 2); - while (fx < rect->xmax) { + while (fx <= rect->xmax) { immVertex2f(pos, fx, rect->ymin); immVertex2f(pos, fx, rect->ymax); fx += dx; } - while (fy < rect->ymax) { + while (fy <= rect->ymax) { immVertex2f(pos, rect->xmin, fy); immVertex2f(pos, rect->xmax, fy); fy += dy; @@ -1824,6 +1843,17 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, const uiWidgetColors *wcol, cons cumap = (CurveMapping *)but->poin; } + /* calculate offset and zoom */ + float zoomx = (BLI_rcti_size_x(rect) - 2.0f) / BLI_rctf_size_x(&cumap->curr); + float zoomy = (BLI_rcti_size_y(rect) - 2.0f) / BLI_rctf_size_y(&cumap->curr); + float offsx = cumap->curr.xmin - (1.0f / zoomx); + float offsy = cumap->curr.ymin - (1.0f / zoomy); + + /* exit early if too narrow */ + if (zoomx == 0.0f) { + return; + } + CurveMap *cuma = &cumap->cm[cumap->cur]; /* need scissor test, curve can draw outside of boundary */ @@ -1842,12 +1872,6 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, const uiWidgetColors *wcol, cons BLI_rcti_size_x(&scissor_new), BLI_rcti_size_y(&scissor_new)); - /* calculate offset and zoom */ - float zoomx = (BLI_rcti_size_x(rect) - 2.0f) / BLI_rctf_size_x(&cumap->curr); - float zoomy = (BLI_rcti_size_y(rect) - 2.0f) / BLI_rctf_size_y(&cumap->curr); - float offsx = cumap->curr.xmin - (1.0f / zoomx); - float offsy = cumap->curr.ymin - (1.0f / zoomy); - /* Do this first to not mess imm context */ if (but->a1 == UI_GRAD_H) { /* magic trigger for curve backgrounds */ @@ -2461,7 +2485,8 @@ void ui_draw_dropshadow( /* alpha ranges from 2 to 20 or so */ #if 0 /* Old Method (pre 2.8) */ float color[4] = {0.0f, 0.0f, 0.0f, calpha}; - UI_draw_roundbox_4fv(true, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax - 10.0f + a, rad + a, color); + UI_draw_roundbox_4fv( + true, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax - 10.0f + a, rad + a, color); #endif /* Compute final visibility to match old method result. */ /* TODO we could just find a better fit function inside the shader instead of this. */ diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 0fe12b21636..8f19f40d1c0 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -205,14 +205,20 @@ static void ui_selectcontext_apply(bContext *C, # define DRAG_MULTINUM_THRESHOLD_DRAG_X (UI_UNIT_Y / 4) /** - * how far to drag horizontally before we stop checking which buttons the gesture spans (in pixels), - * locking down the buttons so we can drag freely without worrying about vertical movement. */ + * How far to drag horizontally + * before we stop checking which buttons the gesture spans (in pixels), + * locking down the buttons so we can drag freely without worrying about vertical movement. + */ # define DRAG_MULTINUM_THRESHOLD_DRAG_Y (UI_UNIT_Y / 4) /** - * how strict to be when detecting a vertical gesture, [0.5 == sloppy], [0.9 == strict], (unsigned dot-product) - * note: we should be quite strict here, since doing a vertical gesture by accident should be avoided, - * however with some care a user should be able to do a vertical movement without *missing*. */ + * How strict to be when detecting a vertical gesture: + * [0.5 == sloppy], [0.9 == strict], (unsigned dot-product). + * + * \note We should be quite strict here, + * since doing a vertical gesture by accident should be avoided, + * however with some care a user should be able to do a vertical movement without _missing_. + */ # define DRAG_MULTINUM_THRESHOLD_VERTICAL (0.75f) /* a simple version of uiHandleButtonData when accessing multiple buttons */ @@ -912,8 +918,8 @@ static void ui_apply_but_TEX(bContext *C, uiBut *but, uiHandleButtonData *data) * feature used for bone renaming, channels, etc. * afterfunc frees rename_orig */ if (data->origstr && (but->flag & UI_BUT_TEXTEDIT_UPDATE)) { - /* In this case, we need to keep origstr available, to restore real org string in case we cancel after - * having typed something already. */ + /* In this case, we need to keep origstr available, + * to restore real org string in case we cancel after having typed something already. */ but->rename_orig = BLI_strdup(data->origstr); } /* only if there are afterfuncs, otherwise 'renam_orig' isn't freed */ @@ -1271,8 +1277,8 @@ static int ui_drag_toggle_but_pushed_state(bContext *C, uiBut *but) } else { /* Assume icon identifies a unique state, for buttons that - * work though functions callbacks and don't have an boolean - * value that indicates the state. */ + * work though functions callbacks and don't have an boolean + * value that indicates the state. */ return but->icon + but->iconadd; } } @@ -1314,8 +1320,8 @@ static bool ui_drag_toggle_set_xy_xy( ui_window_to_block_fl(ar, block, &xy_b_block[0], &xy_b_block[1]); for (but = block->buttons.first; but; but = but->next) { - /* Note: ctrl is always true here because (at least for now) we always want to consider text control - * in this case, even when not embossed. */ + /* Note: ctrl is always true here because (at least for now) + * we always want to consider text control in this case, even when not embossed. */ if (ui_but_is_interactive(but, true)) { if (BLI_rctf_isect_segment(&but->rect, xy_a_block, xy_b_block)) { @@ -1772,7 +1778,11 @@ static bool ui_but_drag_init(bContext *C, /* Initialize alignment for single row/column regions, * otherwise we use the relative position of the first other button dragged over. */ - if (ELEM(data->region->regiontype, RGN_TYPE_NAV_BAR, RGN_TYPE_HEADER, RGN_TYPE_FOOTER)) { + if (ELEM(data->region->regiontype, + RGN_TYPE_NAV_BAR, + RGN_TYPE_HEADER, + RGN_TYPE_TOOL_HEADER, + RGN_TYPE_FOOTER)) { int lock_axis = -1; if (ELEM(data->region->alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) { lock_axis = 0; @@ -3787,7 +3797,7 @@ static void ui_block_open_begin(bContext *C, uiBut *but, uiHandleButtonData *dat #endif /* this makes adjacent blocks auto open from now on */ - //if (but->block->auto_open == 0) { + // if (but->block->auto_open == 0) { // but->block->auto_open = 1; //} } @@ -5302,12 +5312,14 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, co button_activate_state(C, but, BUTTON_STATE_EXIT); ui_apply_but(C, but->block, but, data, true); - /* button's state need to be changed to EXIT so moving mouse away from this mouse wouldn't lead - * to cancel changes made to this button, but changing state to EXIT also makes no button active for - * a while which leads to triggering operator when doing fast scrolling mouse wheel. - * using post activate stuff from button allows to make button be active again after checking for all - * all that mouse leave and cancel stuff, so quick scroll wouldn't be an issue anymore. - * same goes for scrolling wheel in another direction below (sergey) + /* Button's state need to be changed to EXIT so moving mouse away from this mouse wouldn't + * lead to cancel changes made to this button, but changing state to EXIT also makes no + * button active for a while which leads to triggering operator + * when doing fast scrolling mouse wheel. + * using post activate stuff from button allows to make button be active again after + * checking for all all that mouse leave and cancel stuff, + * so quick scroll wouldn't be an issue anymore. + * Same goes for scrolling wheel in another direction below (sergey). */ data->postbut = but; data->posttype = BUTTON_ACTIVATE_OVER; @@ -7680,6 +7692,11 @@ uiBut *UI_region_active_but_get(ARegion *ar) return ui_context_button_active(ar, NULL); } +uiBut *UI_region_but_find_rect_over(const ARegion *ar, const rcti *rect_px) +{ + return ui_but_find_rect_over(ar, rect_px); +} + /** * Version of #UI_context_active_but_get that also returns RNA property info. * Helper function for insert keyframe, reset to default, etc operators. @@ -8730,6 +8747,13 @@ static bool ui_menu_scroll_step(ARegion *ar, uiBlock *block, const int scroll_di /** \name Menu Event Handling * \{ */ +static void ui_region_auto_open_clear(ARegion *ar) +{ + for (uiBlock *block = ar->uiblocks.first; block; block = block->next) { + block->auto_open = false; + } +} + /** * Special function to handle nested menus. * let the parent menu get the event. @@ -8772,6 +8796,7 @@ static int ui_handle_menu_button(bContext *C, const wmEvent *event, uiPopupBlock } else if (!ui_region_contains_point_px(but->active->region, event->x, event->y)) { /* pass, needed to click-exit outside of non-flaoting menus */ + ui_region_auto_open_clear(but->active->region); } else if ((!ELEM(event->type, MOUSEMOVE, WHEELUPMOUSE, WHEELDOWNMOUSE, MOUSEPAN)) && ISMOUSE(event->type)) { @@ -9905,7 +9930,8 @@ static int ui_handle_menus_recursive(bContext *C, } /** - * Allow setting menu return value from externals. E.g. WM might need to do this for exiting files correctly. + * Allow setting menu return value from externals. + * E.g. WM might need to do this for exiting files correctly. */ void UI_popup_menu_retval_set(const uiBlock *block, const int retval, const bool enable) { diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index e2a75abebd7..7e295f83390 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -731,7 +731,11 @@ static void init_internal_icons(void) bbuf = IMB_loadiffname(iconfilestr, IB_rect, NULL); if (bbuf && (bbuf->x < ICON_IMAGE_W || bbuf->y < ICON_IMAGE_H)) { - printf("\n***WARNING***\nIcons file %s too small.\nUsing built-in Icons instead\n", iconfilestr); + printf( + "\n***WARNING***\n" + "Icons file '%s' too small.\n" + "Using built-in Icons instead\n", + iconfilestr); IMB_freeImBuf(bbuf); bbuf = NULL; } @@ -1822,15 +1826,14 @@ static int ui_id_brush_get_icon(const bContext *C, ID *id) ui_id_icon_render(C, id, true); } else { - WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); const EnumPropertyItem *items = NULL; ePaintMode paint_mode = PAINT_MODE_INVALID; ScrArea *sa = CTX_wm_area(C); char space_type = sa->spacetype; - /* When in an unsupported space. */ - if (!ELEM(space_type, SPACE_VIEW3D, SPACE_IMAGE)) { - space_type = workspace->tools_space_type; + /* Fallback to 3D view. */ + if (space_type == SPACE_PROPERTIES) { + space_type = SPACE_VIEW3D; } /* XXX: this is not nice, should probably make brushes @@ -1852,17 +1855,11 @@ static int ui_id_brush_get_icon(const bContext *C, ID *id) } } else if (space_type == SPACE_IMAGE) { - int sima_mode; if (sa->spacetype == space_type) { - SpaceImage *sima = sa->spacedata.first; - sima_mode = sima->mode; - } - else { - sima_mode = workspace->tools_mode; - } - - if (sima_mode == SI_MODE_PAINT) { - paint_mode = PAINT_MODE_TEXTURE_2D; + const SpaceImage *sima = sa->spacedata.first; + if (sima->mode == SI_MODE_PAINT) { + paint_mode = PAINT_MODE_TEXTURE_2D; + } } } diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 86ca2241881..4af7fdd779f 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -172,21 +172,25 @@ struct uiBut { /* both these values use depends on the button type * (polymorphic struct or union would be nicer for this stuff) */ - /* (type == UI_BTYPE_HSVCUBE), Use UI_GRAD_* values. - * (type == UI_BTYPE_NUM), Use to store RNA 'step' value, for dragging and click-step. - * (type == UI_BTYPE_LABEL), Use (a1 == 1.0f) to use a2 as a blending factor (wow, this is imaginative!). - * (type == UI_BTYPE_SCROLL) Use as scroll size. - * (type == UI_BTYPE_SEARCH_MENU) Use as number or rows. - * (type == UI_BTYPE_COLOR) Use as indication of color palette - * (type == UI_BTYPE_PROGRESS_BAR) Use to store progress (0..1). + /** + * For #uiBut.type: + * - UI_BTYPE_HSVCUBE: Use UI_GRAD_* values. + * - UI_BTYPE_NUM: Use to store RNA 'step' value, for dragging and click-step. + * - UI_BTYPE_LABEL: Use `(a1 == 1.0f)` to use a2 as a blending factor (imaginative!). + * - UI_BTYPE_SCROLL: Use as scroll size. + * - UI_BTYPE_SEARCH_MENU: Use as number or rows. + * - UI_BTYPE_COLOR: Use as indication of color palette. + * - UI_BTYPE_PROGRESS_BAR: Use to store progress (0..1). */ float a1; - /* (type == UI_BTYPE_HSVCIRCLE ), Use to store the luminosity. - * (type == UI_BTYPE_NUM), Use to store RNA 'precision' value, for dragging and click-step. - * (type == UI_BTYPE_LABEL), If (a1 == 1.0f) use a2 as a blending factor. - * (type == UI_BTYPE_SEARCH_MENU) Use as number or columns. - * (type == UI_BTYPE_COLOR) Use as index in palette (not so good, needs refactor) + /** + * For #uiBut.type: + * - UI_BTYPE_HSVCIRCLE: Use to store the luminosity. + * - UI_BTYPE_NUM: Use to store RNA 'precision' value, for dragging and click-step. + * - UI_BTYPE_LABEL: If `(a1 == 1.0f)` use a2 as a blending factor. + * - UI_BTYPE_SEARCH_MENU: Use as number or columns. + * - UI_BTYPE_COLOR: Use as index in palette (not so good, needs refactor). */ float a2; @@ -456,7 +460,12 @@ extern void ui_block_to_window_rctf(const struct ARegion *ar, extern float ui_block_to_window_scale(const struct ARegion *ar, uiBlock *block); extern void ui_window_to_block_fl(const struct ARegion *ar, uiBlock *block, float *x, float *y); extern void ui_window_to_block(const struct ARegion *ar, uiBlock *block, int *x, int *y); +extern void ui_window_to_block_rctf(const struct ARegion *ar, + uiBlock *block, + rctf *rct_dst, + const rctf *rct_src); extern void ui_window_to_region(const ARegion *ar, int *x, int *y); +extern void ui_window_to_region_rcti(const ARegion *ar, rcti *rect_dst, const rcti *rct_src); extern void ui_region_to_window(const struct ARegion *ar, int *x, int *y); extern void ui_region_winrct_get_no_margin(const struct ARegion *ar, struct rcti *r_rect); @@ -894,6 +903,7 @@ void ui_but_pie_dir(RadialDirection dir, float vec[2]); bool ui_but_is_cursor_warp(const uiBut *but) ATTR_WARN_UNUSED_RESULT; bool ui_but_contains_pt(const uiBut *but, float mx, float my) ATTR_WARN_UNUSED_RESULT; +bool ui_but_contains_rect(const uiBut *but, const rctf *rect); bool ui_but_contains_point_px_icon(const uiBut *but, struct ARegion *ar, const struct wmEvent *event) ATTR_WARN_UNUSED_RESULT; @@ -909,6 +919,8 @@ uiBut *ui_but_find_mouse_over_ex(struct ARegion *ar, const bool labeledit) ATTR_WARN_UNUSED_RESULT; uiBut *ui_but_find_mouse_over(struct ARegion *ar, const struct wmEvent *event) ATTR_WARN_UNUSED_RESULT; +uiBut *ui_but_find_rect_over(const struct ARegion *ar, + const rcti *rect_px) ATTR_WARN_UNUSED_RESULT; uiBut *ui_list_find_mouse_over_ex(struct ARegion *ar, int x, int y) ATTR_WARN_UNUSED_RESULT; @@ -927,6 +939,7 @@ bool ui_block_is_popup_any(const uiBlock *block) ATTR_WARN_UNUSED_RESULT; uiBut *ui_region_find_first_but_test_flag(struct ARegion *ar, int flag_include, int flag_exclude); uiBut *ui_region_find_active_but(struct ARegion *ar) ATTR_WARN_UNUSED_RESULT; bool ui_region_contains_point_px(const struct ARegion *ar, int x, int y) ATTR_WARN_UNUSED_RESULT; +bool ui_region_contains_rect_px(const struct ARegion *ar, const rcti *rect_px); /* interface_context_menu.c */ bool ui_popup_context_menu_for_button(struct bContext *C, uiBut *but); diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 8e463bf8447..41001ff6d14 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -112,7 +112,7 @@ typedef enum uiItemType { ITEM_LAYOUT_ROOT #if 0 - TEMPLATE_COLUMN_FLOW, + TEMPLATE_COLUMN_FLOW, TEMPLATE_SPLIT, TEMPLATE_BOX, @@ -722,33 +722,87 @@ static void ui_item_enum_expand_handle(bContext *C, void *arg1, void *arg2) RNA_property_enum_set(&but->rnapoin, but->rnaprop, current_value); } } + +/** + * Draw a single enum button, a utility for #ui_item_enum_expand_exec + */ +static void ui_item_enum_expand_elem_exec(uiLayout *layout, + uiBlock *block, + PointerRNA *ptr, + PropertyRNA *prop, + const char *uiname, + const int h, + const eButType but_type, + const bool icon_only, + const EnumPropertyItem *item, + const bool is_first) +{ + const char *name = (!uiname || uiname[0]) ? item->name : ""; + const int icon = item->icon; + const int value = item->value; + const int itemw = ui_text_icon_width(block->curlayout, icon_only ? "" : name, icon, 0); + + uiBut *but; + + if (icon && name[0] && !icon_only) { + but = uiDefIconTextButR_prop( + block, but_type, 0, icon, name, 0, 0, itemw, h, ptr, prop, -1, 0, value, -1, -1, NULL); + } + else if (icon) { + const int w = (is_first) ? itemw : ceilf(itemw - U.pixelsize); + but = uiDefIconButR_prop( + block, but_type, 0, icon, 0, 0, w, h, ptr, prop, -1, 0, value, -1, -1, NULL); + } + else { + but = uiDefButR_prop( + block, but_type, 0, name, 0, 0, itemw, h, ptr, prop, -1, 0, value, -1, -1, NULL); + } + + if (RNA_property_flag(prop) & PROP_ENUM_FLAG) { + /* If this is set, assert since we're clobbering someone elses callback. */ + BLI_assert(but->func == NULL); + UI_but_func_set(but, ui_item_enum_expand_handle, but, POINTER_FROM_INT(value)); + } + + if (uiLayoutGetLocalDir(layout) != UI_LAYOUT_HORIZONTAL) { + but->drawflag |= UI_BUT_TEXT_LEFT; + } + + /* Allow quick, inaccurate swipe motions to switch tabs + * (no need to keep cursor over them). */ + if (but_type == UI_BTYPE_TAB) { + but->flag |= UI_BUT_DRAG_LOCK; + } +} + static void ui_item_enum_expand_exec(uiLayout *layout, uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, const char *uiname, - int h, - int but_type, - bool icon_only) -{ - /* XXX The way this function currently handles uiname parameter is insane and inconsistent with general UI API: - * * uiname is the *enum property* label. - * * when it is NULL or empty, we do not draw *enum items* labels, this doubles the icon_only parameter. - * * we *never* draw (i.e. really use) the enum label uiname, it is just used as a mere flag! - * Unfortunately, fixing this implies an API "soft break", so better to defer it for later... :/ - * --mont29 + const int h, + const eButType but_type, + const bool icon_only) +{ + /* XXX: The way this function currently handles uiname parameter + * is insane and inconsistent with general UI API: + * + * - uiname is the *enum property* label. + * - when it is NULL or empty, we do not draw *enum items* labels, + * this doubles the icon_only parameter. + * - we *never* draw (i.e. really use) the enum label uiname, it is just used as a mere flag! + * + * Unfortunately, fixing this implies an API "soft break", so better to defer it for later... :/ + * - mont29 */ - uiBut *but; - uiLayout *layout_radial = NULL; const EnumPropertyItem *item, *item_array; - const char *name; - int itemw, icon, value; bool free; - bool radial = (layout->root->type == UI_LAYOUT_PIEMENU); BLI_assert(RNA_property_type(prop) == PROP_ENUM); + uiLayout *layout_radial = NULL; + bool radial = (layout->root->type == UI_LAYOUT_PIEMENU); if (radial) { RNA_property_enum_items_gettexted_all(block->evil_C, ptr, prop, &item_array, NULL, &free); } @@ -769,11 +823,12 @@ static void ui_item_enum_expand_exec(uiLayout *layout, UI_block_layout_set_current(block, layout); } } - else if (layout->root->type != UI_LAYOUT_MENU) { - UI_block_layout_set_current(block, ui_item_local_sublayout(layout, layout, 1)); + else if (ELEM(layout->item.type, ITEM_LAYOUT_GRID_FLOW, ITEM_LAYOUT_COLUMN_FLOW) || + layout->root->type == UI_LAYOUT_MENU) { + UI_block_layout_set_current(block, layout); } else { - UI_block_layout_set_current(block, layout); + UI_block_layout_set_current(block, ui_item_local_sublayout(layout, layout, 1)); } for (item = item_array; item->identifier; item++) { @@ -802,54 +857,10 @@ static void ui_item_enum_expand_exec(uiLayout *layout, continue; } - name = (!uiname || uiname[0]) ? item->name : ""; - icon = item->icon; - value = item->value; - itemw = ui_text_icon_width(block->curlayout, icon_only ? "" : name, icon, 0); - - if (icon && name[0] && !icon_only) { - but = uiDefIconTextButR_prop( - block, but_type, 0, icon, name, 0, 0, itemw, h, ptr, prop, -1, 0, value, -1, -1, NULL); - } - else if (icon) { - but = uiDefIconButR_prop(block, - but_type, - 0, - icon, - 0, - 0, - (is_first) ? itemw : ceilf(itemw - U.pixelsize), - h, - ptr, - prop, - -1, - 0, - value, - -1, - -1, - NULL); - } - else { - but = uiDefButR_prop( - block, but_type, 0, name, 0, 0, itemw, h, ptr, prop, -1, 0, value, -1, -1, NULL); - } - - if (RNA_property_flag(prop) & PROP_ENUM_FLAG) { - /* If this is set, assert since we're clobbering someone elses callback. */ - BLI_assert(but->func == NULL); - UI_but_func_set(but, ui_item_enum_expand_handle, but, POINTER_FROM_INT(value)); - } - - if (uiLayoutGetLocalDir(layout) != UI_LAYOUT_HORIZONTAL) { - but->drawflag |= UI_BUT_TEXT_LEFT; - } - - /* Allow quick, inaccurate swipe motions to switch tabs - * (no need to keep cursor over them). */ - if (but_type == UI_BTYPE_TAB) { - but->flag |= UI_BUT_DRAG_LOCK; - } + ui_item_enum_expand_elem_exec( + layout, block, ptr, prop, uiname, h, but_type, icon_only, item, is_first); } + UI_block_layout_set_current(block, layout); if (free) { @@ -861,8 +872,8 @@ static void ui_item_enum_expand(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, const char *uiname, - int h, - bool icon_only) + const int h, + const bool icon_only) { ui_item_enum_expand_exec(layout, block, ptr, prop, uiname, h, UI_BTYPE_ROW, icon_only); } @@ -872,8 +883,8 @@ static void ui_item_enum_expand_tabs(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, const char *uiname, - int h, - bool icon_only) + const int h, + const bool icon_only) { uiBut *last = block->buttons.last; @@ -1533,12 +1544,14 @@ void uiItemsFullEnumO(uiLayout *layout, bool free; if (ui_layout_is_radial(layout)) { - /* XXX: While "_all()" guarantees spatial stability, it's bad when an enum has > 8 items total, - * but only a small subset will ever be shown at once (e.g. Mode Switch menu, after the - * introduction of GP editing modes) + /* XXX: While "_all()" guarantees spatial stability, + * it's bad when an enum has > 8 items total, + * but only a small subset will ever be shown at once + * (e.g. Mode Switch menu, after the introduction of GP editing modes). */ #if 0 - RNA_property_enum_items_gettexted_all(block->evil_C, &ptr, prop, &item_array, &totitem, &free); + RNA_property_enum_items_gettexted_all( + block->evil_C, &ptr, prop, &item_array, &totitem, &free); #else RNA_property_enum_items_gettexted(block->evil_C, &ptr, prop, &item_array, &totitem, &free); #endif @@ -2955,6 +2968,9 @@ void uiItemS_ex(uiLayout *layout, float factor) { uiBlock *block = layout->root->block; bool is_menu = ui_block_is_menu(block); + if (is_menu && !UI_block_can_add_separator(block)) { + return; + } int space = (is_menu) ? 0.45f * UI_UNIT_X : 0.3f * UI_UNIT_X; space *= factor; @@ -3736,9 +3752,10 @@ static void ui_litem_layout_column_flow(uiLayout *litem) emy = 0; /* need to reset height again for next column */ col++; - /* (< remaining width > - < space between remaining columns >) / <remamining columns > */ - w = ((litem->w - (x - litem->x)) - (flow->totcol - col - 1) * style->columnspace) / - (flow->totcol - col); + const int remaining_width = litem->w - (x - litem->x); + const int remaining_width_between_columns = (flow->totcol - col - 1) * style->columnspace; + const int remaining_columns = flow->totcol - col; + w = (remaining_width - remaining_width_between_columns) / remaining_columns; } } @@ -3963,9 +3980,10 @@ static void ui_litem_estimate_grid_flow(uiLayout *litem) return; } - /* Even in varying column width case, we fix our columns number from weighted average width of items, - * a proper solving of required width would be too costly, and this should give reasonably good results - * in all reasonable cases... */ + /* Even in varying column width case, + * we fix our columns number from weighted average width of items, + * a proper solving of required width would be too costly, + * and this should give reasonably good results in all reasonable cases. */ if (gflow->columns_len > 0) { gflow->tot_columns = gflow->columns_len; } @@ -4434,7 +4452,8 @@ uiLayout *uiLayoutBox(uiLayout *layout) } /** - * Check all buttons defined in this layout, and set any button flagged as UI_BUT_LIST_ITEM as active/selected. + * Check all buttons defined in this layout, + * and set any button flagged as UI_BUT_LIST_ITEM as active/selected. * Needed to handle correctly text colors of active (selected) list item. */ void ui_layout_list_set_labels_active(uiLayout *layout) diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 537a1d4c851..768cc32aeb5 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -1125,8 +1125,7 @@ static void ui_editsource_active_but_clear(void) static bool ui_editsource_uibut_match(uiBut *but_a, uiBut *but_b) { # if 0 - printf("matching buttons: '%s' == '%s'\n", - but_a->drawstr, but_b->drawstr); + printf("matching buttons: '%s' == '%s'\n", but_a->drawstr, but_b->drawstr); # endif /* this just needs to be a 'good-enough' comparison so we can know beyond @@ -1153,8 +1152,7 @@ void UI_editsource_active_but_test(uiBut *but) int lineno = -1; # if 0 - printf("comparing buttons: '%s' == '%s'\n", - but->drawstr, ui_editsource_info->but_orig.drawstr); + printf("comparing buttons: '%s' == '%s'\n", but->drawstr, ui_editsource_info->but_orig.drawstr); # endif PyC_FileAndNum_Safe(&fn, &lineno); diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 34e13f6620b..87e58a4b3b5 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -267,7 +267,8 @@ static void ui_panel_copy_offset(Panel *pa, Panel *papar) } /** - * XXX Disabled paneltab handling for now. Old 2.4x feature, *DO NOT* confuse it with new tool tabs in 2.70. ;) + * XXX Disabled paneltab handling for now. Old 2.4x feature, + * *DO NOT* confuse it with new tool tabs in 2.70. ;) * See also T41704. */ /* #define UI_USE_PANELTAB */ @@ -700,11 +701,10 @@ void ui_draw_aligned_panel(uiStyle *style, const bool is_closed_x = (panel->flag & PNL_CLOSEDX) ? true : false; const bool is_closed_y = (panel->flag & PNL_CLOSEDY) ? true : false; const bool is_subpanel = (panel->type && panel->type->parent); - const bool show_drag = - (!is_subpanel && - /* FIXME(campbell): currently no background means floating panel which can't be dragged. - * This may be changed in future. */ - show_background); + const bool show_drag = (!is_subpanel && + /* FIXME(campbell): currently no background means floating panel which + * can't be dragged. This may be changed in future. */ + show_background); if (panel->paneltab) { return; @@ -1671,7 +1671,7 @@ static void ui_handle_panel_header( if (mx <= block->rect.xmax - 8 - PNL_ICON) { button = 2; } - //else if (mx <= block->rect.xmin + 10 + 2 * PNL_ICON + 2) { + // else if (mx <= block->rect.xmin + 10 + 2 * PNL_ICON + 2) { // button = 1; //} } @@ -1756,7 +1756,7 @@ static void ui_handle_panel_header( } } -bool UI_panel_category_is_visible(ARegion *ar) +bool UI_panel_category_is_visible(const ARegion *ar) { /* more than one */ return ar->panels_category.first && ar->panels_category.first != ar->panels_category.last; @@ -2063,7 +2063,7 @@ void UI_panel_category_draw_all(ARegion *ar, const char *category_id_active) BLF_enable(fontid, BLF_ROTATION); BLF_rotation(fontid, M_PI_2); - //UI_fontstyle_set(&style->widget); + // UI_fontstyle_set(&style->widget); ui_fontscale(&fstyle_points, aspect / (U.pixelsize * 1.1f)); BLF_size(fontid, fstyle_points, U.dpi); @@ -2568,7 +2568,7 @@ static void panel_activate_state(const bContext *C, Panel *pa, uiHandlePanelStat * is very hard to control and use, and has no real benefit." - BillRey * Aligorith, 2009Sep */ - //test_add_new_tabs(ar); // also copies locations of tabs in dragged panel + // test_add_new_tabs(ar); // also copies locations of tabs in dragged panel check_panel_overlap(ar, NULL); /* clears */ } diff --git a/source/blender/editors/interface/interface_query.c b/source/blender/editors/interface/interface_query.c index be09e44fa9d..b0fd0cdc35f 100644 --- a/source/blender/editors/interface/interface_query.c +++ b/source/blender/editors/interface/interface_query.c @@ -201,17 +201,19 @@ bool ui_but_contains_pt(const uiBut *but, float mx, float my) return BLI_rctf_isect_pt(&but->rect, mx, my); } +bool ui_but_contains_rect(const uiBut *but, const rctf *rect) +{ + return BLI_rctf_isect(&but->rect, rect, NULL); +} + bool ui_but_contains_point_px(const uiBut *but, const ARegion *ar, int x, int y) { uiBlock *block = but->block; - float mx, my; if (!ui_region_contains_point_px(ar, x, y)) { return false; } - mx = x; - my = y; - + float mx = x, my = y; ui_window_to_block_fl(ar, block, &mx, &my); if (but->pie_dir != UI_RADIAL_NONE) { @@ -253,23 +255,16 @@ bool ui_but_contains_point_px_icon(const uiBut *but, ARegion *ar, const wmEvent /* x and y are only used in case event is NULL... */ uiBut *ui_but_find_mouse_over_ex(ARegion *ar, const int x, const int y, const bool labeledit) { - uiBlock *block; - uiBut *but, *butover = NULL; - float mx, my; + uiBut *butover = NULL; - // if (!win->active) { - // return NULL; - // } if (!ui_region_contains_point_px(ar, x, y)) { return NULL; } - - for (block = ar->uiblocks.first; block; block = block->next) { - mx = x; - my = y; + for (uiBlock *block = ar->uiblocks.first; block; block = block->next) { + float mx = x, my = y; ui_window_to_block_fl(ar, block, &mx, &my); - for (but = block->buttons.last; but; but = but->prev) { + for (uiBut *but = block->buttons.last; but; but = but->prev) { if (ui_but_is_interactive(but, labeledit)) { if (but->pie_dir != UI_RADIAL_NONE) { if (ui_but_isect_pie_seg(block, but)) { @@ -301,22 +296,53 @@ uiBut *ui_but_find_mouse_over(ARegion *ar, const wmEvent *event) return ui_but_find_mouse_over_ex(ar, event->x, event->y, event->ctrl != 0); } -uiBut *ui_list_find_mouse_over_ex(ARegion *ar, int x, int y) +uiBut *ui_but_find_rect_over(const struct ARegion *ar, const rcti *rect_px) { - uiBlock *block; - uiBut *but; - float mx, my; + if (!ui_region_contains_rect_px(ar, rect_px)) { + return NULL; + } + + /* Currently no need to expose this at the moment. */ + bool labeledit = true; + rctf rect_px_fl; + BLI_rctf_rcti_copy(&rect_px_fl, rect_px); + uiBut *butover = NULL; + + for (uiBlock *block = ar->uiblocks.first; block; block = block->next) { + rctf rect_block; + ui_window_to_block_rctf(ar, block, &rect_block, &rect_px_fl); + for (uiBut *but = block->buttons.last; but; but = but->prev) { + if (ui_but_is_interactive(but, labeledit)) { + /* No pie menu support. */ + BLI_assert(but->pie_dir == UI_RADIAL_NONE); + if (ui_but_contains_rect(but, &rect_block)) { + butover = but; + break; + } + } + } + + /* CLIP_EVENTS prevents the event from reaching other blocks */ + if (block->flag & UI_BLOCK_CLIP_EVENTS) { + /* check if mouse is inside block */ + if (BLI_rctf_isect(&block->rect, &rect_block, NULL)) { + break; + } + } + } + return butover; +} + +uiBut *ui_list_find_mouse_over_ex(ARegion *ar, int x, int y) +{ if (!ui_region_contains_point_px(ar, x, y)) { return NULL; } - - for (block = ar->uiblocks.first; block; block = block->next) { - mx = x; - my = y; + for (uiBlock *block = ar->uiblocks.first; block; block = block->next) { + float mx = x, my = y; ui_window_to_block_fl(ar, block, &mx, &my); - - for (but = block->buttons.last; but; but = but->prev) { + for (uiBut *but = block->buttons.last; but; but = but->prev) { if (but->type == UI_BTYPE_LISTBOX && ui_but_contains_pt(but, mx, my)) { return but; } @@ -447,6 +473,15 @@ bool UI_block_is_empty(const uiBlock *block) return true; } +bool UI_block_can_add_separator(const uiBlock *block) +{ + if (ui_block_is_menu(block) && !ui_block_is_pie_menu(block)) { + const uiBut *but = block->buttons.last; + return (but && !ELEM(but->type, UI_BTYPE_SEPR_LINE, UI_BTYPE_SEPR)); + } + return true; +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -455,11 +490,8 @@ bool UI_block_is_empty(const uiBlock *block) uiBut *ui_region_find_active_but(ARegion *ar) { - uiBlock *block; - uiBut *but; - - for (block = ar->uiblocks.first; block; block = block->next) { - for (but = block->buttons.first; but; but = but->next) { + for (uiBlock *block = ar->uiblocks.first; block; block = block->next) { + for (uiBut *but = block->buttons.first; but; but = but->next) { if (but->active) { return but; } @@ -485,22 +517,14 @@ uiBut *ui_region_find_first_but_test_flag(ARegion *ar, int flag_include, int fla /** \} */ /* -------------------------------------------------------------------- */ -/** \name Region (#ARegion) State +/** \name Region (#ARegion) Spatial * \{ */ bool ui_region_contains_point_px(const ARegion *ar, int x, int y) { rcti winrct; - - /* scale down area rect to exclude shadow */ ui_region_winrct_get_no_margin(ar, &winrct); - - /* check if the mouse is in the region */ if (!BLI_rcti_isect_pt(&winrct, x, y)) { - for (uiBlock *block = ar->uiblocks.first; block; block = block->next) { - block->auto_open = false; - } - return false; } @@ -511,14 +535,9 @@ bool ui_region_contains_point_px(const ARegion *ar, int x, int y) */ if (ar->v2d.mask.xmin != ar->v2d.mask.xmax) { const View2D *v2d = &ar->v2d; - int mx, my; + int mx = x, my = y; - /* convert window coordinates to region coordinates */ - mx = x; - my = y; ui_window_to_region(ar, &mx, &my); - - /* check if in the rect */ if (!BLI_rcti_isect_pt(&v2d->mask, mx, my) || UI_view2d_mouse_in_scrollers(ar, &ar->v2d, x, y)) { return false; @@ -528,4 +547,26 @@ bool ui_region_contains_point_px(const ARegion *ar, int x, int y) return true; } +bool ui_region_contains_rect_px(const ARegion *ar, const rcti *rect_px) +{ + rcti winrct; + ui_region_winrct_get_no_margin(ar, &winrct); + if (!BLI_rcti_isect(&winrct, rect_px, NULL)) { + return false; + } + + /* See comment in 'ui_region_contains_point_px' */ + if (ar->v2d.mask.xmin != ar->v2d.mask.xmax) { + const View2D *v2d = &ar->v2d; + rcti rect_region; + ui_window_to_region_rcti(ar, &rect_region, rect_px); + if (!BLI_rcti_isect(&v2d->mask, &rect_region, NULL) || + UI_view2d_rect_in_scrollers(ar, &ar->v2d, rect_px)) { + return false; + } + } + + return true; +} + /** \} */ diff --git a/source/blender/editors/interface/interface_region_color_picker.c b/source/blender/editors/interface/interface_region_color_picker.c index 7ffe572a848..723222d56d1 100644 --- a/source/blender/editors/interface/interface_region_color_picker.c +++ b/source/blender/editors/interface/interface_region_color_picker.c @@ -663,7 +663,8 @@ static void ui_block_colorpicker(uiBlock *block, uiBut *from_but, float rgba[4], UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL); bt->custom_data = cpicker; - /* could use uiItemFullR(col, ptr, prop, -1, 0, UI_ITEM_R_EXPAND|UI_ITEM_R_SLIDER, "", ICON_NONE); + /* Could use: + * uiItemFullR(col, ptr, prop, -1, 0, UI_ITEM_R_EXPAND | UI_ITEM_R_SLIDER, "", ICON_NONE); * but need to use UI_but_func_set for updating other fake buttons */ /* HSV values */ diff --git a/source/blender/editors/interface/interface_region_hud.c b/source/blender/editors/interface/interface_region_hud.c index a1f4b71dc6d..362a1c8a22c 100644 --- a/source/blender/editors/interface/interface_region_hud.c +++ b/source/blender/editors/interface/interface_region_hud.c @@ -193,7 +193,8 @@ static void hud_region_layout(const bContext *C, ARegion *ar) UI_view2d_region_reinit(v2d, V2D_COMMONVIEW_PANELS_UI, ar->winx, ar->winy); - /* Weak, but needed to avoid glitches, especially with hi-dpi (where resizing the view glitches often). + /* Weak, but needed to avoid glitches, especially with hi-dpi + * (where resizing the view glitches often). * Fortunately this only happens occasionally. */ ED_region_panels_layout(C, ar); } @@ -285,6 +286,13 @@ void ED_area_type_hud_ensure(bContext *C, ScrArea *sa) } ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_HUD); + + if (ar && (ar->flag & RGN_FLAG_HIDDEN_BY_USER)) { + /* The region is intentionally hidden by the user, don't show it. */ + hud_region_hide(ar); + return; + } + bool init = false; bool was_hidden = ar == NULL || ar->visible == false; if (!last_redo_poll(C)) { diff --git a/source/blender/editors/interface/interface_region_menu_pie.c b/source/blender/editors/interface/interface_region_menu_pie.c index b115600a80b..dcbbde259f2 100644 --- a/source/blender/editors/interface/interface_region_menu_pie.c +++ b/source/blender/editors/interface/interface_region_menu_pie.c @@ -310,12 +310,14 @@ int UI_pie_menu_invoke_from_rna_enum(struct bContext *C, /** * \name Pie Menu Levels * - * Pie menus can't contain more than 8 items (yet). When using #uiItemsFullEnumO, a "More" button is created that calls + * Pie menus can't contain more than 8 items (yet). + * When using #uiItemsFullEnumO, a "More" button is created that calls * a new pie menu if the enum has too many items. We call this a new "level". * Indirect recursion is used, so that a theoretically unlimited number of items is supported. * - * This is a implementation specifically for operator enums, needed since the object mode pie now has more than 8 - * items. Ideally we'd have some way of handling this for all kinds of pie items, but that's tricky. + * This is a implementation specifically for operator enums, + * needed since the object mode pie now has more than 8 items. + * Ideally we'd have some way of handling this for all kinds of pie items, but that's tricky. * * - Julian (Feb 2016) * diff --git a/source/blender/editors/interface/interface_region_menu_popup.c b/source/blender/editors/interface/interface_region_menu_popup.c index d364bf7e102..b97cbcdfef5 100644 --- a/source/blender/editors/interface/interface_region_menu_popup.c +++ b/source/blender/editors/interface/interface_region_menu_popup.c @@ -279,7 +279,7 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); if (sa && ar) { - if (ar->regiontype == RGN_TYPE_HEADER) { + if (ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER)) { if (ED_area_header_alignment(sa) == RGN_ALIGN_BOTTOM) { UI_block_direction_set(block, UI_DIR_UP); UI_block_order_flip(block); diff --git a/source/blender/editors/interface/interface_region_popover.c b/source/blender/editors/interface/interface_region_popover.c index bbf3df6a264..f149ccd626c 100644 --- a/source/blender/editors/interface/interface_region_popover.c +++ b/source/blender/editors/interface/interface_region_popover.c @@ -187,7 +187,7 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v } /* Prefer popover from header to be positioned into the editor. */ else if (sa && ar) { - if (ar->regiontype == RGN_TYPE_HEADER) { + if (ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER)) { if (ED_area_header_alignment(sa) == RGN_ALIGN_BOTTOM) { UI_block_direction_set(block, UI_DIR_UP | UI_DIR_CENTER_X); } @@ -257,6 +257,8 @@ static void ui_block_free_func_POPOVER(uiPopupBlockHandle *UNUSED(handle), void uiPopupBlockHandle *ui_popover_panel_create( bContext *C, ARegion *butregion, uiBut *but, uiMenuCreateFunc menu_func, void *arg) { + wmWindow *window = CTX_wm_window(C); + /* Create popover, buttons are created from callback. */ uiPopover *pup = MEM_callocN(sizeof(uiPopover), __func__); pup->but = but; @@ -271,7 +273,11 @@ uiPopupBlockHandle *ui_popover_panel_create( pup->menu_arg = arg; #ifdef USE_UI_POPOVER_ONCE - pup->is_once = true; + { + /* Ideally this would be passed in. */ + const wmEvent *event = window->eventstate; + pup->is_once = (event->type == LEFTMOUSE) && (event->val == KM_PRESS); + } #endif /* Create popup block. */ @@ -283,7 +289,6 @@ uiPopupBlockHandle *ui_popover_panel_create( /* Add handlers. If attached to a button, the button will already * add a modal handler and pass on events. */ if (!but) { - wmWindow *window = CTX_wm_window(C); UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); WM_event_add_mousemove(C); handle->popup = true; diff --git a/source/blender/editors/interface/interface_region_popup.c b/source/blender/editors/interface/interface_region_popup.c index 11b2e069d6c..c4bcd7074d8 100644 --- a/source/blender/editors/interface/interface_region_popup.c +++ b/source/blender/editors/interface/interface_region_popup.c @@ -236,10 +236,13 @@ static void ui_popup_block_position(wmWindow *window, } /* Compute offset based on direction. */ - int offset_x = 0, offset_y = 0; + float offset_x = 0, offset_y = 0; + + /* Ensure buttons don't come between the parent button and the popup, see: T63566. */ + const float offset_overlap = max_ff(U.pixelsize, 1.0f); if (dir1 == UI_DIR_LEFT) { - offset_x = butrct.xmin - block->rect.xmax; + offset_x = (butrct.xmin - block->rect.xmax) + offset_overlap; if (dir2 == UI_DIR_UP) { offset_y = butrct.ymin - block->rect.ymin - center_y - UI_MENU_PADDING; } @@ -248,7 +251,7 @@ static void ui_popup_block_position(wmWindow *window, } } else if (dir1 == UI_DIR_RIGHT) { - offset_x = butrct.xmax - block->rect.xmin; + offset_x = (butrct.xmax - block->rect.xmin) - offset_overlap; if (dir2 == UI_DIR_UP) { offset_y = butrct.ymin - block->rect.ymin - center_y - UI_MENU_PADDING; } @@ -257,7 +260,7 @@ static void ui_popup_block_position(wmWindow *window, } } else if (dir1 == UI_DIR_UP) { - offset_y = butrct.ymax - block->rect.ymin; + offset_y = (butrct.ymax - block->rect.ymin) - offset_overlap; if (dir2 == UI_DIR_RIGHT) { offset_x = butrct.xmax - block->rect.xmax + center_x; } @@ -271,7 +274,7 @@ static void ui_popup_block_position(wmWindow *window, } } else if (dir1 == UI_DIR_DOWN) { - offset_y = butrct.ymin - block->rect.ymax; + offset_y = (butrct.ymin - block->rect.ymax) + offset_overlap; if (dir2 == UI_DIR_RIGHT) { offset_x = butrct.xmax - block->rect.xmax + center_x; } diff --git a/source/blender/editors/interface/interface_region_search.c b/source/blender/editors/interface/interface_region_search.c index c37775febda..251bc86a3f5 100644 --- a/source/blender/editors/interface/interface_region_search.c +++ b/source/blender/editors/interface/interface_region_search.c @@ -539,9 +539,10 @@ ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiBut *but data->prv_cols = but->a2; } - /* Only show key shortcuts when needed (checking RNA prop pointer is useless here, a lot of buttons are about data - * without having that pointer defined, let's rather try with optype!). One can also enforce that behavior by - * setting UI_BUT_HAS_SHORTCUT drawflag of search button. */ + /* Only show key shortcuts when needed (checking RNA prop pointer is useless here, a lot of + * buttons are about data without having that pointer defined, let's rather try with optype!). + * One can also enforce that behavior by setting + * UI_BUT_HAS_SHORTCUT drawflag of search button. */ if (but->optype != NULL || (but->drawflag & UI_BUT_HAS_SHORTCUT) != 0) { data->use_sep = true; } @@ -597,7 +598,7 @@ ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiBut *but winx = WM_window_pixels_x(win); // winy = WM_window_pixels_y(win); /* UNUSED */ - //wm_window_get_size(win, &winx, &winy); + // wm_window_get_size(win, &winx, &winy); if (rect_i.xmax > winx) { /* super size */ diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index c8029a2b21a..4a9c7b689c1 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -26,7 +26,8 @@ /* TODO(campbell): * We may want to have a higher level API that initializes a timer, * checks for mouse motion and clears the tool-tip afterwards. - * We never want multiple tool-tips at once so this could be handled on the window / window-manager level. + * We never want multiple tool-tips at once + * so this could be handled on the window / window-manager level. * * For now it's not a priority, so leave as-is. */ @@ -461,7 +462,8 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is * * - Direct access to the tool (as if the toolbar button is pressed). * - The key is bound to a brush type (not the exact brush name). - * - The key is assigned to the operator it's self (bypassing the tool, executing the operator). + * - The key is assigned to the operator it's self + * (bypassing the tool, executing the operator). * * Either way case it's useful to show the shortcut. */ @@ -1061,7 +1063,7 @@ static ARegion *ui_tooltip_create_with_data(bContext *C, field->geom.x_pos = x_pos; } - //fontw *= aspect; + // fontw *= aspect; BLF_disable(data->fstyle.uifont_id, font_flag); BLF_disable(blf_mono_font, font_flag); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 6666991ad26..e96141eaa05 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -127,11 +127,8 @@ static void template_add_button_search_menu(const bContext *C, if (use_previews) { ARegion *region = CTX_wm_region(C); - ScrArea *area = CTX_wm_area(C); - /* XXX ugly top-bar exception */ - const bool use_big_size = ( - /* silly check, could be more generic */ - (region->regiontype != RGN_TYPE_HEADER) && (area->spacetype != SPACE_TOPBAR)); + /* Ugly tool header exception. */ + const bool use_big_size = (region->regiontype != RGN_TYPE_TOOL_HEADER); /* Ugly exception for screens here, * drawing their preview in icon size looks ugly/useless */ const bool use_preview_icon = use_big_size || (id && (GS(id->name) != ID_SCR)); @@ -801,7 +798,7 @@ static void template_ID(bContext *C, char name[UI_MAX_NAME_STR]; const bool user_alert = (id->us <= 0); - //text_idbutton(id, name); + // text_idbutton(id, name); name[0] = '\0'; but = uiDefButR(block, UI_BTYPE_TEXT, @@ -1371,10 +1368,12 @@ void uiTemplateIDTabs(uiLayout *layout, /************************ ID Chooser Template ***************************/ /** - * This is for selecting the type of ID-block to use, and then from the relevant type choosing the block to use + * This is for selecting the type of ID-block to use, + * and then from the relevant type choosing the block to use. * - * - propname: property identifier for property that ID-pointer gets stored to - * - proptypename: property identifier for property used to determine the type of ID-pointer that can be used + * \param propname: property identifier for property that ID-pointer gets stored to. + * \param proptypename: property identifier for property + * used to determine the type of ID-pointer that can be used. */ void uiTemplateAnyID(uiLayout *layout, PointerRNA *ptr, @@ -2354,8 +2353,14 @@ void uiTemplateOperatorRedoProperties(uiLayout *layout, const bContext *C) /* Disable for now, doesn't fit well in popover. */ #if 0 /* Repeat button with operator name as text. */ - uiItemFullO(layout, "SCREEN_OT_repeat_last", RNA_struct_ui_name(op->type->srna), - ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0, NULL); + uiItemFullO(layout, + "SCREEN_OT_repeat_last", + RNA_struct_ui_name(op->type->srna), + ICON_NONE, + NULL, + WM_OP_INVOKE_DEFAULT, + 0, + NULL); #endif if (WM_operator_repeat_check(C, op)) { @@ -4277,7 +4282,7 @@ static void curvemap_buttons_layout(uiLayout *layout, UI_block_funcN_set(block, rna_update_cb, MEM_dupallocN(cb), NULL); /* curve itself */ - size = uiLayoutGetWidth(layout); + size = max_ii(uiLayoutGetWidth(layout), UI_UNIT_X); row = uiLayoutRow(layout, false); uiDefBut( block, UI_BTYPE_CURVE, 0, "", 0, 0, size, 8.0f * UI_UNIT_X, cumap, 0.0f, 1.0f, bg, 0, ""); @@ -4801,9 +4806,9 @@ void uiTemplateLayers(uiLayout *layout, /* the number of layers determines the way we group them * - we want 2 rows only (for now) - * - the number of columns (cols) is the total number of buttons per row - * the 'remainder' is added to this, as it will be ok to have first row slightly wider if need be - * - for now, only split into groups if group will have at least 5 items + * - The number of columns (cols) is the total number of buttons per row the 'remainder' + * is added to this, as it will be ok to have first row slightly wider if need be. + * - For now, only split into groups if group will have at least 5 items. */ layers = RNA_property_array_length(ptr, prop); cols = (layers / 2) + (layers % 2); @@ -4992,7 +4997,7 @@ static void uilist_filter_items_default(struct uiList *ui_list, dyn_data->items_shown++; do_order = order_by_name; } - //printf("%s: '%s' matches '%s'\n", __func__, name, filter); + // printf("%s: '%s' matches '%s'\n", __func__, name, filter); } else if (filter_exclude) { dyn_data->items_shown++; @@ -5316,16 +5321,16 @@ void uiTemplateList(uiLayout *layout, dyn_data->items_len = dyn_data->items_shown = RNA_property_collection_length(dataptr, prop); } else { - //printf("%s: filtering...\n", __func__); + // printf("%s: filtering...\n", __func__); filter_items(ui_list, C, dataptr, propname); - //printf("%s: filtering done.\n", __func__); + // printf("%s: filtering done.\n", __func__); } items_shown = dyn_data->items_shown; if (items_shown >= 0) { bool activei_mapping_pending = true; items_ptr = MEM_mallocN(sizeof(_uilist_item) * items_shown, __func__); - //printf("%s: items shown: %d.\n", __func__, items_shown); + // printf("%s: items shown: %d.\n", __func__, items_shown); RNA_PROP_BEGIN (dataptr, itemptr, prop) { if (!dyn_data->items_filter_flags || ((dyn_data->items_filter_flags[i] & UILST_FLT_ITEM) ^ filter_exclude)) { @@ -5337,7 +5342,7 @@ void uiTemplateList(uiLayout *layout, else { ii = order_reverse ? items_shown - ++idx : idx++; } - //printf("%s: ii: %d\n", __func__, ii); + // printf("%s: ii: %d\n", __func__, ii); items_ptr[ii].item = itemptr; items_ptr[ii].org_idx = i; items_ptr[ii].flt_flag = dyn_data->items_filter_flags ? dyn_data->items_filter_flags[i] : @@ -5624,14 +5629,17 @@ void uiTemplateList(uiLayout *layout, if (glob) { /* About UI_BTYPE_GRIP drag-resize: - * We can't directly use results from a grip button, since we have a rather complex behavior here - * (sizing by discrete steps and, overall, autosize feature). - * Since we *never* know whether we are grip-resizing or not (because there is no callback for when a - * button enters/leaves its "edit mode"), we use the fact that grip-controlled value (dyn_data->resize) - * is completely handled by the grip during the grab resize, so settings its value here has no effect - * at all. - * It is only meaningful when we are not resizing, in which case this gives us the correct "init drag" value. - * Note we cannot affect dyn_data->resize_prev here, since this value is not controlled by the grip! + * We can't directly use results from a grip button, since we have a + * rather complex behavior here (sizing by discrete steps and, overall, autosize feature). + * Since we *never* know whether we are grip-resizing or not + * (because there is no callback for when a button enters/leaves its "edit mode"), + * we use the fact that grip-controlled value (dyn_data->resize) is completely handled + * by the grip during the grab resize, so settings its value here has no effect at all. + * + * It is only meaningful when we are not resizing, + * in which case this gives us the correct "init drag" value. + * Note we cannot affect dyn_data->resize_prev here, + * since this value is not controlled by the grip! */ dyn_data->resize = dyn_data->resize_prev + (dyn_data->visual_height - ui_list->list_grip) * UI_UNIT_Y; @@ -5874,7 +5882,8 @@ static bool ui_layout_operator_buts_poll_property(struct PointerRNA *UNUSED(ptr) /** * Draw Operator property buttons for redoing execution with different settings. - * This function does not initialize the layout, functions can be called on the layout before and after. + * This function does not initialize the layout, + * functions can be called on the layout before and after. */ eAutoPropButsReturn uiTemplateOperatorPropertyButs(const bContext *C, uiLayout *layout, @@ -5890,8 +5899,8 @@ eAutoPropButsReturn uiTemplateOperatorPropertyButs(const bContext *C, op->properties = IDP_New(IDP_GROUP, &val, "wmOperatorProperties"); } - /* poll() on this operator may still fail, at the moment there is no nice feedback when this happens - * just fails silently */ + /* poll() on this operator may still fail, + * at the moment there is no nice feedback when this happens just fails silently. */ if (!WM_operator_repeat_check(C, op)) { UI_block_lock_set(block, true, "Operator can't' redo"); return return_info; @@ -6702,17 +6711,18 @@ void uiTemplateCacheFile(uiLayout *layout, bContext *C, PointerRNA *ptr, const c uiItemR(row, &fileptr, "override_frame", 0, "Override Frame", ICON_NONE); row = uiLayoutRow(layout, false); - uiLayoutSetEnabled(row, RNA_boolean_get(&fileptr, "override_frame")); + uiLayoutSetActive(row, RNA_boolean_get(&fileptr, "override_frame")); uiItemR(row, &fileptr, "frame", 0, "Frame", ICON_NONE); row = uiLayoutRow(layout, false); uiItemR(row, &fileptr, "frame_offset", 0, "Frame Offset", ICON_NONE); + uiLayoutSetActive(row, !RNA_boolean_get(&fileptr, "is_sequence")); row = uiLayoutRow(layout, false); uiItemL(row, IFACE_("Manual Transform:"), ICON_NONE); row = uiLayoutRow(layout, false); - uiLayoutSetEnabled(row, (sbuts->mainb == BCONTEXT_CONSTRAINT)); + uiLayoutSetActive(row, (sbuts->mainb == BCONTEXT_CONSTRAINT)); uiItemR(row, &fileptr, "scale", 0, "Scale", ICON_NONE); /* TODO: unused for now, so no need to expose. */ diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 9920d4f1fa5..bf52cc625c2 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -508,7 +508,8 @@ int UI_icon_from_report_type(int type) /********************************** Misc **************************************/ /** - * Returns the best "UI" precision for given floating value, so that e.g. 10.000001 rather gets drawn as '10'... + * Returns the best "UI" precision for given floating value, + * so that e.g. 10.000001 rather gets drawn as '10'... */ int UI_calc_float_precision(int prec, double value) { @@ -519,7 +520,8 @@ int UI_calc_float_precision(int prec, double value) BLI_assert(prec <= UI_PRECISION_FLOAT_MAX); BLI_assert(fabs(pow10_neg[prec] - pow(10, -prec)) < 1e-16); - /* check on the number of decimal places need to display the number, this is so 0.00001 is not displayed as 0.00, + /* Check on the number of decimal places need to display the number, + * this is so 0.00001 is not displayed as 0.00, * _but_, this is only for small values si 10.0001 will not get the same treatment. */ value = ABS(value); @@ -631,8 +633,10 @@ uiButStore *UI_butstore_create(uiBlock *block) void UI_butstore_free(uiBlock *block, uiButStore *bs_handle) { /* Workaround for button store being moved into new block, - * which then can't use the previous buttons state ('ui_but_update_from_old_block' fails to find a match), - * keeping the active button in the old block holding a reference to the button-state in the new block: see T49034. + * which then can't use the previous buttons state + * ('ui_but_update_from_old_block' fails to find a match), + * keeping the active button in the old block holding a reference + * to the button-state in the new block: see T49034. * * Ideally we would manage moving the 'uiButStore', keeping a correct state. * All things considered this is the most straightforward fix - Campbell. diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index e18a2e6068a..a9cd2f9cee1 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -1604,9 +1604,14 @@ static void ui_text_clip_right_ex(const uiFontStyle *fstyle, /** * Cut off the middle of the text to fit into the given width. - * Note in case this middle clipping would just remove a few chars, it rather clips right, which is more readable. - * If rpart_sep is not Null, the part of str starting to first occurrence of rpart_sep is preserved at all cost (useful - * for strings with shortcuts, like 'AVeryLongFooBarLabelForMenuEntry|Ctrl O' -> 'AVeryLong...MenuEntry|Ctrl O'). + * + * \note in case this middle clipping would just remove a few chars, + * it rather clips right, which is more readable. + * + * If rpart_sep is not Null, the part of str starting to first occurrence of rpart_sep + * is preserved at all cost. + * Useful for strings with shortcuts + * (like 'AVeryLongFooBarLabelForMenuEntry|Ctrl O' -> 'AVeryLong...MenuEntry|Ctrl O'). */ float UI_text_clip_middle_ex(const uiFontStyle *fstyle, char *str, @@ -1691,8 +1696,8 @@ float UI_text_clip_middle_ex(const uiFontStyle *fstyle, r_len = strlen(str + r_offset) + 1; /* +1 for the trailing '\0'. */ if (l_end + sep_len + r_len + rpart_len > max_len) { - /* Corner case, the str already takes all available mem, and the ellipsis chars would actually - * add more chars... + /* Corner case, the str already takes all available mem, + * and the ellipsis chars would actually add more chars. * Better to just trim one or two letters to the right in this case... * Note: with a single-char ellipsis, this should never happen! But better be safe here... */ @@ -1753,8 +1758,10 @@ static void ui_text_clip_middle(const uiFontStyle *fstyle, uiBut *but, const rct } /** - * Like ui_text_clip_middle(), but protect/preserve at all cost the right part of the string after sep. - * Useful for strings with shortcuts (like 'AVeryLongFooBarLabelForMenuEntry|Ctrl O' -> 'AVeryLong...MenuEntry|Ctrl O'). + * Like #ui_text_clip_middle(), but protect/preserve at all cost + * the right part of the string after sep. + * Useful for strings with shortcuts + * (like 'AVeryLongFooBarLabelForMenuEntry|Ctrl O' -> 'AVeryLong...MenuEntry|Ctrl O'). */ static void ui_text_clip_middle_protect_right(const uiFontStyle *fstyle, uiBut *but, @@ -2780,8 +2787,8 @@ static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int dir /* menu is 2nd level or deeper */ if (flag & UI_BLOCK_POPUP) { - //rect->ymin -= 4.0; - //rect->ymax += 4.0; + // rect->ymin -= 4.0; + // rect->ymax += 4.0; } else if (direction == UI_DIR_DOWN) { roundboxalign = (UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT); @@ -4111,7 +4118,7 @@ static void widget_tab(uiWidgetColors *wcol, rcti *rect, int state, int roundbox const bool is_active = (state & UI_SELECT); /* Draw shaded outline - Disabled for now, - * seems incorrect and also looks nicer without it imho ;) */ + * seems incorrect and also looks nicer without it imho ;) */ //#define USE_TAB_SHADED_HIGHLIGHT uiWidgetBase wtb; @@ -4679,7 +4686,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct } if (wt) { - //rcti disablerect = *rect; /* rect gets clipped smaller for text */ + // rcti disablerect = *rect; /* rect gets clipped smaller for text */ int roundboxalign, state, drawflag; bool disabled = false; diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index fa56dc04143..587cccf516c 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -366,6 +366,10 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid) case TH_OUTLINE_WIDTH: cp = &ts->outline_width; break; + case TH_OBCENTER_DIA: + cp = &ts->obcenter_dia; + break; + break; case TH_EDGE: cp = ts->edge; break; diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index fa56721c11f..58d26c4a840 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -31,12 +31,14 @@ #include "DNA_scene_types.h" #include "DNA_userdef_types.h" +#include "BLI_array.h" #include "BLI_utildefines.h" #include "BLI_link_utils.h" #include "BLI_rect.h" #include "BLI_math.h" #include "BLI_memarena.h" #include "BLI_timecode.h" +#include "BLI_string.h" #include "BKE_context.h" #include "BKE_screen.h" @@ -212,11 +214,14 @@ static void view2d_masks(View2D *v2d, bool check_scrollers, const rcti *mask_scr /* Refresh and Validation */ /** - * Initialize all relevant View2D data (including view rects if first time) and/or refresh mask sizes after view resize - * - for some of these presets, it is expected that the region will have defined some + * Initialize all relevant View2D data (including view rects if first time) + * and/or refresh mask sizes after view resize. + * + * - For some of these presets, it is expected that the region will have defined some * additional settings necessary for the customization of the 2D viewport to its requirements - * - this function should only be called from region init() callbacks, where it is expected that - * this is called before UI_view2d_size_update(), as this one checks that the rects are properly initialized. + * - This function should only be called from region init() callbacks, where it is expected that + * this is called before #UI_view2d_size_update(), + * as this one checks that the rects are properly initialized. */ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) { @@ -238,7 +243,8 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) v2d->minzoom = 0.01f; v2d->maxzoom = 1000.0f; - /* tot rect and cur should be same size, and aligned using 'standard' OpenGL coordinates for now + /* View2D tot rect and cur should be same size, + * and aligned using 'standard' OpenGL coordinates for now: * - region can resize 'tot' later to fit other data * - keeptot is only within bounds, as strict locking is not that critical * - view is aligned for (0,0) -> (winx-1, winy-1) setup @@ -271,8 +277,9 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) /* scroller settings are currently not set here... that is left for regions... */ break; } - /* 'stack view' - practically the same as list/channel view, except is located in the pos y half instead. - * zoom, aspect ratio, and alignment restrictions are set here */ + /* 'stack view' - practically the same as list/channel view, + * except is located in the pos y half instead. + * Zoom, aspect ratio, and alignment restrictions are set here. */ case V2D_COMMONVIEW_STACK: { /* zoom + aspect ratio are locked */ v2d->keepzoom = (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y | V2D_LIMITZOOM | V2D_KEEPASPECT); @@ -545,10 +552,12 @@ static void ui_view2d_curRect_validate_resize(View2D *v2d, bool resize, bool mas if (do_cur) { if ((v2d->keeptot == V2D_KEEPTOT_STRICT) && (winx != v2d->oldwinx)) { - /* special exception for Outliner (and later channel-lists): - * - The view may be moved left to avoid contents being pushed out of view when view shrinks. - * - The keeptot code will make sure cur->xmin will not be less than tot->xmin (which cannot be allowed) - * - width is not adjusted for changed ratios here... + /* Special exception for Outliner (and later channel-lists): + * - The view may be moved left to avoid contents + * being pushed out of view when view shrinks. + * - The keeptot code will make sure cur->xmin will not be less than tot->xmin + * (which cannot be allowed). + * - width is not adjusted for changed ratios here. */ if (winx < v2d->oldwinx) { float temp = v2d->oldwinx - winx; @@ -906,8 +915,9 @@ void UI_view2d_sync(bScreen *screen, ScrArea *area, View2D *v2dcur, int flag) } /** - * Restore 'cur' rect to standard orientation (i.e. optimal maximum view of tot) - * This does not take into account if zooming the view on an axis will improve the view (if allowed) + * Restore 'cur' rect to standard orientation (i.e. optimal maximum view of tot). + * This does not take into account if zooming the view on an axis + * will improve the view (if allowed). */ void UI_view2d_curRect_reset(View2D *v2d) { @@ -1109,7 +1119,7 @@ void UI_view2d_zoom_cache_reset(void) /* View Matrix Setup */ /* mapping function to ensure 'cur' draws extended over the area where sliders are */ -static void view2d_map_cur_using_mask(View2D *v2d, rctf *r_curmasked) +static void view2d_map_cur_using_mask(const View2D *v2d, rctf *r_curmasked) { *r_curmasked = v2d->cur; @@ -1141,7 +1151,7 @@ static void view2d_map_cur_using_mask(View2D *v2d, rctf *r_curmasked) } /* Set view matrices to use 'cur' rect as viewing frame for View2D drawing */ -void UI_view2d_view_ortho(View2D *v2d) +void UI_view2d_view_ortho(const View2D *v2d) { rctf curmasked; const int sizex = BLI_rcti_size_x(&v2d->mask); @@ -1149,8 +1159,9 @@ void UI_view2d_view_ortho(View2D *v2d) const float eps = 0.001f; float xofs = 0.0f, yofs = 0.0f; - /* pixel offsets (-GLA_PIXEL_OFS) are needed to get 1:1 correspondence with pixels for smooth UI drawing, - * but only applied where requested + /* Pixel offsets (-GLA_PIXEL_OFS) are needed to get 1:1 + * correspondence with pixels for smooth UI drawing, + * but only applied where requested. */ /* XXX brecht: instead of zero at least use a tiny offset, otherwise * pixel rounding is effectively random due to float inaccuracy */ @@ -1184,15 +1195,17 @@ void UI_view2d_view_ortho(View2D *v2d) /** * Set view matrices to only use one axis of 'cur' only * - * \param xaxis: if non-zero, only use cur x-axis, otherwise use cur-yaxis (mostly this will be used for x) + * \param xaxis: if non-zero, only use cur x-axis, + * otherwise use cur-yaxis (mostly this will be used for x). */ void UI_view2d_view_orthoSpecial(ARegion *ar, View2D *v2d, const bool xaxis) { rctf curmasked; float xofs, yofs; - /* pixel offsets (-GLA_PIXEL_OFS) are needed to get 1:1 correspondence with pixels for smooth UI drawing, - * but only applied where requested + /* Pixel offsets (-GLA_PIXEL_OFS) are needed to get 1:1 + * correspondence with pixels for smooth UI drawing, + * but only applied where requested. */ /* XXX temp (ton) */ xofs = 0.0f; // (v2d->flag & V2D_PIXELOFS_X) ? GLA_PIXEL_OFS : 0.0f; @@ -1227,338 +1240,6 @@ void UI_view2d_view_restore(const bContext *C) /* *********************************************************************** */ /* Gridlines */ -/* View2DGrid is typedef'd in UI_view2d.h */ -struct View2DGrid { - float dx, dy; /* stepsize (in pixels) between gridlines */ - float startx, starty; /* initial coordinates to start drawing grid from */ - int powerx, powery; /* step as power of 10 */ -}; - -/* --------------- */ - -/* try to write step as a power of 10 */ -static void step_to_grid(float *step, const int unit, int *r_power) -{ - const float loga = (float)log10(*step); - float rem; - - int power = (int)(loga); - - rem = loga - power; - rem = (float)pow(10.0, rem); - - if (loga < 0.0f) { - if (rem < 0.2f) { - rem = 0.2f; - } - else if (rem < 0.5f) { - rem = 0.5f; - } - else { - rem = 1.0f; - } - - *step = rem * (float)pow(10.0, power); - - /* for frames, we want 1.0 frame intervals only */ - if (unit == V2D_UNIT_FRAMES) { - rem = 1.0f; - /* use 2 since there are grid lines drawn in between, - * this way to get 1 line per frame */ - *step = 2.0f; - } - - /* prevents printing 1.0 2.0 3.0 etc */ - if (rem == 1.0f) { - power++; - } - } - else { - if (rem < 2.0f) { - rem = 2.0f; - } - else if (rem < 5.0f) { - rem = 5.0f; - } - else { - rem = 10.0f; - } - - *step = rem * (float)pow(10.0, power); - - power++; - /* prevents printing 1.0, 2.0, 3.0, etc. */ - if (rem == 10.0f) { - power++; - } - } - - *r_power = power; -} - -/** - * Initialize settings necessary for drawing gridlines in a 2d-view - * - * - Currently, will return pointer to View2DGrid struct that needs to - * be freed with UI_view2d_grid_free() - * - Is used for scrollbar drawing too (for units drawing) - * - Units + clamping args will be checked, to make sure they are valid values that can be used - * so it is very possible that we won't return grid at all! - * - * - xunits,yunits = V2D_UNIT_* grid steps in seconds or frames - * - xclamp,yclamp = V2D_CLAMP_* only show whole-number intervals - * - winx = width of region we're drawing to, note: not used but keeping for completeness. - * - winy = height of region we're drawing into - */ -View2DGrid *UI_view2d_grid_calc(Scene *scene, - View2D *v2d, - short xunits, - short xclamp, - short yunits, - short yclamp, - int UNUSED(winx), - int winy) -{ - - View2DGrid *grid; - float space, seconddiv; - - /* check that there are at least some workable args */ - if (ELEM(V2D_ARG_DUMMY, xunits, xclamp) && ELEM(V2D_ARG_DUMMY, yunits, yclamp)) { - return NULL; - } - - /* grid here is allocated... */ - grid = MEM_callocN(sizeof(View2DGrid), "View2DGrid"); - - /* rule: gridstep is minimal GRIDSTEP pixels */ - if (xunits == V2D_UNIT_SECONDS) { - seconddiv = (float)(0.01 * FPS); - } - else { - seconddiv = 1.0f; - } - - /* calculate x-axis grid scale (only if both args are valid) */ - if (ELEM(V2D_ARG_DUMMY, xunits, xclamp) == 0) { - space = BLI_rctf_size_x(&v2d->cur); - - if (space != 0.0f) { - const float pixels = (float)BLI_rcti_size_x(&v2d->mask); - if (pixels != 0.0f) { - grid->dx = (U.v2d_min_gridsize * UI_DPI_FAC * space) / (seconddiv * pixels); - step_to_grid(&grid->dx, xunits, &grid->powerx); - grid->dx *= seconddiv; - } - } - - if (xclamp == V2D_GRID_CLAMP) { - CLAMP_MIN(grid->dx, 0.1f); - CLAMP_MIN(grid->powerx, 0); - grid->powerx -= 2; - } - } - - /* calculate y-axis grid scale (only if both args are valid) */ - if (ELEM(V2D_ARG_DUMMY, yunits, yclamp) == 0) { - space = BLI_rctf_size_y(&v2d->cur); - if (space != 0.0f) { - const float pixels = (float)winy; - if (pixels != 0.0f) { - grid->dy = U.v2d_min_gridsize * UI_DPI_FAC * space / pixels; - step_to_grid(&grid->dy, yunits, &grid->powery); - } - } - - if (yclamp == V2D_GRID_CLAMP) { - CLAMP_MIN(grid->dy, 1.0f); - CLAMP_MIN(grid->powery, 1); - } - } - - /* calculate start position */ - if (ELEM(V2D_ARG_DUMMY, xunits, xclamp) == 0) { - grid->startx = seconddiv * (v2d->cur.xmin / seconddiv - - (float)fmod(v2d->cur.xmin / seconddiv, grid->dx / seconddiv)); - if (v2d->cur.xmin < 0.0f) { - grid->startx -= grid->dx; - } - } - else { - grid->startx = v2d->cur.xmin; - } - - if (ELEM(V2D_ARG_DUMMY, yunits, yclamp) == 0) { - grid->starty = (v2d->cur.ymin - (float)fmod(v2d->cur.ymin, grid->dy)); - if (v2d->cur.ymin < 0.0f) { - grid->starty -= grid->dy; - } - } - else { - grid->starty = v2d->cur.ymin; - } - - return grid; -} - -/* Draw gridlines in the given 2d-region */ -void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag) -{ - float vec1[2], vec2[2]; - int a, step; - int vertical_minor_step = (BLI_rcti_size_x(&v2d->mask) + 1) / (U.v2d_min_gridsize * UI_DPI_FAC); - int horizontal_major_step = (BLI_rcti_size_y(&v2d->mask) + 1) / - (U.v2d_min_gridsize * UI_DPI_FAC); - uchar grid_line_color[3]; - - /* check for grid first, as it may not exist */ - if (grid == NULL) { - return; - } - - /* Count the needed vertices for the gridlines */ - unsigned vertex_count = 0; - if (flag & V2D_VERTICAL_LINES) { - /* vertical lines */ - vertex_count += 2 * vertical_minor_step; /* minor gridlines */ - vertex_count += 2 * (vertical_minor_step + 2); /* major gridlines */ - } - if (flag & V2D_HORIZONTAL_LINES) { - /* horizontal lines */ - vertex_count += 2 * (horizontal_major_step + 1); /* major gridlines */ - - /* fine lines */ - if (flag & V2D_HORIZONTAL_FINELINES) { - vertex_count += 2 * (horizontal_major_step + 1); - } - } - /* axes */ - if (flag & V2D_HORIZONTAL_AXIS) { - vertex_count += 2; - } - if (flag & V2D_VERTICAL_AXIS) { - vertex_count += 2; - } - - /* If there is nothing to render, exit early */ - if (vertex_count == 0) { - return; - } - - GPUVertFormat *format = immVertexFormat(); - uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - uint color = GPU_vertformat_attr_add( - format, "color", GPU_COMP_U8, 3, GPU_FETCH_INT_TO_FLOAT_UNIT); - - immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); - immBegin(GPU_PRIM_LINES, vertex_count); - - /* vertical lines */ - if (flag & V2D_VERTICAL_LINES) { - /* initialize initial settings */ - vec1[0] = vec2[0] = grid->startx; - vec1[1] = grid->starty; - vec2[1] = v2d->cur.ymax; - - /* minor gridlines */ - step = vertical_minor_step; - if (step != 0) { - UI_GetThemeColor3ubv(TH_GRID, grid_line_color); - - for (a = 0; a < step; a++) { - immAttrSkip(color); - immVertex2fv(pos, vec1); - immAttr3ubv(color, grid_line_color); - immVertex2fv(pos, vec2); - - vec2[0] = vec1[0] += grid->dx; - } - } - - /* major gridlines */ - vec2[0] = vec1[0] -= 0.5f * grid->dx; - - UI_GetThemeColorShade3ubv(TH_GRID, 16, grid_line_color); - - step++; - for (a = 0; a <= step; a++) { - immAttrSkip(color); - immVertex2fv(pos, vec1); - immAttr3ubv(color, grid_line_color); - immVertex2fv(pos, vec2); - - vec2[0] = vec1[0] -= grid->dx; - } - } - - /* horizontal lines */ - if (flag & V2D_HORIZONTAL_LINES) { - /* only major gridlines */ - vec1[1] = vec2[1] = grid->starty; - vec1[0] = grid->startx; - vec2[0] = v2d->cur.xmax; - - step = horizontal_major_step; - - UI_GetThemeColor3ubv(TH_GRID, grid_line_color); - - for (a = 0; a <= step; a++) { - immAttrSkip(color); - immVertex2fv(pos, vec1); - immAttr3ubv(color, grid_line_color); - immVertex2fv(pos, vec2); - - vec2[1] = vec1[1] += grid->dy; - } - - /* fine grid lines */ - vec2[1] = vec1[1] -= 0.5f * grid->dy; - step++; - - if (flag & V2D_HORIZONTAL_FINELINES) { - UI_GetThemeColorShade3ubv(TH_GRID, 16, grid_line_color); - for (a = 0; a < step; a++) { - immAttrSkip(color); - immVertex2fv(pos, vec1); - immAttr3ubv(color, grid_line_color); - immVertex2fv(pos, vec2); - - vec2[1] = vec1[1] -= grid->dy; - } - } - } - - /* Axes are drawn as darker lines */ - UI_GetThemeColorShade3ubv(TH_GRID, -50, grid_line_color); - - /* horizontal axis */ - if (flag & V2D_HORIZONTAL_AXIS) { - vec1[0] = v2d->cur.xmin; - vec2[0] = v2d->cur.xmax; - vec1[1] = vec2[1] = 0.0f; - - immAttrSkip(color); - immVertex2fv(pos, vec1); - immAttr3ubv(color, grid_line_color); - immVertex2fv(pos, vec2); - } - - /* vertical axis */ - if (flag & V2D_VERTICAL_AXIS) { - vec1[1] = v2d->cur.ymin; - vec2[1] = v2d->cur.ymax; - vec1[0] = vec2[0] = 0.0f; - - immAttrSkip(color); - immVertex2fv(pos, vec1); - immAttr3ubv(color, grid_line_color); - immVertex2fv(pos, vec2); - } - - immEnd(); - immUnbindProgram(); -} - /* Draw a constant grid in given 2d-region */ void UI_view2d_constant_grid_draw(View2D *v2d, float step) { @@ -1716,135 +1397,6 @@ void UI_view2d_multi_grid_draw(View2D *v2d, int colorid, float step, int level_s immUnbindProgram(); } -static void get_scale_indicator_text( - const Scene *scene, float value, int brevity_level, short unit, uint max_length, char *r_str) -{ - if (unit == V2D_UNIT_SECONDS) { - BLI_timecode_string_from_time( - r_str, max_length, brevity_level, value / (float)FPS, FPS, U.timecode_style); - } - else { - BLI_timecode_string_from_time_seconds(r_str, max_length, brevity_level, value); - } -} - -void UI_view2d_grid_draw_numbers_horizontal(const Scene *scene, - const View2D *v2d, - const View2DGrid *grid, - const rcti *rect, - int unit, - bool whole_numbers_only) -{ - BLI_assert(grid); - float xstep = grid->dx * UI_view2d_scale_get_x(v2d); - if (xstep <= 0.0f) { - return; - } - - float initial_xpos = UI_view2d_view_to_region_x(v2d, grid->startx); - float ypos = (float)rect->ymin + 2 * UI_DPI_FAC; - float initial_value = grid->startx; - float value_step = grid->dx; - int brevity_level = grid->powerx; - - /* Make sure that the value_step is >= 1 when only whole numbers are displayed. - * Otherwise the same number could be displayed more than once. */ - if (whole_numbers_only) { - while (value_step < 0.9999f) { - xstep *= 2.0f; - value_step *= 2.0f; - } - } - - /* Skip first few steps if they don't intersect - * the rectangle that will contain the numbers. */ - while (initial_xpos < rect->xmin) { - initial_xpos += xstep; - initial_value += value_step; - } - - if (unit == V2D_UNIT_FRAMES) { - brevity_level = 1; - } - - const int font_id = BLF_default(); - UI_FontThemeColor(font_id, TH_TEXT); - - BLF_batch_draw_begin(); - - for (float xpos = initial_xpos, value = initial_value; xpos < rect->xmax; - xpos += xstep, value += value_step) { - char text[32]; - get_scale_indicator_text(scene, value, brevity_level, unit, sizeof(text), text); - float text_width = BLF_width(font_id, text, strlen(text)); - BLF_draw_default_ascii(xpos - text_width / 2.0f, ypos, 0.0f, text, sizeof(text)); - } - - BLF_batch_draw_end(); -} - -void UI_view2d_grid_draw_numbers_vertical(const Scene *scene, - const View2D *v2d, - const View2DGrid *grid, - const rcti *rect, - int unit, - float text_offset) -{ - BLI_assert(grid); - float ystep = grid->dy * UI_view2d_scale_get_y(v2d); - if (ystep <= 0.0f) { - return; - } - - const int font_id = BLF_default(); - UI_FontThemeColor(font_id, TH_TEXT); - - BLF_enable(font_id, BLF_ROTATION); - BLF_rotation(font_id, M_PI_2); - - float initial_value = grid->starty; - float value_step = grid->dy; - float xpos = rect->xmax - 2.0f * UI_DPI_FAC; - float initial_ypos = UI_view2d_view_to_region_y(v2d, grid->starty); - - /* Currently only used by the sequencer to display - * channel numbers in the center. */ - initial_ypos += text_offset * ystep; - - /* Skip first few steps if they don't intersect - * the rectangle that will contain the numbers. */ - while (initial_ypos < rect->ymin) { - initial_ypos += ystep; - initial_value += value_step; - } - - for (float ypos = initial_ypos, value = initial_value; ypos < rect->ymax; - ypos += ystep, value += value_step) { - char text[32]; - get_scale_indicator_text(scene, value, grid->powery, unit, sizeof(text), text); - float text_width = BLF_width(font_id, text, sizeof(text)); - BLF_draw_default_ascii(xpos, ypos - text_width / 2.0f, 0.0f, text, sizeof(text)); - } - - BLF_disable(font_id, BLF_ROTATION); -} - -/* the price we pay for not exposting structs :( */ -void UI_view2d_grid_size(View2DGrid *grid, float *r_dx, float *r_dy) -{ - *r_dx = grid->dx; - *r_dy = grid->dy; -} - -/* free temporary memory used for drawing grid */ -void UI_view2d_grid_free(View2DGrid *grid) -{ - /* only free if there's a grid */ - if (grid) { - MEM_freeN(grid); - } -} - /* *********************************************************************** */ /* Scrollers */ @@ -1861,21 +1413,10 @@ struct View2DScrollers { rcti hor, vert; /* exact size of slider backdrop */ int horfull, vertfull; /* set if sliders are full, we don't draw them */ - - /* scales */ - View2DGrid *grid; /* grid for coordinate drawing */ - short xunits, xclamp; /* units and clamping options for x-axis */ - short yunits, yclamp; /* units and clamping options for y-axis */ }; /* Calculate relevant scroller properties */ -View2DScrollers *UI_view2d_scrollers_calc(const bContext *C, - View2D *v2d, - const rcti *mask_custom, - short xunits, - short xclamp, - short yunits, - short yclamp) +View2DScrollers *UI_view2d_scrollers_calc(View2D *v2d, const rcti *mask_custom) { View2DScrollers *scrollers; rcti vert, hor; @@ -2003,30 +1544,11 @@ View2DScrollers *UI_view2d_scrollers_calc(const bContext *C, } } - /* grid markings on scrollbars */ - if (scroll & (V2D_SCROLL_SCALE_HORIZONTAL | V2D_SCROLL_SCALE_VERTICAL)) { - /* store clamping */ - scrollers->xclamp = xclamp; - scrollers->xunits = xunits; - scrollers->yclamp = yclamp; - scrollers->yunits = yunits; - - scrollers->grid = UI_view2d_grid_calc(CTX_data_scene(C), - v2d, - xunits, - xclamp, - yunits, - yclamp, - BLI_rcti_size_x(&hor), - BLI_rcti_size_y(&vert)); - } - - /* return scrollers */ return scrollers; } /* Draw scrollbars in the given 2d-region */ -void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *vs) +void UI_view2d_scrollers_draw(View2D *v2d, View2DScrollers *vs) { bTheme *btheme = UI_GetTheme(); rcti vert, hor; @@ -2073,13 +1595,6 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v } UI_draw_widget_scroll(&wcol, &hor, &slider, state); - - { - if (scroll & V2D_SCROLL_SCALE_HORIZONTAL) { - UI_view2d_grid_draw_numbers_horizontal( - CTX_data_scene(C), v2d, vs->grid, &vs->hor, vs->xunits, vs->xclamp == V2D_GRID_CLAMP); - } - } } /* vertical scrollbar */ @@ -2114,17 +1629,6 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v } UI_draw_widget_scroll(&wcol, &vert, &slider, state); - - { - if (scroll & V2D_SCROLL_SCALE_VERTICAL) { - float text_offset = 0.0f; - if (vs->yclamp & V2D_GRID_CLAMP) { - text_offset = 0.5f; - } - UI_view2d_grid_draw_numbers_vertical( - CTX_data_scene(C), v2d, vs->grid, &vs->vert, vs->yunits, text_offset); - } - } } /* Was changed above, so reset. */ @@ -2134,10 +1638,6 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v /* free temporary memory used for drawing scrollers */ void UI_view2d_scrollers_free(View2DScrollers *scrollers) { - /* need to free grid as well... */ - if (scrollers->grid) { - MEM_freeN(scrollers->grid); - } MEM_freeN(scrollers); } @@ -2198,7 +1698,8 @@ void UI_view2d_listview_cell_to_view(View2D *v2d, } /** - * Get the 'cell' (row, column) that the given 2D-view coordinates (i.e. in 'tot' rect space) lie in. + * Get the 'cell' (row, column) that the given 2D-view coordinates + * (i.e. in 'tot' rect space) lie in. * * \param columnwidth, rowheight: size of each 'cell' * \param startx, starty: coordinates (in 'tot' rect space) that the list starts from. @@ -2255,7 +1756,8 @@ void UI_view2d_listview_view_to_cell(View2D *v2d, * Get the 'extreme' (min/max) column and row indices which are visible within the 'cur' rect * * \param columnwidth, rowheight: Size of each 'cell' - * \param startx, starty: Coordinates that the list starts from, which should be (0,0) for most views + * \param startx, starty: Coordinates that the list starts from, + * which should be (0,0) for most views. * \param column_min, column_max, row_min, row_max: The starting and ending column/row indices */ void UI_view2d_listview_visible_cells(View2D *v2d, @@ -2613,27 +2115,54 @@ void UI_view2d_offset(struct View2D *v2d, float xfac, float yfac) char UI_view2d_mouse_in_scrollers_ex( const ARegion *ar, const View2D *v2d, int x, int y, int *r_scroll) { - int co[2]; - int scroll = view2d_scroll_mapped(v2d->scroll); + const int scroll = view2d_scroll_mapped(v2d->scroll); *r_scroll = scroll; - /* clamp x,y to region-coordinates first */ - co[0] = x - ar->winrct.xmin; - co[1] = y - ar->winrct.ymin; - - /* check if within scrollbars */ - if (scroll & V2D_SCROLL_HORIZONTAL) { - if (IN_2D_HORIZ_SCROLL(v2d, co)) { - return 'h'; + if (scroll) { + /* Move to region-coordinates. */ + const int co[2] = { + x - ar->winrct.xmin, + y - ar->winrct.ymin, + }; + if (scroll & V2D_SCROLL_HORIZONTAL) { + if (IN_2D_HORIZ_SCROLL(v2d, co)) { + return 'h'; + } + } + if (scroll & V2D_SCROLL_VERTICAL) { + if (IN_2D_VERT_SCROLL(v2d, co)) { + return 'v'; + } } } - if (scroll & V2D_SCROLL_VERTICAL) { - if (IN_2D_VERT_SCROLL(v2d, co)) { - return 'v'; + + return 0; +} + +char UI_view2d_rect_in_scrollers_ex(const ARegion *ar, + const View2D *v2d, + const rcti *rect, + int *r_scroll) +{ + const int scroll = view2d_scroll_mapped(v2d->scroll); + *r_scroll = scroll; + + if (scroll) { + /* Move to region-coordinates. */ + rcti rect_region = *rect; + BLI_rcti_translate(&rect_region, -ar->winrct.xmin, ar->winrct.ymin); + if (scroll & V2D_SCROLL_HORIZONTAL) { + if (IN_2D_HORIZ_SCROLL_RECT(v2d, &rect_region)) { + return 'h'; + } + } + if (scroll & V2D_SCROLL_VERTICAL) { + if (IN_2D_VERT_SCROLL_RECT(v2d, &rect_region)) { + return 'v'; + } } } - /* not found */ return 0; } @@ -2643,6 +2172,12 @@ char UI_view2d_mouse_in_scrollers(const ARegion *ar, const View2D *v2d, int x, i return UI_view2d_mouse_in_scrollers_ex(ar, v2d, x, y, &scroll_dummy); } +char UI_view2d_rect_in_scrollers(const ARegion *ar, const View2D *v2d, const rcti *rect) +{ + int scroll_dummy = 0; + return UI_view2d_rect_in_scrollers_ex(ar, v2d, rect, &scroll_dummy); +} + /* ******************* view2d text drawing cache ******************** */ typedef struct View2DString { diff --git a/source/blender/editors/interface/view2d_draw.c b/source/blender/editors/interface/view2d_draw.c new file mode 100644 index 00000000000..91128e49a60 --- /dev/null +++ b/source/blender/editors/interface/view2d_draw.c @@ -0,0 +1,526 @@ +/* + * 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. + * + * The Original Code is Copyright (C) 2008 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup edinterface + */ + +#include <float.h> +#include <limits.h> +#include <math.h> +#include <string.h> + +#include "MEM_guardedalloc.h" + +#include "DNA_scene_types.h" +#include "DNA_userdef_types.h" + +#include "BLI_array.h" +#include "BLI_utildefines.h" +#include "BLI_rect.h" +#include "BLI_math.h" +#include "BLI_timecode.h" +#include "BLI_string.h" + +#include "GPU_immediate.h" +#include "GPU_matrix.h" + +#include "WM_api.h" + +#include "BLF_api.h" + +#include "UI_interface.h" +#include "UI_view2d.h" + +#include "interface_intern.h" + +/* Compute display grid resolution + ********************************************************/ + +#define MIN_MAJOR_LINE_DISTANCE (UI_DPI_FAC * 50) + +static float select_major_distance(const float *possible_distances, + uint amount, + float pixel_width, + float view_width) +{ + BLI_assert(amount >= 1); + + if (IS_EQF(view_width, 0.0f)) { + return possible_distances[0]; + } + + float pixels_per_view_unit = pixel_width / view_width; + + for (uint i = 0; i < amount; i++) { + float distance = possible_distances[i]; + if (pixels_per_view_unit * distance >= MIN_MAJOR_LINE_DISTANCE) { + return distance; + } + } + return possible_distances[amount - 1]; +} + +static const float discrete_value_scales[] = { + 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000}; + +static const float continuous_value_scales[] = {0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, + 5, 10, 20, 50, 100, 200, 500, 1000, + 2000, 5000, 10000, 20000, 50000, 100000}; + +static uint view2d_major_step_x__discrete(const View2D *v2d) +{ + return select_major_distance(discrete_value_scales, + ARRAY_SIZE(discrete_value_scales), + BLI_rcti_size_x(&v2d->mask), + BLI_rctf_size_x(&v2d->cur)); +} + +static float view2d_major_step_x__continuous(const View2D *v2d) +{ + return select_major_distance(continuous_value_scales, + ARRAY_SIZE(continuous_value_scales), + BLI_rcti_size_x(&v2d->mask), + BLI_rctf_size_x(&v2d->cur)); +} + +static float view2d_major_step_y__continuous(const View2D *v2d) +{ + return select_major_distance(continuous_value_scales, + ARRAY_SIZE(continuous_value_scales), + BLI_rcti_size_y(&v2d->mask), + BLI_rctf_size_y(&v2d->cur)); +} + +static float view2d_major_step_x__time(const View2D *v2d, const Scene *scene) +{ + double fps = FPS; + + float *possible_distances = NULL; + BLI_array_staticdeclare(possible_distances, 32); + + for (uint step = 1; step < fps; step *= 2) { + BLI_array_append(possible_distances, step); + } + BLI_array_append(possible_distances, fps); + BLI_array_append(possible_distances, 2 * fps); + BLI_array_append(possible_distances, 5 * fps); + BLI_array_append(possible_distances, 10 * fps); + BLI_array_append(possible_distances, 30 * fps); + BLI_array_append(possible_distances, 60 * fps); + BLI_array_append(possible_distances, 2 * 60 * fps); + BLI_array_append(possible_distances, 5 * 60 * fps); + BLI_array_append(possible_distances, 10 * 60 * fps); + BLI_array_append(possible_distances, 30 * 60 * fps); + BLI_array_append(possible_distances, 60 * 60 * fps); + + float distance = select_major_distance(possible_distances, + BLI_array_len(possible_distances), + BLI_rcti_size_x(&v2d->mask), + BLI_rctf_size_x(&v2d->cur)); + + BLI_array_free(possible_distances); + return distance; +} + +/* Draw parallel lines + ************************************/ + +typedef struct ParallelLinesSet { + float offset; + float distance; +} ParallelLinesSet; + +static void get_parallel_lines_draw_steps(const ParallelLinesSet *lines, + float region_start, + float region_end, + float *r_first, + uint *r_steps) +{ + BLI_assert(lines->distance > 0); + BLI_assert(region_start <= region_end); + + *r_first = ceilf((region_start - lines->offset) / lines->distance) * lines->distance + + lines->offset; + + if (region_start <= *r_first && region_end >= *r_first) { + *r_steps = MAX2(0, floorf((region_end - *r_first) / lines->distance)) + 1; + } + else { + *r_steps = 0; + } +} + +static void draw_parallel_lines(const ParallelLinesSet *lines, + const rctf *rect, + const uchar *color, + char direction) +{ + float first; + uint steps; + + if (direction == 'v') { + get_parallel_lines_draw_steps(lines, rect->xmin, rect->xmax, &first, &steps); + } + else { + BLI_assert(direction == 'h'); + get_parallel_lines_draw_steps(lines, rect->ymin, rect->ymax, &first, &steps); + } + + if (steps == 0) { + return; + } + + GPUVertFormat *format = immVertexFormat(); + uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immUniformColor3ubv(color); + immBegin(GPU_PRIM_LINES, steps * 2); + + if (direction == 'v') { + for (uint i = 0; i < steps; i++) { + float xpos = first + i * lines->distance; + immVertex2f(pos, xpos, rect->ymin); + immVertex2f(pos, xpos, rect->ymax); + } + } + else { + for (uint i = 0; i < steps; i++) { + float ypos = first + i * lines->distance; + immVertex2f(pos, rect->xmin, ypos); + immVertex2f(pos, rect->xmax, ypos); + } + } + + immEnd(); + immUnbindProgram(); +} + +static void view2d_draw_lines_internal(const View2D *v2d, + const ParallelLinesSet *lines, + const uchar *color, + char direction) +{ + GPU_matrix_push_projection(); + UI_view2d_view_ortho(v2d); + draw_parallel_lines(lines, &v2d->cur, color, direction); + GPU_matrix_pop_projection(); +} + +static void view2d_draw_lines(const View2D *v2d, + float major_distance, + bool display_minor_lines, + char direction) +{ + uchar major_color[3]; + uchar minor_color[3]; + UI_GetThemeColor3ubv(TH_GRID, major_color); + UI_GetThemeColorShade3ubv(TH_GRID, 16, minor_color); + + ParallelLinesSet major_lines; + major_lines.distance = major_distance; + major_lines.offset = 0; + view2d_draw_lines_internal(v2d, &major_lines, major_color, direction); + + if (display_minor_lines) { + ParallelLinesSet minor_lines; + minor_lines.distance = major_distance; + minor_lines.offset = major_distance / 2.0f; + view2d_draw_lines_internal(v2d, &minor_lines, minor_color, direction); + } +} + +/* Scale indicator text drawing + **************************************************/ + +typedef void (*PositionToString)( + void *user_data, float v2d_pos, float v2d_step, uint max_len, char *r_str); + +static void draw_horizontal_scale_indicators(const ARegion *ar, + const View2D *v2d, + float distance, + const rcti *rect, + PositionToString to_string, + void *to_string_data) +{ + GPU_matrix_push_projection(); + wmOrtho2_region_pixelspace(ar); + + float start; + uint steps; + { + ParallelLinesSet lines; + lines.distance = distance; + lines.offset = 0; + get_parallel_lines_draw_steps(&lines, + UI_view2d_region_to_view_x(v2d, rect->xmin), + UI_view2d_region_to_view_x(v2d, rect->xmax), + &start, + &steps); + } + + const int font_id = BLF_default(); + UI_FontThemeColor(font_id, TH_TEXT); + + BLF_batch_draw_begin(); + + float ypos = rect->ymin + 4 * UI_DPI_FAC; + float xmin = rect->xmin; + float xmax = rect->xmax; + + for (uint i = 0; i < steps; i++) { + float xpos_view = start + i * distance; + float xpos_region = UI_view2d_view_to_region_x(v2d, xpos_view); + char text[32]; + to_string(to_string_data, xpos_view, distance, sizeof(text), text); + float text_width = BLF_width(font_id, text, strlen(text)); + + if (xpos_region - text_width / 2.0f >= xmin && xpos_region + text_width / 2.0f <= xmax) { + BLF_draw_default_ascii(xpos_region - text_width / 2.0f, ypos, 0.0f, text, sizeof(text)); + } + } + + BLF_batch_draw_end(); + + GPU_matrix_pop_projection(); +} + +static void draw_vertical_scale_indicators(const ARegion *ar, + const View2D *v2d, + float distance, + float display_offset, + const rcti *rect, + PositionToString to_string, + void *to_string_data) +{ + GPU_matrix_push_projection(); + wmOrtho2_region_pixelspace(ar); + + float start; + uint steps; + { + ParallelLinesSet lines; + lines.distance = distance; + lines.offset = 0; + get_parallel_lines_draw_steps(&lines, + UI_view2d_region_to_view_y(v2d, rect->ymin), + UI_view2d_region_to_view_y(v2d, rect->ymax), + &start, + &steps); + } + + const int font_id = BLF_default(); + UI_FontThemeColor(font_id, TH_TEXT); + + BLF_enable(font_id, BLF_ROTATION); + BLF_rotation(font_id, M_PI_2); + + BLF_batch_draw_begin(); + + float xpos = rect->xmax - 2.0f * UI_DPI_FAC; + float ymin = rect->ymin; + float ymax = rect->ymax; + + for (uint i = 0; i < steps; i++) { + float ypos_view = start + i * distance; + float ypos_region = UI_view2d_view_to_region_y(v2d, ypos_view + display_offset); + char text[32]; + to_string(to_string_data, ypos_view, distance, sizeof(text), text); + float text_width = BLF_width(font_id, text, strlen(text)); + + if (ypos_region - text_width / 2.0f >= ymin && ypos_region + text_width / 2.0f <= ymax) { + BLF_draw_default_ascii(xpos, ypos_region - text_width / 2.0f, 0.0f, text, sizeof(text)); + } + } + + BLF_batch_draw_end(); + BLF_disable(font_id, BLF_ROTATION); + + GPU_matrix_pop_projection(); +} + +static void view_to_string__frame_number( + void *UNUSED(user_data), float v2d_pos, float UNUSED(v2d_step), uint max_len, char *r_str) +{ + BLI_snprintf(r_str, max_len, "%d", (int)v2d_pos); +} + +static void view_to_string__time( + void *user_data, float v2d_pos, float UNUSED(v2d_step), uint max_len, char *r_str) +{ + const Scene *scene = (const Scene *)user_data; + + int brevity_level = 0; + BLI_timecode_string_from_time( + r_str, max_len, brevity_level, v2d_pos / (float)FPS, FPS, U.timecode_style); +} + +static void view_to_string__value( + void *UNUSED(user_data), float v2d_pos, float v2d_step, uint max_len, char *r_str) +{ + if (v2d_step >= 1.0f) { + BLI_snprintf(r_str, max_len, "%d", (int)v2d_pos); + } + else if (v2d_step >= 0.1f) { + BLI_snprintf(r_str, max_len, "%.1f", v2d_pos); + } + else if (v2d_step >= 0.01f) { + BLI_snprintf(r_str, max_len, "%.2f", v2d_pos); + } + else { + BLI_snprintf(r_str, max_len, "%.3f", v2d_pos); + } +} + +/* Grid Resolution API + **************************************************/ + +float UI_view2d_grid_resolution_x__frames_or_seconds(const struct View2D *v2d, + const struct Scene *scene, + bool display_seconds) +{ + if (display_seconds) { + return view2d_major_step_x__time(v2d, scene); + } + else { + return view2d_major_step_x__continuous(v2d); + } +} + +float UI_view2d_grid_resolution_y__values(const struct View2D *v2d) +{ + return view2d_major_step_y__continuous(v2d); +} + +/* Line Drawing API + **************************************************/ + +void UI_view2d_draw_lines_x__discrete_values(const View2D *v2d) +{ + uint major_line_distance = view2d_major_step_x__discrete(v2d); + view2d_draw_lines(v2d, major_line_distance, major_line_distance > 1, 'v'); +} + +void UI_view2d_draw_lines_x__values(const View2D *v2d) +{ + float major_line_distance = view2d_major_step_x__continuous(v2d); + view2d_draw_lines(v2d, major_line_distance, true, 'v'); +} + +void UI_view2d_draw_lines_y__values(const View2D *v2d) +{ + float major_line_distance = view2d_major_step_y__continuous(v2d); + view2d_draw_lines(v2d, major_line_distance, true, 'h'); +} + +void UI_view2d_draw_lines_x__discrete_time(const View2D *v2d, const Scene *scene) +{ + float major_line_distance = view2d_major_step_x__time(v2d, scene); + view2d_draw_lines(v2d, major_line_distance, major_line_distance > 1, 'v'); +} + +void UI_view2d_draw_lines_x__discrete_frames_or_seconds(const View2D *v2d, + const Scene *scene, + bool display_seconds) +{ + if (display_seconds) { + UI_view2d_draw_lines_x__discrete_time(v2d, scene); + } + else { + UI_view2d_draw_lines_x__discrete_values(v2d); + } +} + +void UI_view2d_draw_lines_x__frames_or_seconds(const View2D *v2d, + const Scene *scene, + bool display_seconds) +{ + if (display_seconds) { + UI_view2d_draw_lines_x__discrete_time(v2d, scene); + } + else { + UI_view2d_draw_lines_x__values(v2d); + } +} + +/* Scale indicator text drawing API + **************************************************/ + +void UI_view2d_draw_scale_x__discrete_values(const ARegion *ar, + const View2D *v2d, + const rcti *rect) +{ + float number_step = view2d_major_step_x__discrete(v2d); + draw_horizontal_scale_indicators(ar, v2d, number_step, rect, view_to_string__frame_number, NULL); +} + +void UI_view2d_draw_scale_x__discrete_time(const ARegion *ar, + const View2D *v2d, + const rcti *rect, + const Scene *scene) +{ + float step = view2d_major_step_x__time(v2d, scene); + draw_horizontal_scale_indicators(ar, v2d, step, rect, view_to_string__time, (void *)scene); +} + +void UI_view2d_draw_scale_x__values(const ARegion *ar, const View2D *v2d, const rcti *rect) +{ + float step = view2d_major_step_x__continuous(v2d); + draw_horizontal_scale_indicators(ar, v2d, step, rect, view_to_string__value, NULL); +} + +void UI_view2d_draw_scale_y__values(const ARegion *ar, const View2D *v2d, const rcti *rect) +{ + float step = view2d_major_step_y__continuous(v2d); + draw_vertical_scale_indicators(ar, v2d, step, 0.0f, rect, view_to_string__value, NULL); +} + +void UI_view2d_draw_scale_y__block(const ARegion *ar, const View2D *v2d, const rcti *rect) +{ + draw_vertical_scale_indicators(ar, v2d, 1.0f, 0.5f, rect, view_to_string__value, NULL); +} + +void UI_view2d_draw_scale_x__discrete_frames_or_seconds(const struct ARegion *ar, + const struct View2D *v2d, + const struct rcti *rect, + const struct Scene *scene, + bool display_seconds) +{ + if (display_seconds) { + UI_view2d_draw_scale_x__discrete_time(ar, v2d, rect, scene); + } + else { + UI_view2d_draw_scale_x__discrete_values(ar, v2d, rect); + } +} + +void UI_view2d_draw_scale_x__frames_or_seconds(const struct ARegion *ar, + const struct View2D *v2d, + const struct rcti *rect, + const struct Scene *scene, + bool display_seconds) +{ + if (display_seconds) { + UI_view2d_draw_scale_x__discrete_time(ar, v2d, rect, scene); + } + else { + UI_view2d_draw_scale_x__values(ar, v2d, rect); + } +} diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 855ad0306c4..ab8d1cf9bf6 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -1183,8 +1183,9 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, const wmEvent *event vzd->dx += dx; vzd->dy += dy; - /* store mouse coordinates for next time, if not doing continuous zoom - * - continuous zoom only depends on distance of mouse to starting point to determine rate of change + /* Store mouse coordinates for next time, if not doing continuous zoom: + * - Continuous zoom only depends on distance of mouse + * to starting point to determine rate of change. */ if (U.viewzoom != USER_ZOOM_CONT) { // XXX store this setting as RNA prop? vzd->lastx = event->x; @@ -1647,9 +1648,11 @@ typedef struct v2dScrollerMove { /** * #View2DScrollers is typedef'd in UI_view2d.h - * This is a CUT DOWN VERSION of the 'real' version, which is defined in view2d.c, as we only need focus bubble info + * This is a CUT DOWN VERSION of the 'real' version, which is defined in view2d.c, + * as we only need focus bubble info. * - * \warning: The start of this struct must not change, so that it stays in sync with the 'real' version + * \warning: The start of this struct must not change, + * so that it stays in sync with the 'real' version. * For now, we don't need to have a separate (internal) header for structs like this... */ struct View2DScrollers { @@ -1782,8 +1785,7 @@ static void scroller_activate_init(bContext *C, /* 'zone' depends on where mouse is relative to bubble * - zooming must be allowed on this axis, otherwise, default to pan */ - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); /* use a union of 'cur' & 'tot' incase the current view is far outside 'tot'. In this cases * moving the scroll bars has far too little effect and the view can get stuck T31476. */ diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt index fbbb8621ae6..5a35b251d0c 100644 --- a/source/blender/editors/io/CMakeLists.txt +++ b/source/blender/editors/io/CMakeLists.txt @@ -17,16 +17,16 @@ set(INC ../include + ../../alembic ../../blenkernel ../../blenlib ../../blentranslation ../../bmesh + ../../collada ../../depsgraph ../../makesdna ../../makesrna ../../windowmanager - ../../collada - ../../alembic ../../../../intern/guardedalloc ) diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c index dc8e33c817e..2f3e73f32d5 100644 --- a/source/blender/editors/io/io_alembic.c +++ b/source/blender/editors/io/io_alembic.c @@ -504,10 +504,12 @@ static int cmp_frame(const void *a, const void *b) const CacheFrame *frame_a = a; const CacheFrame *frame_b = b; - if (frame_a->framenr < frame_b->framenr) + if (frame_a->framenr < frame_b->framenr) { return -1; - if (frame_a->framenr > frame_b->framenr) + } + if (frame_a->framenr > frame_b->framenr) { return 1; + } return 0; } diff --git a/source/blender/editors/io/io_cache.c b/source/blender/editors/io/io_cache.c index 6358c2c1370..3dd3b20bda3 100644 --- a/source/blender/editors/io/io_cache.c +++ b/source/blender/editors/io/io_cache.c @@ -38,6 +38,8 @@ #include "RNA_access.h" +#include "DEG_depsgraph.h" + #include "UI_interface.h" #include "WM_api.h" @@ -93,7 +95,7 @@ static int cachefile_open_exec(bContext *C, wmOperator *op) CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, BLI_path_basename(filename), 0); BLI_strncpy(cache_file->filepath, filename, FILE_MAX); - BKE_cachefile_reload(bmain, cache_file); + DEG_id_tag_update(&cache_file->id, ID_RECALC_COPY_ON_WRITE); /* Will be set when running invoke, not exec directly. */ if (op->customdata != NULL) { @@ -137,7 +139,7 @@ void CACHEFILE_OT_open(wmOperatorType *ot) /* ***************************** Reload Operator **************************** */ -static int cachefile_reload_exec(bContext *C, wmOperator *op) +static int cachefile_reload_exec(bContext *C, wmOperator *UNUSED(op)) { CacheFile *cache_file = CTX_data_edit_cachefile(C); @@ -145,14 +147,10 @@ static int cachefile_reload_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - Main *bmain = CTX_data_main(C); - - BLI_freelistN(&cache_file->object_paths); - BKE_cachefile_reload(bmain, cache_file); + Depsgraph *depsgraph = CTX_data_depsgraph(C); + BKE_cachefile_reload(depsgraph, cache_file); return OPERATOR_FINISHED; - - UNUSED_VARS(op); } void CACHEFILE_OT_reload(wmOperatorType *ot) diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index af2366e7485..aa0c2b58468 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -60,10 +60,12 @@ static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent * char filepath[FILE_MAX]; const char *blendfile_path = BKE_main_blendfile_path(bmain); - if (blendfile_path[0] == '\0') + if (blendfile_path[0] == '\0') { BLI_strncpy(filepath, "untitled", sizeof(filepath)); - else + } + else { BLI_strncpy(filepath, blendfile_path, sizeof(filepath)); + } BLI_path_extension_replace(filepath, sizeof(filepath), ".dae"); RNA_string_set(op->ptr, "filepath", filepath); @@ -179,7 +181,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) /* get editmode results */ ED_object_editmode_load(bmain, CTX_data_edit_object(C)); - //Scene *scene = CTX_data_scene(C); + // Scene *scene = CTX_data_scene(C); ExportSettings export_settings; @@ -233,10 +235,12 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) export_settings.keep_bind_info = keep_bind_info != 0; int includeFilter = OB_REL_NONE; - if (export_settings.include_armatures) + if (export_settings.include_armatures) { includeFilter |= OB_REL_MOD_ARMATURE; - if (export_settings.include_children) + } + if (export_settings.include_children) { includeFilter |= OB_REL_CHILDREN_RECURSIVE; + } export_count = collada_export(C, &export_settings); @@ -813,7 +817,7 @@ void WM_OT_collada_import(wmOperatorType *ot) ot->exec = wm_collada_import_exec; ot->poll = WM_operator_winactive; - //ot->flag |= OPTYPE_PRESET; + // ot->flag |= OPTYPE_PRESET; ot->ui = wm_collada_import_draw; diff --git a/source/blender/editors/lattice/editlattice_select.c b/source/blender/editors/lattice/editlattice_select.c index 782c0644313..7e89ed9511f 100644 --- a/source/blender/editors/lattice/editlattice_select.c +++ b/source/blender/editors/lattice/editlattice_select.c @@ -582,8 +582,9 @@ static void findnearestLattvert__doClosest(void *userData, BPoint *bp, const flo } *data = userData; float dist_test = len_manhattan_v2v2(data->mval_fl, screen_co); - if ((bp->f1 & SELECT) && data->select) + if ((bp->f1 & SELECT) && data->select) { dist_test += 5.0f; + } if (dist_test < data->dist) { data->dist = dist_test; diff --git a/source/blender/editors/lattice/editlattice_tools.c b/source/blender/editors/lattice/editlattice_tools.c index 8ef383de552..0cfe59ef06c 100644 --- a/source/blender/editors/lattice/editlattice_tools.c +++ b/source/blender/editors/lattice/editlattice_tools.c @@ -57,8 +57,9 @@ static bool make_regular_poll(bContext *C) { Object *ob; - if (ED_operator_editlattice(C)) + if (ED_operator_editlattice(C)) { return 1; + } ob = CTX_data_active_object(C); return (ob && ob->type == OB_LATTICE); diff --git a/source/blender/editors/lattice/editlattice_undo.c b/source/blender/editors/lattice/editlattice_undo.c index 9ee2e8b563b..166201adc15 100644 --- a/source/blender/editors/lattice/editlattice_undo.c +++ b/source/blender/editors/lattice/editlattice_undo.c @@ -102,8 +102,7 @@ static int validate_undoLatt(void *data, void *edata) UndoLattice *ult = (UndoLattice *)data; EditLatt *editlatt = (EditLatt *)edata; - return (ult->pntsu == editlatt->latt->pntsu && - ult->pntsv == editlatt->latt->pntsv && + return (ult->pntsu == editlatt->latt->pntsu && ult->pntsv == editlatt->latt->pntsv && ult->pntsw == editlatt->latt->pntsw); } #endif diff --git a/source/blender/editors/mask/CMakeLists.txt b/source/blender/editors/mask/CMakeLists.txt index 9dabcc0e8bb..81c861ab4e4 100644 --- a/source/blender/editors/mask/CMakeLists.txt +++ b/source/blender/editors/mask/CMakeLists.txt @@ -26,8 +26,8 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c index 1c872e73226..3c456f9e2e2 100644 --- a/source/blender/editors/mask/mask_add.c +++ b/source/blender/editors/mask/mask_add.c @@ -126,8 +126,9 @@ bool ED_mask_find_nearest_diff_point(const bContext *C, dist_sq = dist_squared_to_line_segment_v2(co, a, b); if (dist_sq < dist_best_sq) { - if (tangent) + if (tangent) { sub_v2_v2v2(tangent, &diff_points[2 * j + 2], &diff_points[2 * j]); + } point_masklay = masklay; point_spline = spline; @@ -138,8 +139,9 @@ bool ED_mask_find_nearest_diff_point(const bContext *C, } } - if (feather_points) + if (feather_points) { MEM_freeN(feather_points); + } MEM_freeN(diff_points); } @@ -148,14 +150,17 @@ bool ED_mask_find_nearest_diff_point(const bContext *C, } if (point && dist_best_sq < threshold) { - if (masklay_r) + if (masklay_r) { *masklay_r = point_masklay; + } - if (spline_r) + if (spline_r) { *spline_r = point_spline; + } - if (point_r) + if (point_r) { *point_r = point; + } if (u_r) { /* TODO(sergey): Projection fails in some weirdo cases.. */ @@ -173,14 +178,17 @@ bool ED_mask_find_nearest_diff_point(const bContext *C, return true; } - if (masklay_r) + if (masklay_r) { *masklay_r = NULL; + } - if (spline_r) + if (spline_r) { *spline_r = NULL; + } - if (point_r) + if (point_r) { *point_r = NULL; + } return false; } @@ -702,8 +710,9 @@ static int add_feather_vertex_exec(bContext *C, wmOperator *op) RNA_float_get_array(op->ptr, "location", co); point = ED_mask_point_find_nearest(C, mask, co, threshold, NULL, NULL, NULL, NULL); - if (point) + if (point) { return OPERATOR_FINISHED; + } if (ED_mask_find_nearest_diff_point( C, mask, co, threshold, true, NULL, true, true, &masklay, &spline, &point, &u, NULL)) { diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c index 479e4fd2d6c..305e3a328ab 100644 --- a/source/blender/editors/mask/mask_draw.c +++ b/source/blender/editors/mask/mask_draw.c @@ -203,11 +203,13 @@ static void draw_spline_points(const bContext *C, float(*feather_points)[2], (*fp)[2]; float min[2], max[2]; - if (!spline->tot_point) + if (!spline->tot_point) { return; + } - if (sc) + if (sc) { undistort = sc->clip && (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT); + } /* TODO, add this to sequence editor */ float handle_size = 2.0f * UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE) * U.pixelsize; @@ -233,8 +235,9 @@ static void draw_spline_points(const bContext *C, copy_v2_v2(feather_point, *fp); - if (undistort) + if (undistort) { mask_point_undistort_pos(sc, feather_point, feather_point); + } if (j == 0) { sel = MASKPOINT_ISSEL_ANY(point); @@ -244,10 +247,12 @@ static void draw_spline_points(const bContext *C, } if (sel) { - if (point == masklay->act_point) + if (point == masklay->act_point) { immUniformColor3f(1.0f, 1.0f, 1.0f); - else + } + else { immUniformThemeColorShadeAlpha(TH_HANDLE_VERTEX_SELECT, 0, 255); + } } else { immUniformThemeColorShadeAlpha(TH_HANDLE_VERTEX, 0, 255); @@ -314,13 +319,16 @@ static void draw_spline_points(const bContext *C, /* draw CV point */ if (MASKPOINT_ISSEL_KNOT(point)) { - if (point == masklay->act_point) + if (point == masklay->act_point) { immUniformColor3f(1.0f, 1.0f, 1.0f); - else + } + else { immUniformThemeColorShadeAlpha(TH_HANDLE_VERTEX_SELECT, 0, 255); + } } - else + else { immUniformThemeColorShadeAlpha(TH_HANDLE_VERTEX, 0, 255); + } immBegin(GPU_PRIM_POINTS, 1); immVertex2fv(pos, vert); @@ -502,8 +510,9 @@ static void mask_draw_curve_type(const bContext *C, BLI_assert(false); } - if (points != orig_points) + if (points != orig_points) { MEM_freeN(points); + } } static void draw_spline_curve(const bContext *C, @@ -533,8 +542,9 @@ static void draw_spline_curve(const bContext *C, diff_points = BKE_mask_spline_differentiate_with_resolution(spline, &tot_diff_point, resol); - if (!diff_points) + if (!diff_points) { return; + } if (is_smooth) { GPU_line_smooth(true); @@ -633,8 +643,9 @@ void ED_mask_draw(const bContext *C, const char draw_flag, const char draw_type) Mask *mask = CTX_data_edit_mask(C); int width, height; - if (!mask) + if (!mask) { return; + } ED_mask_get_size(sa, &width, &height); diff --git a/source/blender/editors/mask/mask_edit.c b/source/blender/editors/mask/mask_edit.c index 7325686d4f0..0c5591ed89b 100644 --- a/source/blender/editors/mask/mask_edit.c +++ b/source/blender/editors/mask/mask_edit.c @@ -374,8 +374,9 @@ bool ED_mask_selected_minmax(const bContext *C, float min[2], float max[2]) MaskLayer *mask_layer; bool ok = false; - if (mask == NULL) + if (mask == NULL) { return ok; + } INIT_MINMAX2(min, max); for (mask_layer = mask->masklayers.first; mask_layer != NULL; mask_layer = mask_layer->next) { @@ -519,6 +520,6 @@ void ED_operatormacros_mask(void) OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "MASK_OT_duplicate"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); } diff --git a/source/blender/editors/mask/mask_editaction.c b/source/blender/editors/mask/mask_editaction.c index d30e62d89f5..985fa58cace 100644 --- a/source/blender/editors/mask/mask_editaction.c +++ b/source/blender/editors/mask/mask_editaction.c @@ -60,15 +60,17 @@ bool ED_masklayer_frames_looper(MaskLayer *masklay, MaskLayerShape *masklay_shape; /* error checker */ - if (masklay == NULL) + if (masklay == NULL) { return false; + } /* do loop */ for (masklay_shape = masklay->splines_shapes.first; masklay_shape; masklay_shape = masklay_shape->next) { /* execute callback */ - if (masklay_shape_cb(masklay_shape, scene)) + if (masklay_shape_cb(masklay_shape, scene)) { return true; + } } /* nothing to return */ @@ -85,8 +87,9 @@ void ED_masklayer_make_cfra_list(MaskLayer *masklay, ListBase *elems, bool onlys CfraElem *ce; /* error checking */ - if (ELEM(NULL, masklay, elems)) + if (ELEM(NULL, masklay, elems)) { return; + } /* loop through mask-frames, adding */ for (masklay_shape = masklay->splines_shapes.first; masklay_shape; @@ -111,14 +114,16 @@ bool ED_masklayer_frame_select_check(MaskLayer *masklay) MaskLayerShape *masklay_shape; /* error checking */ - if (masklay == NULL) + if (masklay == NULL) { return 0; + } /* stop at the first one found */ for (masklay_shape = masklay->splines_shapes.first; masklay_shape; masklay_shape = masklay_shape->next) { - if (masklay_shape->flag & MASK_SHAPE_SELECT) + if (masklay_shape->flag & MASK_SHAPE_SELECT) { return 1; + } } /* not found */ @@ -128,8 +133,9 @@ bool ED_masklayer_frame_select_check(MaskLayer *masklay) /* helper function - select mask-frame based on SELECT_* mode */ static void masklayshape_select(MaskLayerShape *masklay_shape, short select_mode) { - if (masklay_shape == NULL) + if (masklay_shape == NULL) { return; + } switch (select_mode) { case SELECT_ADD: @@ -150,8 +156,9 @@ void ED_mask_select_frames(MaskLayer *masklay, short select_mode) MaskLayerShape *masklay_shape; /* error checking */ - if (masklay == NULL) + if (masklay == NULL) { return; + } /* handle according to mode */ for (masklay_shape = masklay->splines_shapes.first; masklay_shape; @@ -164,8 +171,9 @@ void ED_mask_select_frames(MaskLayer *masklay, short select_mode) void ED_masklayer_frame_select_set(MaskLayer *masklay, short mode) { /* error checking */ - if (masklay == NULL) + if (masklay == NULL) { return; + } /* now call the standard function */ ED_mask_select_frames(masklay, mode); @@ -176,8 +184,9 @@ void ED_mask_select_frame(MaskLayer *masklay, int selx, short select_mode) { MaskLayerShape *masklay_shape; - if (masklay == NULL) + if (masklay == NULL) { return; + } masklay_shape = BKE_mask_layer_shape_find_frame(masklay, selx); @@ -191,14 +200,16 @@ void ED_masklayer_frames_select_box(MaskLayer *masklay, float min, float max, sh { MaskLayerShape *masklay_shape; - if (masklay == NULL) + if (masklay == NULL) { return; + } /* only select those frames which are in bounds */ for (masklay_shape = masklay->splines_shapes.first; masklay_shape; masklay_shape = masklay_shape->next) { - if (IN_RANGE(masklay_shape->frame, min, max)) + if (IN_RANGE(masklay_shape->frame, min, max)) { masklayshape_select(masklay_shape, select_mode); + } } } @@ -210,8 +221,9 @@ void ED_masklayer_frames_select_region(KeyframeEditData *ked, { MaskLayerShape *masklay_shape; - if (masklay == NULL) + if (masklay == NULL) { return; + } /* only select frames which are within the region */ for (masklay_shape = masklay->splines_shapes.first; masklay_shape; @@ -225,13 +237,15 @@ void ED_masklayer_frames_select_region(KeyframeEditData *ked, /* check the necessary regions */ if (tool == BEZT_OK_CHANNEL_LASSO) { /* Lasso */ - if (keyframe_region_lasso_test(ked->data, pt)) + if (keyframe_region_lasso_test(ked->data, pt)) { masklayshape_select(masklay_shape, select_mode); + } } else if (tool == BEZT_OK_CHANNEL_CIRCLE) { /* Circle */ - if (keyframe_region_circle_test(ked->data, pt)) + if (keyframe_region_circle_test(ked->data, pt)) { masklayshape_select(masklay_shape, select_mode); + } } } } @@ -246,8 +260,9 @@ bool ED_masklayer_frames_delete(MaskLayer *masklay) bool changed = false; /* error checking */ - if (masklay == NULL) + if (masklay == NULL) { return false; + } /* check for frames to delete */ for (masklay_shape = masklay->splines_shapes.first; masklay_shape; @@ -269,8 +284,9 @@ void ED_masklayer_frames_duplicate(MaskLayer *masklay) MaskLayerShape *masklay_shape, *gpfn; /* error checking */ - if (masklay == NULL) + if (masklay == NULL) { return; + } /* duplicate selected frames */ for (masklay_shape = masklay->splines_shapes.first; masklay_shape; masklay_shape = gpfn) { @@ -295,31 +311,35 @@ void ED_masklayer_frames_duplicate(MaskLayer *masklay) static short snap_masklayer_nearest(MaskLayerShape *masklay_shape, Scene *UNUSED(scene)) { - if (masklay_shape->flag & MASK_SHAPE_SELECT) + if (masklay_shape->flag & MASK_SHAPE_SELECT) { masklay_shape->frame = (int)(floor(masklay_shape->frame + 0.5)); + } return 0; } static short snap_masklayer_nearestsec(MaskLayerShape *masklay_shape, Scene *scene) { float secf = (float)FPS; - if (masklay_shape->flag & MASK_SHAPE_SELECT) + if (masklay_shape->flag & MASK_SHAPE_SELECT) { masklay_shape->frame = (int)(floorf(masklay_shape->frame / secf + 0.5f) * secf); + } return 0; } static short snap_masklayer_cframe(MaskLayerShape *masklay_shape, Scene *scene) { - if (masklay_shape->flag & MASK_SHAPE_SELECT) + if (masklay_shape->flag & MASK_SHAPE_SELECT) { masklay_shape->frame = (int)CFRA; + } return 0; } static short snap_masklayer_nearmarker(MaskLayerShape *masklay_shape, Scene *scene) { - if (masklay_shape->flag & MASK_SHAPE_SELECT) + if (masklay_shape->flag & MASK_SHAPE_SELECT) { masklay_shape->frame = (int)ED_markers_find_nearest_marker_time(&scene->markers, (float)masklay_shape->frame); + } return 0; } diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index 2b925b9095e..c0f3b1f8338 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -179,29 +179,36 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, } if (len_sq < threshold_sq) { - if (masklay_r) + if (masklay_r) { *masklay_r = point_masklay; + } - if (spline_r) + if (spline_r) { *spline_r = point_spline; + } - if (which_handle_r) + if (which_handle_r) { *which_handle_r = which_handle; + } - if (score) + if (score) { *score = sqrtf(len_sq); + } return point; } - if (masklay_r) + if (masklay_r) { *masklay_r = NULL; + } - if (spline_r) + if (spline_r) { *spline_r = NULL; + } - if (which_handle_r) + if (which_handle_r) { *which_handle_r = MASK_WHICH_HANDLE_NONE; + } return NULL; } @@ -238,7 +245,7 @@ bool ED_mask_feather_find_nearest(const bContext *C, MaskSpline *spline; for (spline = masklay->splines.first; spline; spline = spline->next) { - //MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); + // MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); int i, tot_feather_point; float(*feather_points)[2], (*fp)[2]; @@ -262,10 +269,12 @@ bool ED_mask_feather_find_nearest(const bContext *C, cur_len_sq = len_squared_v2v2(vec, co); if (point == NULL || cur_len_sq < len) { - if (j == 0) + if (j == 0) { uw = NULL; - else + } + else { uw = &cur_point->uw[j - 1]; + } point_masklay = masklay; point_spline = spline; @@ -282,32 +291,40 @@ bool ED_mask_feather_find_nearest(const bContext *C, } if (len < threshold_sq) { - if (masklay_r) + if (masklay_r) { *masklay_r = point_masklay; + } - if (spline_r) + if (spline_r) { *spline_r = point_spline; + } - if (point_r) + if (point_r) { *point_r = point; + } - if (uw_r) + if (uw_r) { *uw_r = uw; + } - if (score) + if (score) { *score = sqrtf(len); + } return true; } - if (masklay_r) + if (masklay_r) { *masklay_r = NULL; + } - if (spline_r) + if (spline_r) { *spline_r = NULL; + } - if (point_r) + if (point_r) { *point_r = NULL; + } return false; } @@ -720,10 +737,12 @@ static void *slide_point_customdata(bContext *C, wmOperator *op, const wmEvent * } if (cv_point && action == SLIDE_ACTION_NONE) { - if (which_handle != MASK_WHICH_HANDLE_NONE) + if (which_handle != MASK_WHICH_HANDLE_NONE) { action = SLIDE_ACTION_HANDLE; - else + } + else { action = SLIDE_ACTION_POINT; + } masklay = cv_masklay; spline = cv_spline; @@ -851,8 +870,9 @@ static void slide_point_restore_spline(SlidePointData *data) point->bezt = orig_point->bezt; - for (j = 0; j < point->tot_uw; j++) + for (j = 0; j < point->tot_uw; j++) { point->uw[j] = orig_point->uw[j]; + } } } @@ -865,10 +885,12 @@ static void cancel_slide_point(SlidePointData *data) } else { if (data->action == SLIDE_ACTION_FEATHER) { - if (data->uw) + if (data->uw) { data->uw->w = data->weight; - else + } + else { data->point->bezt.weight = data->weight; + } } else if (data->action != SLIDE_ACTION_SPLINE) { copy_m3_m3(data->point->bezt.vec, data->vec); @@ -880,8 +902,9 @@ static void cancel_slide_point(SlidePointData *data) static void free_slide_point_data(SlidePointData *data) { - if (data->orig_spline) + if (data->orig_spline) { BKE_mask_spline_free(data->orig_spline); + } MEM_freeN(data); } @@ -906,8 +929,9 @@ static int slide_point_modal(bContext *C, wmOperator *op, const wmEvent *event) } } - if (ELEM(event->type, LEFTSHIFTKEY, RIGHTSHIFTKEY)) + if (ELEM(event->type, LEFTSHIFTKEY, RIGHTSHIFTKEY)) { data->is_accurate = (event->val == KM_PRESS); + } ATTR_FALLTHROUGH; /* update CV position */ case MOUSEMOVE: { @@ -1028,8 +1052,9 @@ static int slide_point_modal(bContext *C, wmOperator *op, const wmEvent *event) if (is_overall_feather) { float w_delta; - if (dot_v2v2(no, vec) <= 0.0f) + if (dot_v2v2(no, vec) <= 0.0f) { w = -w; + } w_delta = w - data->weight * data->weight_scalar; @@ -1049,8 +1074,9 @@ static int slide_point_modal(bContext *C, wmOperator *op, const wmEvent *event) slide_point_delta_all_feather(data, w_delta); } else { - if (dot_v2v2(no, vec) <= 0.0f) + if (dot_v2v2(no, vec) <= 0.0f) { w = 0.0f; + } if (data->orig_spline) { /* restore possible overall feather changes */ @@ -1586,12 +1612,14 @@ static void delete_feather_points(MaskSplinePoint *point) { int i, count = 0; - if (!point->tot_uw) + if (!point->tot_uw) { return; + } for (i = 0; i < point->tot_uw; i++) { - if ((point->uw[i].flag & SELECT) == 0) + if ((point->uw[i].flag & SELECT) == 0) { count++; + } } if (count == 0) { @@ -1644,8 +1672,9 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) for (i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; - if (!MASKPOINT_ISSEL_ANY(point)) + if (!MASKPOINT_ISSEL_ANY(point)) { count++; + } } if (count == 0) { @@ -1670,8 +1699,9 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) MaskSplinePoint *point = &spline->points[i]; if (!MASKPOINT_ISSEL_ANY(point)) { - if (point == masklay->act_point) + if (point == masklay->act_point) { masklay->act_point = &new_points[j]; + } delete_feather_points(point); @@ -1679,8 +1709,9 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) j++; } else { - if (point == masklay->act_point) + if (point == masklay->act_point) { masklay->act_point = NULL; + } BKE_mask_point_free(point); spline->tot_point--; @@ -2138,14 +2169,16 @@ static int mask_layer_move_exec(bContext *C, wmOperator *op) MaskLayer *mask_layer_other; int direction = RNA_enum_get(op->ptr, "direction"); - if (!mask_layer) + if (!mask_layer) { return OPERATOR_CANCELLED; + } if (direction == -1) { mask_layer_other = mask_layer->prev; - if (!mask_layer_other) + if (!mask_layer_other) { return OPERATOR_CANCELLED; + } BLI_remlink(&mask->masklayers, mask_layer); BLI_insertlinkbefore(&mask->masklayers, mask_layer_other, mask_layer); @@ -2154,8 +2187,9 @@ static int mask_layer_move_exec(bContext *C, wmOperator *op) else if (direction == 1) { mask_layer_other = mask_layer->next; - if (!mask_layer_other) + if (!mask_layer_other) { return OPERATOR_CANCELLED; + } BLI_remlink(&mask->masklayers, mask_layer); BLI_insertlinkafter(&mask->masklayers, mask_layer_other, mask_layer); diff --git a/source/blender/editors/mask/mask_relationships.c b/source/blender/editors/mask/mask_relationships.c index bb9359bad71..75b2aee3570 100644 --- a/source/blender/editors/mask/mask_relationships.c +++ b/source/blender/editors/mask/mask_relationships.c @@ -184,7 +184,7 @@ void MASK_OT_parent_set(wmOperatorType *ot) ot->idname = "MASK_OT_parent_set"; /* api callbacks */ - //ot->invoke = mask_parent_set_invoke; + // ot->invoke = mask_parent_set_invoke; ot->exec = mask_parent_set_exec; ot->poll = ED_space_clip_maskedit_mask_poll; diff --git a/source/blender/editors/mask/mask_select.c b/source/blender/editors/mask/mask_select.c index 076f8d067b9..a592f39d24b 100644 --- a/source/blender/editors/mask/mask_select.c +++ b/source/blender/editors/mask/mask_select.c @@ -57,8 +57,9 @@ bool ED_mask_spline_select_check(MaskSpline *spline) for (i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; - if (MASKPOINT_ISSEL_ANY(point)) + if (MASKPOINT_ISSEL_ANY(point)) { return true; + } } return false; @@ -99,10 +100,12 @@ void ED_mask_spline_select_set(MaskSpline *spline, const bool do_select) { int i; - if (do_select) + if (do_select) { spline->flag |= SELECT; - else + } + else { spline->flag &= ~SELECT; + } for (i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; @@ -131,10 +134,12 @@ void ED_mask_select_toggle_all(Mask *mask, int action) MaskLayer *masklay; if (action == SEL_TOGGLE) { - if (ED_mask_select_check(mask)) + if (ED_mask_select_check(mask)) { action = SEL_DESELECT; - else + } + else { action = SEL_SELECT; + } } for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { @@ -257,6 +262,7 @@ static int select_exec(bContext *C, wmOperator *op) bool extend = RNA_boolean_get(op->ptr, "extend"); bool deselect = RNA_boolean_get(op->ptr, "deselect"); bool toggle = RNA_boolean_get(op->ptr, "toggle"); + const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all"); eMaskWhichHandle which_handle; const float threshold = 19; @@ -265,8 +271,9 @@ static int select_exec(bContext *C, wmOperator *op) point = ED_mask_point_find_nearest( C, mask, co, threshold, &masklay, &spline, &which_handle, NULL); - if (extend == false && deselect == false && toggle == false) + if (extend == false && deselect == false && toggle == false) { ED_mask_select_toggle_all(mask, SEL_DESELECT); + } if (point) { if (which_handle != MASK_WHICH_HANDLE_NONE) { @@ -333,12 +340,14 @@ static int select_exec(bContext *C, wmOperator *op) masklay->act_spline = spline; masklay->act_point = point; - if (uw) + if (uw) { uw->flag |= SELECT; + } } else if (deselect) { - if (uw) + if (uw) { uw->flag &= ~SELECT; + } } else { masklay->act_spline = spline; @@ -360,6 +369,15 @@ static int select_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } + else if (deselect_all) { + ED_mask_select_toggle_all(mask, SEL_DESELECT); + + ED_mask_select_flush_all(mask); + + WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask); + + return OPERATOR_FINISHED; + } } return OPERATOR_PASS_THROUGH; diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt index e67d63b01a5..57bf67e825e 100644 --- a/source/blender/editors/mesh/CMakeLists.txt +++ b/source/blender/editors/mesh/CMakeLists.txt @@ -21,8 +21,8 @@ set(INC ../../blenkernel ../../blenlib ../../blentranslation - ../../depsgraph ../../bmesh + ../../depsgraph ../../gpu ../../imbuf ../../makesdna @@ -30,8 +30,8 @@ set(INC ../../render/extern/include ../../windowmanager ../../../../intern/clog - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index f342cc3a809..990250792a1 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -65,8 +65,9 @@ void paintface_flush_flags(struct bContext *C, Object *ob, short flag) BLI_assert((flag & ~(SELECT | ME_HIDE)) == 0); - if (me == NULL) + if (me == NULL) { return; + } /* note, call #BKE_mesh_flush_hidden_from_verts_ex first when changing hidden flags */ @@ -120,7 +121,7 @@ void paintface_flush_flags(struct bContext *C, Object *ob, short flag) BKE_mesh_batch_cache_dirty_tag(me_eval, BKE_MESH_BATCH_DIRTY_ALL); } else { - BKE_mesh_batch_cache_dirty_tag(me_eval, BKE_MESH_BATCH_DIRTY_SELECT); + BKE_mesh_batch_cache_dirty_tag(me_eval, BKE_MESH_BATCH_DIRTY_SELECT_PAINT); } DEG_id_tag_update(ob->data, ID_RECALC_SELECT); @@ -139,8 +140,9 @@ void paintface_hide(bContext *C, Object *ob, const bool unselected) int a; me = BKE_mesh_from_object(ob); - if (me == NULL || me->totpoly == 0) + if (me == NULL || me->totpoly == 0) { return; + } mpoly = me->mpoly; a = me->totpoly; @@ -170,8 +172,9 @@ void paintface_reveal(bContext *C, Object *ob, const bool select) int a; me = BKE_mesh_from_object(ob); - if (me == NULL || me->totpoly == 0) + if (me == NULL || me->totpoly == 0) { return; + } mpoly = me->mpoly; a = me->totpoly; @@ -227,8 +230,9 @@ static void select_linked_tfaces_with_seams(Mesh *me, const unsigned int index, /* expand selection */ mp = me->mpoly; for (a = 0; a < me->totpoly; a++, mp++) { - if (mp->flag & ME_HIDE) + if (mp->flag & ME_HIDE) { continue; + } if (!BLI_BITMAP_TEST(poly_tag, a)) { mark = false; @@ -269,8 +273,9 @@ void paintface_select_linked(bContext *C, Object *ob, const int mval[2], const b unsigned int index = (unsigned int)-1; me = BKE_mesh_from_object(ob); - if (me == NULL || me->totpoly == 0) + if (me == NULL || me->totpoly == 0) { return; + } if (mval) { if (!ED_mesh_pick_face(C, ob, mval, ED_MESH_PICK_DEFAULT_FACE_DIST, &index)) { @@ -364,8 +369,9 @@ bool paintface_minmax(Object *ob, float r_min[3], float r_max[3]) mvert = me->mvert; mp = me->mpoly; for (a = me->totpoly; a > 0; a--, mp++) { - if (mp->flag & ME_HIDE || !(mp->flag & ME_FACE_SEL)) + if (mp->flag & ME_HIDE || !(mp->flag & ME_FACE_SEL)) { continue; + } ml = me->mloop + mp->totloop; for (b = 0; b < mp->totloop; b++, ml++) { @@ -399,8 +405,9 @@ bool paintface_mouse_select( } mpoly_sel = me->mpoly + index; - if (mpoly_sel->flag & ME_HIDE) + if (mpoly_sel->flag & ME_HIDE) { return false; + } /* clear flags */ if (!extend && !deselect && !toggle) { @@ -416,10 +423,12 @@ bool paintface_mouse_select( mpoly_sel->flag &= ~ME_FACE_SEL; } else if (toggle) { - if (mpoly_sel->flag & ME_FACE_SEL) + if (mpoly_sel->flag & ME_FACE_SEL) { mpoly_sel->flag &= ~ME_FACE_SEL; - else + } + else { mpoly_sel->flag |= ME_FACE_SEL; + } } else { mpoly_sel->flag |= ME_FACE_SEL; @@ -512,15 +521,17 @@ void paintvert_flush_flags(Object *ob) int totvert; int i; - if (me == NULL) + if (me == NULL) { return; + } /* we could call this directly in all areas that change selection, * since this could become slow for realtime updates (circle-select for eg) */ BKE_mesh_flush_select_from_verts(me); - if (me_eval == NULL) + if (me_eval == NULL) { return; + } index_array = CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX); diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index 815f51a4772..a7d1e54ad59 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -490,8 +490,8 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ - /* Note that if you use MESH_ADD_VERTS_MAXI for both x and y at the same time you will still reach - * impossible values (10^12 vertices or so...). */ + /* Note that if you use MESH_ADD_VERTS_MAXI for both x and y at the same time + * you will still reach impossible values (10^12 vertices or so...). */ RNA_def_int( ot->srna, "x_subdivisions", 10, 2, MESH_ADD_VERTS_MAXI, "X Subdivisions", "", 2, 1000); RNA_def_int( diff --git a/source/blender/editors/mesh/editmesh_add_gizmo.c b/source/blender/editors/mesh/editmesh_add_gizmo.c index 9ed2c15f1c1..839ee186016 100644 --- a/source/blender/editors/mesh/editmesh_add_gizmo.c +++ b/source/blender/editors/mesh/editmesh_add_gizmo.c @@ -58,7 +58,8 @@ * When we place a shape, pick a plane. * * We may base this choice on context, - * for now pick the "ground" based on the 3D cursor's dominant plane pointing down relative to the view. + * for now pick the "ground" based on the 3D cursor's dominant plane + * pointing down relative to the view. */ static void calc_initial_placement_point_from_view(bContext *C, const float mval[2], diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c index 2c0c8b2c708..f6940cae953 100644 --- a/source/blender/editors/mesh/editmesh_bevel.c +++ b/source/blender/editors/mesh/editmesh_bevel.c @@ -120,10 +120,12 @@ static float get_bevel_offset(wmOperator *op) { float val; - if (RNA_enum_get(op->ptr, "offset_type") == BEVEL_AMT_PERCENT) + if (RNA_enum_get(op->ptr, "offset_type") == BEVEL_AMT_PERCENT) { val = RNA_float_get(op->ptr, "offset_pct"); - else + } + else { val = RNA_float_get(op->ptr, "offset"); + } return val; } @@ -491,7 +493,8 @@ static int edbm_bevel_invoke(bContext *C, wmOperator *op, const wmEvent *event) /* for OFFSET_VALUE only, the scale is the size of a pixel under the mouse in 3d space */ opdata->scale[OFFSET_VALUE] = rv3d ? ED_view3d_pixel_size(rv3d, center_3d) : 1.0f; - /* since we are affecting untransformed object but seeing in transformed space, compensate for that */ + /* since we are affecting untransformed object but seeing in transformed space, + * compensate for that */ opdata->scale[OFFSET_VALUE] /= opdata->max_obj_scale; edbm_bevel_calc_initial_length(op, event, false); @@ -578,10 +581,12 @@ static bool edbm_bevel_poll_property(const bContext *UNUSED(C), if (STRPREFIX(prop_id, "offset")) { int offset_type = RNA_enum_get(op->ptr, "offset_type"); - if (STREQ(prop_id, "offset") && offset_type == BEVEL_AMT_PERCENT) + if (STREQ(prop_id, "offset") && offset_type == BEVEL_AMT_PERCENT) { return false; - else if (STREQ(prop_id, "offset_pct") && offset_type != BEVEL_AMT_PERCENT) + } + else if (STREQ(prop_id, "offset_pct") && offset_type != BEVEL_AMT_PERCENT) { return false; + } } return true; @@ -647,8 +652,9 @@ wmKeyMap *bevel_modal_keymap(wmKeyConfig *keyconf) wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "Bevel Modal Map"); /* this function is called for each spacetype, only needs to add map once */ - if (keymap && keymap->modal_items) + if (keymap && keymap->modal_items) { return NULL; + } keymap = WM_modalkeymap_add(keyconf, "Bevel Modal Map", modal_items); @@ -688,10 +694,12 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event) } else if (etype == MOUSEPAN) { float delta = 0.02f * (event->y - event->prevy); - if (opdata->segments >= 1 && opdata->segments + delta < 1) + if (opdata->segments >= 1 && opdata->segments + delta < 1) { opdata->segments = 1; - else + } + else { opdata->segments += delta; + } RNA_int_set(op->ptr, "segments", (int)opdata->segments); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); @@ -732,13 +740,16 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event) if (type > BEVEL_AMT_PERCENT) { type = BEVEL_AMT_OFFSET; } - if (opdata->value_mode == OFFSET_VALUE && type == BEVEL_AMT_PERCENT) + if (opdata->value_mode == OFFSET_VALUE && type == BEVEL_AMT_PERCENT) { opdata->value_mode = OFFSET_VALUE_PERCENT; - else if (opdata->value_mode == OFFSET_VALUE_PERCENT && type != BEVEL_AMT_PERCENT) + } + else if (opdata->value_mode == OFFSET_VALUE_PERCENT && type != BEVEL_AMT_PERCENT) { opdata->value_mode = OFFSET_VALUE; + } RNA_enum_set(op->ptr, "offset_type", type); - if (opdata->initial_length[opdata->value_mode] == -1.0f) + if (opdata->initial_length[opdata->value_mode] == -1.0f) { edbm_bevel_calc_initial_length(op, event, true); + } } /* Update offset accordingly to new offset_type. */ if (!has_numinput && @@ -804,10 +815,12 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event) case BEV_MODAL_INNER_MITER_CHANGE: { int miter_inner = RNA_enum_get(op->ptr, "miter_inner"); miter_inner++; - if (miter_inner == BEVEL_MITER_PATCH) + if (miter_inner == BEVEL_MITER_PATCH) { miter_inner++; /* no patch option for inner miter */ - if (miter_inner > BEVEL_MITER_ARC) + } + if (miter_inner > BEVEL_MITER_ARC) { miter_inner = BEVEL_MITER_SHARP; + } RNA_enum_set(op->ptr, "miter_inner", miter_inner); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); @@ -818,8 +831,9 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event) case BEV_MODAL_OUTER_MITER_CHANGE: { int miter_outer = RNA_enum_get(op->ptr, "miter_outer"); miter_outer++; - if (miter_outer > BEVEL_MITER_ARC) + if (miter_outer > BEVEL_MITER_ARC) { miter_outer = BEVEL_MITER_SHARP; + } RNA_enum_set(op->ptr, "miter_outer", miter_outer); edbm_bevel_calc(op); edbm_bevel_update_header(C, op); diff --git a/source/blender/editors/mesh/editmesh_extrude.c b/source/blender/editors/mesh/editmesh_extrude.c index eeda7ec5f2d..82cff8363f8 100644 --- a/source/blender/editors/mesh/editmesh_extrude.c +++ b/source/blender/editors/mesh/editmesh_extrude.c @@ -347,28 +347,37 @@ static bool edbm_extrude_mesh(Object *obedit, BMEditMesh *em, wmOperator *op) bool changed = false; if (em->selectmode & SCE_SELECT_VERTEX) { - if (em->bm->totvertsel == 0) + if (em->bm->totvertsel == 0) { nr = NONE; - else if (em->bm->totvertsel == 1) + } + else if (em->bm->totvertsel == 1) { nr = VERT_ONLY; - else if (em->bm->totedgesel == 0) + } + else if (em->bm->totedgesel == 0) { nr = VERT_ONLY; - else + } + else { nr = ELEM_FLAG; + } } else if (em->selectmode & SCE_SELECT_EDGE) { - if (em->bm->totedgesel == 0) + if (em->bm->totedgesel == 0) { nr = NONE; - else if (em->bm->totfacesel == 0) + } + else if (em->bm->totfacesel == 0) { nr = EDGE_ONLY; - else + } + else { nr = ELEM_FLAG; + } } else { - if (em->bm->totfacesel == 0) + if (em->bm->totfacesel == 0) { nr = NONE; - else + } + else { nr = ELEM_FLAG; + } } switch (nr) { @@ -431,7 +440,7 @@ void MESH_OT_extrude_region(wmOperatorType *ot) ot->description = "Extrude region of faces"; /* api callbacks */ - //ot->invoke = mesh_extrude_region_invoke; + // ot->invoke = mesh_extrude_region_invoke; ot->exec = edbm_extrude_region_exec; ot->poll = ED_operator_editmesh; diff --git a/source/blender/editors/mesh/editmesh_extrude_screw.c b/source/blender/editors/mesh/editmesh_extrude_screw.c index c9422545c7b..252f95a10ac 100644 --- a/source/blender/editors/mesh/editmesh_extrude_screw.c +++ b/source/blender/editors/mesh/editmesh_extrude_screw.c @@ -125,8 +125,9 @@ static int edbm_screw_exec(bContext *C, wmOperator *op) sub_v3_v3v3(dvec, v1_co_global, v2_co_global); mul_v3_fl(dvec, 1.0f / steps); - if (dot_v3v3(nor, dvec) > 0.0f) + if (dot_v3v3(nor, dvec) > 0.0f) { negate_v3(dvec); + } BMOperator spinop; if (!EDBM_op_init( diff --git a/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c b/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c index 85be7d902ad..269ead7b23f 100644 --- a/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c +++ b/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c @@ -1018,7 +1018,8 @@ static void gizmo_mesh_spin_redo_draw_prepare(const bContext *UNUSED(C), wmGizmo ggd->data.op = WM_operator_last_redo((bContext *)ggd->data.context); } - /* Not essential, just avoids feedback loop where matrices could shift because of float precision. + /* Not essential, just avoids feedback loop where matrices + * could shift because of float precision. * Updates in this case are also redundant. */ bool is_modal = false; for (wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) { diff --git a/source/blender/editors/mesh/editmesh_inset.c b/source/blender/editors/mesh/editmesh_inset.c index 7bee030bb46..2955488a597 100644 --- a/source/blender/editors/mesh/editmesh_inset.c +++ b/source/blender/editors/mesh/editmesh_inset.c @@ -91,8 +91,9 @@ static void edbm_inset_update_header(wmOperator *op, bContext *C) if (sa) { char flts_str[NUM_STR_REP_LEN * 2]; - if (hasNumInput(&opdata->num_input)) + if (hasNumInput(&opdata->num_input)) { outputNumInput(&opdata->num_input, flts_str, &sce->unit); + } else { BLI_snprintf(flts_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "thickness")); BLI_snprintf( @@ -413,18 +414,21 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, const wmEvent *event) } /* Fake shift-transform... */ - if (opdata->shift) + if (opdata->shift) { amount = (amount - opdata->shift_amount) * 0.1f + opdata->shift_amount; + } - if (opdata->modify_depth) + if (opdata->modify_depth) { RNA_float_set(op->ptr, "depth", amount); + } else { amount = max_ff(amount, 0.0f); RNA_float_set(op->ptr, "thickness", amount); } - if (edbm_inset_calc(op)) + if (edbm_inset_calc(op)) { edbm_inset_update_header(op, C); + } else { edbm_inset_cancel(C, op); return OPERATOR_CANCELLED; @@ -446,10 +450,12 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, const wmEvent *event) case LEFTSHIFTKEY: case RIGHTSHIFTKEY: if (event->val == KM_PRESS) { - if (opdata->modify_depth) + if (opdata->modify_depth) { opdata->shift_amount = RNA_float_get(op->ptr, "depth"); - else + } + else { opdata->shift_amount = RNA_float_get(op->ptr, "thickness"); + } opdata->shift = true; handled = true; } @@ -469,14 +475,16 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, const wmEvent *event) if (event->val == KM_PRESS) { opdata->old_thickness = RNA_float_get(op->ptr, "thickness"); - if (opdata->shift) + if (opdata->shift) { opdata->shift_amount = opdata->old_thickness; + } opdata->modify_depth = true; } else { opdata->old_depth = RNA_float_get(op->ptr, "depth"); - if (opdata->shift) + if (opdata->shift) { opdata->shift_amount = opdata->old_depth; + } opdata->modify_depth = false; } opdata->initial_length = len_v2(mlen); diff --git a/source/blender/editors/mesh/editmesh_intersect.c b/source/blender/editors/mesh/editmesh_intersect.c index 06e2ef6e304..370cc6a2a6d 100644 --- a/source/blender/editors/mesh/editmesh_intersect.c +++ b/source/blender/editors/mesh/editmesh_intersect.c @@ -512,12 +512,15 @@ static int bm_edge_sort_length_cb(const void *e_a_v, const void *e_b_v) const float val_a = -BM_edge_calc_length_squared(*((BMEdge **)e_a_v)); const float val_b = -BM_edge_calc_length_squared(*((BMEdge **)e_b_v)); - if (val_a > val_b) + if (val_a > val_b) { return 1; - else if (val_a < val_b) + } + else if (val_a < val_b) { return -1; - else + } + else { return 0; + } } static void bm_face_split_by_edges_island_connect( diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index f4979c8f2a8..cc0c2f5bbe4 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -157,7 +157,7 @@ typedef struct KnifeTool_OpData { void *draw_handle; /* for drawing preview loop */ ViewContext vc; /* note: _don't_ use 'mval', instead use the one we define below */ float mval[2]; /* mouse value with snapping applied */ - //bContext *C; + // bContext *C; Scene *scene; Object *ob; @@ -366,8 +366,9 @@ static Ref *find_ref(ListBase *lb, void *ref) Ref *ref1; for (ref1 = lb->first; ref1; ref1 = ref1->next) { - if (ref1->ref == ref) + if (ref1->ref == ref) { return ref1; + } } return NULL; @@ -375,8 +376,9 @@ static Ref *find_ref(ListBase *lb, void *ref) static void knife_append_list_no_dup(KnifeTool_OpData *kcd, ListBase *lst, void *elem) { - if (!find_ref(lst, elem)) + if (!find_ref(lst, elem)) { knife_append_list(kcd, lst, elem); + } } static KnifeEdge *new_knife_edge(KnifeTool_OpData *kcd) @@ -410,8 +412,9 @@ static BMFace *knife_find_common_face(ListBase *faces1, ListBase *faces2) for (ref1 = faces1->first; ref1; ref1 = ref1->next) { for (ref2 = faces2->first; ref2; ref2 = ref2->next) { - if (ref1->ref == ref2->ref) + if (ref1->ref == ref2->ref) { return (BMFace *)(ref1->ref); + } } } return NULL; @@ -441,10 +444,12 @@ static KnifeVert *get_bm_knife_vert(KnifeTool_OpData *kcd, BMVert *v) BMIter bmiter; BMFace *f; - if (BM_elem_index_get(v) >= 0) + if (BM_elem_index_get(v) >= 0) { cageco = kcd->cagecos[BM_elem_index_get(v)]; - else + } + else { cageco = v->co; + } kfv = new_knife_vert(kcd, v->co, cageco); kfv->v = v; BLI_ghash_insert(kcd->origvertmap, v, kfv); @@ -493,8 +498,9 @@ static void set_lowest_face_tri(KnifeTool_OpData *kcd, BMFace *f, int index) { int i; - if (BLI_ghash_lookup(kcd->facetrimap, f)) + if (BLI_ghash_lookup(kcd->facetrimap, f)) { return; + } BLI_assert(index >= 0 && index < kcd->em->tottri); BLI_assert(kcd->em->looptris[index][0]->f == f); @@ -504,8 +510,9 @@ static void set_lowest_face_tri(KnifeTool_OpData *kcd, BMFace *f, int index) break; } } - if (i == -1) + if (i == -1) { i++; + } BLI_ghash_insert(kcd->facetrimap, f, POINTER_FROM_INT(i + 1)); } @@ -594,8 +601,9 @@ static KnifeVert *knife_split_edge(KnifeTool_OpData *kcd, * If v1 and v2 are in multiple faces together (e.g., if they * are in doubled polys) then this arbitrarily chooses one of them */ f = knife_find_common_face(&kfe->v1->faces, &kfe->v2->faces); - if (f) + if (f) { knife_append_list(kcd, &newkfe->v2->faces, f); + } } newkfe->basef = kfe->basef; @@ -605,8 +613,9 @@ static KnifeVert *knife_split_edge(KnifeTool_OpData *kcd, kfe->v1 = newkfe->v2; BLI_addtail(&kfe->v1->edges, ref); - for (ref = kfe->faces.first; ref; ref = ref->next) + for (ref = kfe->faces.first; ref; ref = ref->next) { knife_edge_append_face(kcd, newkfe, ref->ref); + } knife_add_to_vert_edges(kcd, newkfe); @@ -637,22 +646,29 @@ static int linehit_compare(const void *vlh1, const void *vlh2) const KnifeLineHit *lh1 = vlh1; const KnifeLineHit *lh2 = vlh2; - if (lh1->l < lh2->l) + if (lh1->l < lh2->l) { return -1; - else if (lh1->l > lh2->l) + } + else if (lh1->l > lh2->l) { return 1; + } else { - if (lh1->m < lh2->m) + if (lh1->m < lh2->m) { return -1; - else if (lh1->m > lh2->m) + } + else if (lh1->m > lh2->m) { return 1; + } else { - if (lh1->v < lh2->v) + if (lh1->v < lh2->v) { return -1; - else if (lh1->v > lh2->v) + } + else if (lh1->v > lh2->v) { return 1; - else + } + else { return 0; + } } } } @@ -670,8 +686,9 @@ static void prepare_linehits_for_cut(KnifeTool_OpData *kcd) n = kcd->totlinehit; linehits = kcd->linehits; - if (n == 0) + if (n == 0) { return; + } qsort(linehits, n, sizeof(KnifeLineHit), linehit_compare); @@ -725,8 +742,9 @@ static void prepare_linehits_for_cut(KnifeTool_OpData *kcd) memcpy(&linehits[i], &linehits[j], sizeof(KnifeLineHit)); } else { - if (i + 1 != j) + if (i + 1 != j) { memcpy(&linehits[i + 1], &linehits[j], sizeof(KnifeLineHit)); + } i++; } j++; @@ -851,8 +869,9 @@ static void knife_add_single_cut(KnifeTool_OpData *kcd, knife_add_to_vert_edges(kcd, kfe); /* TODO: check if this is ever needed */ - if (kfe->basef && !find_ref(&kfe->faces, kfe->basef)) + if (kfe->basef && !find_ref(&kfe->faces, kfe->basef)) { knife_edge_append_face(kcd, kfe, kfe->basef); + } } /* Given a list of KnifeLineHits for one face, sorted by l @@ -863,8 +882,9 @@ static void knife_cut_face(KnifeTool_OpData *kcd, BMFace *f, ListBase *hits) { Ref *r; - if (BLI_listbase_count_at_most(hits, 2) != 2) + if (BLI_listbase_count_at_most(hits, 2) != 2) { return; + } for (r = hits->first; r->next; r = r->next) { knife_add_single_cut(kcd, r->ref, r->next->ref, f); @@ -1167,8 +1187,9 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void BLI_mempool_iternew(kcd->kedges, &iter); for (kfe = BLI_mempool_iterstep(&iter); kfe; kfe = BLI_mempool_iterstep(&iter)) { - if (!kfe->is_cut) + if (!kfe->is_cut) { continue; + } immVertex3fv(pos, kfe->v1->cageco); immVertex3fv(pos, kfe->v2->cageco); @@ -1191,8 +1212,9 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void BLI_mempool_iternew(kcd->kverts, &iter); for (kfv = BLI_mempool_iterstep(&iter); kfv; kfv = BLI_mempool_iterstep(&iter)) { - if (!kfv->is_cut) + if (!kfv->is_cut) { continue; + } immVertex3fv(pos, kfv->cageco); } @@ -1249,8 +1271,9 @@ static bool knife_ray_intersect_face(KnifeTool_OpData *kcd, float ray_tri_uv[2]; tri = kcd->em->looptris[tri_i]; - if (tri[0]->f != f) + if (tri[0]->f != f) { break; + } lv1 = kcd->cagecos[BM_elem_index_get(tri[0]->v)]; lv2 = kcd->cagecos[BM_elem_index_get(tri[1]->v)]; lv3 = kcd->cagecos[BM_elem_index_get(tri[2]->v)]; @@ -1594,8 +1617,9 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd) * (which may involve using doubles everywhere!), * limit the distance between these points */ if (kcd->is_ortho && (kcd->vc.rv3d->persp != RV3D_CAMOB)) { - if (kcd->ortho_extent == 0.0f) + if (kcd->ortho_extent == 0.0f) { calc_ortho_extent(kcd); + } clip_to_ortho_planes(v1, v3, kcd->ortho_extent_center, kcd->ortho_extent + 10.0f); clip_to_ortho_planes(v2, v4, kcd->ortho_extent_center, kcd->ortho_extent + 10.0f); } @@ -1642,8 +1666,9 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd) lst = knife_get_face_kedges(kcd, f); for (ref = lst->first; ref; ref = ref->next) { kfe = ref->ref; - if (BLI_smallhash_haskey(&kfes, (uintptr_t)kfe)) + if (BLI_smallhash_haskey(&kfes, (uintptr_t)kfe)) { continue; + } BLI_smallhash_insert(&kfes, (uintptr_t)kfe, kfe); v = kfe->v1; BLI_smallhash_reinsert(&kfvs, (uintptr_t)v, v); @@ -1653,7 +1678,8 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd) } /* Now go through the candidates and find intersections */ - /* These tolerances, in screen space, are for intermediate hits, as ends are already snapped to screen */ + /* These tolerances, in screen space, are for intermediate hits, + * as ends are already snapped to screen. */ if (kcd->is_interactive) { vert_tol = KNIFE_FLT_EPS_PX_VERT; @@ -1663,8 +1689,8 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd) else { /* Use 1/100th of a pixel, see T43896 (too big), T47910 (too small). * - * Update, leave this as is until we investigate not using pixel coords for geometry calculations: T48023 - */ + * Update, leave this as is until we investigate not using pixel coords + * for geometry calculations: T48023. */ vert_tol = line_tol = face_tol = 0.5f; } @@ -1724,12 +1750,14 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd) if (isect_kind == -1) { /* isect_seg_seg_v2_simple doesn't do tolerance test around ends of s1-s2 */ closest_to_line_segment_v2(sint, s1, se1, se2); - if (len_squared_v2v2(sint, s1) <= line_tol_sq) + if (len_squared_v2v2(sint, s1) <= line_tol_sq) { isect_kind = 1; + } else { closest_to_line_segment_v2(sint, s2, se1, se2); - if (len_squared_v2v2(sint, s2) <= line_tol_sq) + if (len_squared_v2v2(sint, s2) <= line_tol_sq) { isect_kind = 1; + } } } if (isect_kind == 1) { @@ -1808,8 +1836,9 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd) BLI_smallhash_release(&kfes); BLI_smallhash_release(&kfvs); BLI_bvhtree_free(planetree); - if (results) + if (results) { MEM_freeN(results); + } } static void knife_input_ray_segment(KnifeTool_OpData *kcd, @@ -1851,8 +1880,9 @@ static BMFace *knife_find_closest_face(KnifeTool_OpData *kcd, f = NULL; } - if (is_space) + if (is_space) { *is_space = !f; + } if (!f) { if (kcd->is_interactive) { @@ -2024,8 +2054,9 @@ static KnifeEdge *knife_find_closest_edge( copy_v3_v3(cur_cagep, test_cagep); } - if (fptr) + if (fptr) { *fptr = f; + } if (cure) { if (!kcd->ignore_edge_snapping || !(cure->e)) { @@ -2055,8 +2086,9 @@ static KnifeEdge *knife_find_closest_edge( return cure; } - if (fptr) + if (fptr) { *fptr = NULL; + } return NULL; } @@ -2132,8 +2164,9 @@ static KnifeVert *knife_find_closest_vert( } if (!kcd->ignore_vert_snapping || !(curv && curv->v)) { - if (fptr) + if (fptr) { *fptr = f; + } if (curv) { copy_v3_v3(p, curv->co); @@ -2148,15 +2181,17 @@ static KnifeVert *knife_find_closest_vert( return curv; } else { - if (fptr) + if (fptr) { *fptr = f; + } return NULL; } } - if (fptr) + if (fptr) { *fptr = NULL; + } return NULL; } @@ -2261,12 +2296,15 @@ static int sort_verts_by_dist_cb(void *co_p, const void *cur_a_p, const void *cu const float a_sq = len_squared_v3v3(co, cur_a->co); const float b_sq = len_squared_v3v3(co, cur_b->co); - if (a_sq < b_sq) + if (a_sq < b_sq) { return -1; - else if (a_sq > b_sq) + } + else if (a_sq > b_sq) { return 1; - else + } + else { return 0; + } } static bool knife_verts_edge_in_face(KnifeVert *v1, KnifeVert *v2, BMFace *f) @@ -2275,8 +2313,9 @@ static bool knife_verts_edge_in_face(KnifeVert *v1, KnifeVert *v2, BMFace *f) bool v1_inface, v2_inface; BMLoop *l1, *l2; - if (!f || !v1 || !v2) + if (!f || !v1 || !v2) { return false; + } l1 = v1->v ? BM_face_vert_share_loop(f, v1->v) : NULL; l2 = v2->v ? BM_face_vert_share_loop(f, v2->v) : NULL; @@ -2453,8 +2492,9 @@ static void knife_make_cuts(KnifeTool_OpData *kcd) } f = kfe->basef; - if (!f || kfe->e) + if (!f || kfe->e) { continue; + } lst = BLI_smallhash_lookup(fhash, (uintptr_t)f); if (!lst) { lst = knife_empty_list(kcd); @@ -2466,21 +2506,24 @@ static void knife_make_cuts(KnifeTool_OpData *kcd) /* put list of splitting vertices for an edge into ehash, keyed by edge */ BLI_mempool_iternew(kcd->kverts, &iter); for (kfv = BLI_mempool_iterstep(&iter); kfv; kfv = BLI_mempool_iterstep(&iter)) { - if (kfv->v) + if (kfv->v) { continue; /* already have a BMVert */ + } for (ref = kfv->edges.first; ref; ref = ref->next) { kfe = ref->ref; e = kfe->e; - if (!e) + if (!e) { continue; + } lst = BLI_smallhash_lookup(ehash, (uintptr_t)e); if (!lst) { lst = knife_empty_list(kcd); BLI_smallhash_insert(ehash, (uintptr_t)e, lst); } /* there can be more than one kfe in kfv's list with same e */ - if (!find_ref(lst, kfv)) + if (!find_ref(lst, kfv)) { knife_append_list(kcd, lst, kfv); + } } } @@ -2544,8 +2587,9 @@ static void knife_recalc_projmat(KnifeTool_OpData *kcd) /* called when modal loop selection is done... */ static void knifetool_exit_ex(bContext *C, KnifeTool_OpData *kcd) { - if (!kcd) + if (!kcd) { return; + } if (kcd->is_interactive) { WM_cursor_modal_restore(CTX_wm_window(C)); @@ -2575,8 +2619,9 @@ static void knifetool_exit_ex(bContext *C, KnifeTool_OpData *kcd) knifetool_free_bmbvh(kcd); - if (kcd->linehits) + if (kcd->linehits) { MEM_freeN(kcd->linehits); + } /* destroy kcd itself */ MEM_freeN(kcd); @@ -2773,8 +2818,9 @@ wmKeyMap *knifetool_modal_keymap(wmKeyConfig *keyconf) wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "Knife Tool Modal Map"); /* this function is called for each spacetype, only needs to add map once */ - if (keymap && keymap->modal_items) + if (keymap && keymap->modal_items) { return NULL; + } keymap = WM_modalkeymap_add(keyconf, "Knife Tool Modal Map", modal_items); @@ -2801,8 +2847,9 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event) view3d_operator_needs_opengl(C); ED_view3d_init_mats_rv3d(obedit, kcd->vc.rv3d); /* needed to initialize clipping */ - if (kcd->mode == MODE_PANNING) + if (kcd->mode == MODE_PANNING) { kcd->mode = kcd->prevmode; + } /* handle modal keymap */ if (event->type == EVT_MODAL_MAP) { diff --git a/source/blender/editors/mesh/editmesh_loopcut.c b/source/blender/editors/mesh/editmesh_loopcut.c index d0988811d15..528235e693a 100644 --- a/source/blender/editors/mesh/editmesh_loopcut.c +++ b/source/blender/editors/mesh/editmesh_loopcut.c @@ -545,8 +545,9 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event) case RETKEY: case PADENTER: case LEFTMOUSE: /* confirm */ // XXX hardcoded - if (event->val == KM_PRESS) + if (event->val == KM_PRESS) { return loopcut_finish(lcd, C, op); + } ED_region_tag_redraw(lcd->ar); handled = true; @@ -573,8 +574,9 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event) case MOUSEPAN: if (event->alt == 0) { cuts += 0.02f * (event->y - event->prevy); - if (cuts < 1 && lcd->cuts >= 1) + if (cuts < 1 && lcd->cuts >= 1) { cuts = 1; + } } else { smoothness += 0.002f * (event->y - event->prevy); @@ -584,8 +586,9 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event) case PADPLUSKEY: case PAGEUPKEY: case WHEELUPMOUSE: /* change number of cuts */ - if (event->val == KM_RELEASE) + if (event->val == KM_RELEASE) { break; + } if (event->alt == 0) { cuts += 1; } @@ -597,8 +600,9 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event) case PADMINUS: case PAGEDOWNKEY: case WHEELDOWNMOUSE: /* change number of cuts */ - if (event->val == KM_RELEASE) + if (event->val == KM_RELEASE) { break; + } if (event->alt == 0) { cuts = max_ff(cuts - 1, 1); } diff --git a/source/blender/editors/mesh/editmesh_path.c b/source/blender/editors/mesh/editmesh_path.c index c6b1ab9f1f2..f8ec4334427 100644 --- a/source/blender/editors/mesh/editmesh_path.c +++ b/source/blender/editors/mesh/editmesh_path.c @@ -281,10 +281,12 @@ static void edgetag_set_cb(BMEdge *e, bool val, void *user_data_v) case EDGE_MODE_TAG_FREESTYLE: { FreestyleEdge *fed; fed = CustomData_bmesh_get(&bm->edata, e->head.data, CD_FREESTYLE_EDGE); - if (!val) + if (!val) { fed->flag &= ~FREESTYLE_EDGE_MARK; - else + } + else { fed->flag |= FREESTYLE_EDGE_MARK; + } break; } #endif @@ -396,8 +398,9 @@ static void mouse_mesh_shortest_path_edge(Scene *UNUSED(scene), if (op_params->edge_mode != EDGE_MODE_SELECT) { if (op_params->track_active) { /* simple rules - last edge is _always_ active and selected */ - if (e_act) + if (e_act) { BM_edge_select_set(bm, e_act, false); + } BM_edge_select_set(bm, e_dst_last, true); BM_select_history_store(bm, e_dst_last); } @@ -408,10 +411,12 @@ static void mouse_mesh_shortest_path_edge(Scene *UNUSED(scene), if (op_params->track_active) { /* even if this is selected it may not be in the selection list */ if (op_params->edge_mode == EDGE_MODE_SELECT) { - if (edgetag_test_cb(e_dst_last, &user_data) == 0) + if (edgetag_test_cb(e_dst_last, &user_data) == 0) { BM_select_history_remove(bm, e_dst_last); - else + } + else { BM_select_history_store(bm, e_dst_last); + } } } @@ -429,12 +434,12 @@ static bool facetag_filter_cb(BMFace *f, void *UNUSED(user_data_v)) { return !BM_elem_flag_test(f, BM_ELEM_HIDDEN); } -//static bool facetag_test_cb(Scene *UNUSED(scene), BMesh *UNUSED(bm), BMFace *f) +// static bool facetag_test_cb(Scene *UNUSED(scene), BMesh *UNUSED(bm), BMFace *f) static bool facetag_test_cb(BMFace *f, void *UNUSED(user_data_v)) { return BM_elem_flag_test_bool(f, BM_ELEM_SELECT); } -//static void facetag_set_cb(BMesh *bm, Scene *UNUSED(scene), BMFace *f, const bool val) +// static void facetag_set_cb(BMesh *bm, Scene *UNUSED(scene), BMFace *f, const bool val) static void facetag_set_cb(BMFace *f, bool val, void *user_data_v) { struct UserData *user_data = user_data_v; @@ -777,12 +782,15 @@ static int edbm_shortest_path_select_exec(bContext *C, wmOperator *op) if ((em->selectmode & SCE_SELECT_VERTEX) && (bm->totvertsel >= 2)) { BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) { if (BM_elem_flag_test(ele, BM_ELEM_SELECT)) { - if (ele_src == NULL) + if (ele_src == NULL) { ele_src = ele; - else if (ele_dst == NULL) + } + else if (ele_dst == NULL) { ele_dst = ele; - else + } + else { break; + } } } } @@ -791,12 +799,15 @@ static int edbm_shortest_path_select_exec(bContext *C, wmOperator *op) ele_src = NULL; BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) { if (BM_elem_flag_test(ele, BM_ELEM_SELECT)) { - if (ele_src == NULL) + if (ele_src == NULL) { ele_src = ele; - else if (ele_dst == NULL) + } + else if (ele_dst == NULL) { ele_dst = ele; - else + } + else { break; + } } } } @@ -805,12 +816,15 @@ static int edbm_shortest_path_select_exec(bContext *C, wmOperator *op) ele_src = NULL; BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) { if (BM_elem_flag_test(ele, BM_ELEM_SELECT)) { - if (ele_src == NULL) + if (ele_src == NULL) { ele_src = ele; - else if (ele_dst == NULL) + } + else if (ele_dst == NULL) { ele_dst = ele; - else + } + else { break; + } } } } diff --git a/source/blender/editors/mesh/editmesh_preselect_edgering.c b/source/blender/editors/mesh/editmesh_preselect_edgering.c index b007343e14e..92a8c7da71d 100644 --- a/source/blender/editors/mesh/editmesh_preselect_edgering.c +++ b/source/blender/editors/mesh/editmesh_preselect_edgering.c @@ -93,8 +93,9 @@ static void edgering_find_order(BMEdge *eed_last, BMEdge *eed, BMVert *eve_last, if (!(BM_edge_in_face(eed, l->f) && BM_edge_in_face(eed_last, l->f))) { BMIter liter; BM_ITER_ELEM (l, &liter, l, BM_LOOPS_OF_LOOP) { - if (BM_edge_in_face(eed, l->f) && BM_edge_in_face(eed_last, l->f)) + if (BM_edge_in_face(eed, l->f) && BM_edge_in_face(eed_last, l->f)) { break; + } } } diff --git a/source/blender/editors/mesh/editmesh_rip.c b/source/blender/editors/mesh/editmesh_rip.c index 42521d04008..ffdb434405e 100644 --- a/source/blender/editors/mesh/editmesh_rip.c +++ b/source/blender/editors/mesh/editmesh_rip.c @@ -86,8 +86,7 @@ static float edbm_rip_edgedist_squared(ARegion *ar, #if 0 static float edbm_rip_linedist( - ARegion *ar, float mat[4][4], - const float co1[3], const float co2[3], const float mvalf[2]) + ARegion *ar, float mat[4][4], const float co1[3], const float co2[3], const float mvalf[2]) { float vec1[2], vec2[2]; @@ -171,23 +170,26 @@ static float edbm_rip_edge_side_measure( * * The method used for checking the side of selection is as follows... * - First tag all rip-able edges. - * - Build a contiguous edge list by looping over tagged edges and following each ones tagged siblings in both - * directions. - * - The loops are not stored in an array, Instead both loops on either side of each edge has its index values set - * to count down from the last edge, this way, once we have the 'last' edge its very easy to walk down the - * connected edge loops. - * The reason for using loops like this is because when the edges are split we don't which face user gets the newly - * created edge (its as good as random so we cant assume new edges will be on once side). - * After splitting, its very simple to walk along boundary loops since each only has one edge from a single side. - * - The end loop pairs are stored in an array however to support multiple edge-selection-islands, so you can rip - * multiple selections at once. + * - Build a contiguous edge list by looping over tagged edges and following each ones tagged + * siblings in both directions. + * - The loops are not stored in an array, Instead both loops on either side of each edge has + * its index values set to count down from the last edge, this way, once we have the 'last' + * edge its very easy to walk down the connected edge loops. + * The reason for using loops like this is because when the edges are split we don't which + * face user gets the newly created edge + * (its as good as random so we cant assume new edges will be on once side). + * After splitting, its very simple to walk along boundary loops since each only has one edge + * from a single side. + * - The end loop pairs are stored in an array however to support multiple edge-selection-islands, + * so you can rip multiple selections at once. * - * Execute the split * - * - For each #EdgeLoopPair walk down both sides of the split using the loops and measure which is facing the mouse. + * - For each #EdgeLoopPair walk down both sides of the split using the loops and measure + * which is facing the mouse. * - Deselect the edge loop facing away. * * Limitation! - * This currently works very poorly with intersecting edge islands (verts with more than 2 tagged edges) - * This is nice to but for now not essential. + * This currently works very poorly with intersecting edge islands + * (verts with more than 2 tagged edges). This is nice to but for now not essential. * * - campbell. */ @@ -540,8 +542,9 @@ static int edbm_rip_invoke__vert(bContext *C, const wmEvent *event, Object *obed ese.ele = NULL; BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { - if (BM_elem_flag_test(v, BM_ELEM_SELECT)) + if (BM_elem_flag_test(v, BM_ELEM_SELECT)) { break; + } } } @@ -810,8 +813,9 @@ static int edbm_rip_invoke__vert(bContext *C, const wmEvent *event, Object *obed BM_vert_select_set(bm, v_rip, true); } else { - if (fill_uloop_pairs) + if (fill_uloop_pairs) { MEM_freeN(fill_uloop_pairs); + } return OPERATOR_CANCELLED; } } @@ -905,6 +909,9 @@ static int edbm_rip_invoke__edge(bContext *C, const wmEvent *event, Object *obed if (BM_elem_flag_test(e, BM_ELEM_SELECT)) { e_best = e; i++; + /* Tag the edge verts so we know which verts to rip */ + BM_elem_flag_enable(e->v1, BM_ELEM_TAG); + BM_elem_flag_enable(e->v2, BM_ELEM_TAG); } totedge_manifold++; } @@ -932,13 +939,14 @@ static int edbm_rip_invoke__edge(bContext *C, const wmEvent *event, Object *obed l_b; l = BM_loop_other_edge_loop(l, v); - /* important edge is manifold else we can be attempting to split off a fan that don't budge, - * not crashing but adds duplicate edge. */ + /* Important edge is manifold else we can be attempting to split off + * a fan that don't budge, not crashing but adds duplicate edge. */ if (BM_edge_is_manifold(l->e)) { l = l->radial_next; - if (totedge_manifold != 3) + if (totedge_manifold != 3) { l = BM_loop_other_edge_loop(l, v); + } if (l) { BLI_assert(!BM_elem_flag_test(l->e, BM_ELEM_TAG)); diff --git a/source/blender/editors/mesh/editmesh_rip_edge.c b/source/blender/editors/mesh/editmesh_rip_edge.c index e2b77d8c83b..61253f06f9f 100644 --- a/source/blender/editors/mesh/editmesh_rip_edge.c +++ b/source/blender/editors/mesh/editmesh_rip_edge.c @@ -71,8 +71,9 @@ static int edbm_rip_edge_invoke(bContext *C, wmOperator *UNUSED(op), const wmEve float projectMat[4][4]; - if (bm->totvertsel == 0) + if (bm->totvertsel == 0) { continue; + } ED_view3d_ob_project_mat_get(rv3d, obedit, projectMat); diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index 94886266d24..9df03a81762 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -110,8 +110,9 @@ void EDBM_select_mirrored( EDBM_verts_mirror_cache_begin(em, axis, true, true, use_topology); - if (!extend) + if (!extend) { EDBM_flag_disable_all(em, BM_ELEM_SELECT); + } if (bm->selectmode & SCE_SELECT_VERTEX) { BMVert *v; @@ -241,19 +242,22 @@ bool EDBM_backbuf_check(unsigned int index) /* odd logic, if selbuf is NULL we assume no zbuf-selection is enabled * and just ignore the depth buffer, this is error prone since its possible * code doesn't set the depth buffer by accident, but leave for now. - Campbell */ - if (selbuf == NULL) + if (selbuf == NULL) { return true; + } - if (index > 0 && index <= bm_vertoffs) + if (index > 0 && index <= bm_vertoffs) { return BLI_BITMAP_TEST_BOOL(selbuf, index); + } return false; } void EDBM_backbuf_free(void) { - if (selbuf) + if (selbuf) { MEM_freeN(selbuf); + } selbuf = NULL; } @@ -458,7 +462,8 @@ static void findnearestvert__doClosest(void *userData, * * \param r_dist: (in/out), minimal distance to the nearest and at the end, actual distance * \param use_select_bias: - * - When true, selected vertices are given a 5 pixel bias to make them further than unselect verts. + * - When true, selected vertices are given a 5 pixel bias + * to make them further than unselect verts. * - When false, unselected vertices are given the bias. * \param use_cycle: Cycle over elements within #FIND_NEAR_CYCLE_THRESHOLD_MIN in order of index. */ @@ -1173,9 +1178,7 @@ bool EDBM_unified_findnearest_from_raycast(ViewContext *vc, float point[3]; #if 0 const float dist_sq_test = dist_squared_ray_to_seg_v3( - ray_origin, ray_direction, - e->v1->co, e->v2->co, - point, &depth); + ray_origin, ray_direction, e->v1->co, e->v2->co, point, &depth); #else if (coords) { mid_v3_v3v3( @@ -1425,10 +1428,12 @@ static int edbm_select_mode_invoke(bContext *C, wmOperator *op, const wmEvent *e /* detecting these options based on shift/ctrl here is weak, but it's done * to make this work when clicking buttons or menus */ - if (!RNA_struct_property_is_set(op->ptr, "use_extend")) + if (!RNA_struct_property_is_set(op->ptr, "use_extend")) { RNA_boolean_set(op->ptr, "use_extend", event->shift); - if (!RNA_struct_property_is_set(op->ptr, "use_expand")) + } + if (!RNA_struct_property_is_set(op->ptr, "use_expand")) { RNA_boolean_set(op->ptr, "use_expand", event->ctrl); + } return edbm_select_mode_exec(C, op); } @@ -1801,7 +1806,8 @@ static bool mouse_mesh_loop( length_2 = len_squared_v2v2(mvalf, v2_co); } #if 0 - printf("mouse to v1: %f\nmouse to v2: %f\n", len_squared_v2v2(mvalf, v1_co), + printf("mouse to v1: %f\nmouse to v2: %f\n", + len_squared_v2v2(mvalf, v1_co), len_squared_v2v2(mvalf, v2_co)); #endif BM_select_history_store(em->bm, (length_1 < length_2) ? eed->v1 : eed->v2); @@ -2205,8 +2211,9 @@ static void edbm_strip_selections(BMEditMesh *em) ese = em->bm->selected.first; while (ese) { nextese = ese->next; - if (ese->htype == BM_VERT) + if (ese->htype == BM_VERT) { BLI_freelinkN(&(em->bm->selected), ese); + } ese = nextese; } } @@ -2214,8 +2221,9 @@ static void edbm_strip_selections(BMEditMesh *em) ese = em->bm->selected.first; while (ese) { nextese = ese->next; - if (ese->htype == BM_EDGE) + if (ese->htype == BM_EDGE) { BLI_freelinkN(&(em->bm->selected), ese); + } ese = nextese; } } @@ -2223,8 +2231,9 @@ static void edbm_strip_selections(BMEditMesh *em) ese = em->bm->selected.first; while (ese) { nextese = ese->next; - if (ese->htype == BM_FACE) + if (ese->htype == BM_FACE) { BLI_freelinkN(&(em->bm->selected), ese); + } ese = nextese; } } @@ -2576,8 +2585,9 @@ bool EDBM_deselect_by_material(BMEditMesh *em, const short index, const bool sel bool changed = false; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) + if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { continue; + } if (efa->mat_nr == index) { changed = true; BM_face_select_set(em->bm, efa, select); @@ -2588,10 +2598,12 @@ bool EDBM_deselect_by_material(BMEditMesh *em, const short index, const bool sel void EDBM_select_toggle_all(BMEditMesh *em) /* exported for UV */ { - if (em->bm->totvertsel || em->bm->totedgesel || em->bm->totfacesel) + if (em->bm->totvertsel || em->bm->totedgesel || em->bm->totfacesel) { EDBM_flag_disable_all(em, BM_ELEM_SELECT); - else + } + else { EDBM_flag_enable_all(em, BM_ELEM_SELECT); + } } void EDBM_select_swap(BMEditMesh *em) /* exported for UV */ @@ -2603,22 +2615,25 @@ void EDBM_select_swap(BMEditMesh *em) /* exported for UV */ if (em->bm->selectmode & SCE_SELECT_VERTEX) { BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { - if (BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) + if (BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) { continue; + } BM_vert_select_set(em->bm, eve, !BM_elem_flag_test(eve, BM_ELEM_SELECT)); } } else if (em->selectmode & SCE_SELECT_EDGE) { BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) + if (BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) { continue; + } BM_edge_select_set(em->bm, eed, !BM_elem_flag_test(eed, BM_ELEM_SELECT)); } } else { BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) + if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { continue; + } BM_face_select_set(em->bm, efa, !BM_elem_flag_test(efa, BM_ELEM_SELECT)); } } @@ -2675,8 +2690,9 @@ bool EDBM_select_interior_faces(BMEditMesh *em) bool changed = false; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) + if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { continue; + } ok = true; BM_ITER_ELEM (eed, &eiter, efa, BM_EDGES_OF_FACE) { @@ -4602,8 +4618,9 @@ static int edbm_region_to_loop_exec(bContext *C, wmOperator *UNUSED(op)) totsel += BM_elem_flag_test(l2->f, BM_ELEM_SELECT) != 0; } - if ((tot != totsel && totsel > 0) || (totsel == 1 && tot == 1)) + if ((tot != totsel && totsel > 0) || (totsel == 1 && tot == 1)) { BM_elem_flag_enable(l1->e, BM_ELEM_TAG); + } } } @@ -4671,8 +4688,9 @@ static int loop_find_region(BMLoop *l, int flag, GSet *visit_face_set, BMFace ** BLI_array_append(region, f); BM_ITER_ELEM (l1, &liter1, f, BM_LOOPS_OF_FACE) { - if (BM_elem_flag_test(l1->e, flag)) + if (BM_elem_flag_test(l1->e, flag)) { continue; + } BM_ITER_ELEM (l2, &liter2, l1->e, BM_LOOPS_OF_EDGE) { /* avoids finding same region twice @@ -4702,10 +4720,12 @@ static int verg_radial(const void *va, const void *vb) const int a = BM_edge_face_count(e_a); const int b = BM_edge_face_count(e_b); - if (a > b) + if (a > b) { return -1; - if (a < b) + } + if (a < b) { return 1; + } return 0; } @@ -4748,12 +4768,14 @@ static int loop_find_regions(BMEditMesh *em, const bool selbigger) e = edges[i]; - if (!BM_elem_flag_test(e, BM_ELEM_TAG)) + if (!BM_elem_flag_test(e, BM_ELEM_TAG)) { continue; + } BM_ITER_ELEM (l, &liter, e, BM_LOOPS_OF_EDGE) { - if (BLI_gset_haskey(visit_face_set, l->f)) + if (BLI_gset_haskey(visit_face_set, l->f)) { continue; + } c = loop_find_region(l, BM_ELEM_SELECT, visit_face_set, ®ion_out); diff --git a/source/blender/editors/mesh/editmesh_select_similar.c b/source/blender/editors/mesh/editmesh_select_similar.c index 3006e2ed73d..2782cc92aca 100644 --- a/source/blender/editors/mesh/editmesh_select_similar.c +++ b/source/blender/editors/mesh/editmesh_select_similar.c @@ -1218,12 +1218,15 @@ static int edbm_select_similar_exec(bContext *C, wmOperator *op) ts->select_thresh = RNA_property_float_get(op->ptr, prop); } - if (type < 100) + if (type < 100) { return similar_vert_select_exec(C, op); - else if (type < 200) + } + else if (type < 200) { return similar_edge_select_exec(C, op); - else + } + else { return similar_face_select_exec(C, op); + } } static const EnumPropertyItem *select_similar_type_itemf(bContext *C, @@ -1233,8 +1236,9 @@ static const EnumPropertyItem *select_similar_type_itemf(bContext *C, { Object *obedit; - if (!C) /* needed for docs and i18n tools */ + if (!C) { /* needed for docs and i18n tools */ return prop_similar_types; + } obedit = CTX_data_edit_object(C); diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 79bbf021829..cd9d046ae04 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -885,8 +885,9 @@ static void edbm_add_edge_face_exec__tricky_finalize_sel(BMesh *bm, BMElem *ele_ BM_select_history_clear(bm); /* Notes on hidden geometry: - * - un-hide the face since its possible hidden was copied when copying surrounding face attributes. - * - un-hide before adding to select history + * - Un-hide the face since its possible hidden was copied when copying + * surrounding face attributes. + * - Un-hide before adding to select history * since we may extend into an existing, hidden vert/edge. */ @@ -946,8 +947,8 @@ static int edbm_add_edge_face_exec(bContext *C, wmOperator *op) BMElem *ele_desel; BMFace *ele_desel_face; - /* be extra clever, figure out if a partial selection should be extended so we can create geometry - * with single vert or single edge selection */ + /* be extra clever, figure out if a partial selection should be extended so we can create + * geometry with single vert or single edge selection. */ ele_desel = edbm_add_edge_face_exec__tricky_extend_sel(em->bm); #endif if (!EDBM_op_init(em, @@ -980,7 +981,8 @@ static int edbm_add_edge_face_exec(bContext *C, wmOperator *op) /* Newly created faces may include existing hidden edges, * copying face data from surrounding, may have copied hidden face flag too. * - * Important that faces use flushing since 'edges.out' wont include hidden edges that already existed. + * Important that faces use flushing since 'edges.out' + * wont include hidden edges that already existed. */ BMO_slot_buffer_hflag_disable( em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_HIDDEN, true); @@ -2207,7 +2209,7 @@ static int edbm_normals_make_consistent_exec(bContext *C, wmOperator *op) void MESH_OT_normals_make_consistent(wmOperatorType *ot) { /* identifiers */ - ot->name = "Make Normals Consistent"; + ot->name = "Recalculate Normals"; ot->description = "Make face and vertex normals point either outside or inside the mesh"; ot->idname = "MESH_OT_normals_make_consistent"; @@ -2271,12 +2273,15 @@ static int edbm_do_smooth_vertex_exec(bContext *C, wmOperator *op) MirrorModifierData *mmd = (MirrorModifierData *)md; if (mmd->flag & MOD_MIR_CLIPPING) { - if (mmd->flag & MOD_MIR_AXIS_X) + if (mmd->flag & MOD_MIR_AXIS_X) { mirrx = true; - if (mmd->flag & MOD_MIR_AXIS_Y) + } + if (mmd->flag & MOD_MIR_AXIS_Y) { mirry = true; - if (mmd->flag & MOD_MIR_AXIS_Z) + } + if (mmd->flag & MOD_MIR_AXIS_Z) { mirrz = true; + } clip_dist = mmd->tolerance; } @@ -2496,8 +2501,9 @@ static void mesh_set_smooth_faces(BMEditMesh *em, short smooth) BMIter iter; BMFace *efa; - if (em == NULL) + if (em == NULL) { return; + } BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) { @@ -2768,7 +2774,7 @@ void MESH_OT_uvs_reverse(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ - //RNA_def_enum(ot->srna, "axis", axis_items, DIRECTION_CW, "Axis", "Axis to mirror UVs around"); + // RNA_def_enum(ot->srna, "axis", axis_items, DIRECTION_CW, "Axis", "Axis to mirror UVs around"); } void MESH_OT_colors_rotate(wmOperatorType *ot) @@ -2804,7 +2810,9 @@ void MESH_OT_colors_reverse(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ - //RNA_def_enum(ot->srna, "axis", axis_items, DIRECTION_CW, "Axis", "Axis to mirror colors around"); +#if 0 + RNA_def_enum(ot->srna, "axis", axis_items, DIRECTION_CW, "Axis", "Axis to mirror colors around"); +#endif } /** \} */ @@ -2835,31 +2843,37 @@ static bool merge_firstlast(BMEditMesh *em, /* do sanity check in mergemenu in edit.c ?*/ if (use_first == false) { - if (!em->bm->selected.last || ((BMEditSelection *)em->bm->selected.last)->htype != BM_VERT) + if (!em->bm->selected.last || ((BMEditSelection *)em->bm->selected.last)->htype != BM_VERT) { return false; + } ese = em->bm->selected.last; mergevert = (BMVert *)ese->ele; } else { - if (!em->bm->selected.first || ((BMEditSelection *)em->bm->selected.first)->htype != BM_VERT) + if (!em->bm->selected.first || ((BMEditSelection *)em->bm->selected.first)->htype != BM_VERT) { return false; + } ese = em->bm->selected.first; mergevert = (BMVert *)ese->ele; } - if (!BM_elem_flag_test(mergevert, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(mergevert, BM_ELEM_SELECT)) { return false; + } if (use_uvmerge) { if (!EDBM_op_callf( - em, wmop, "pointmerge_facedata verts=%hv vert_snap=%e", BM_ELEM_SELECT, mergevert)) + em, wmop, "pointmerge_facedata verts=%hv vert_snap=%e", BM_ELEM_SELECT, mergevert)) { return false; + } } - if (!EDBM_op_callf(em, wmop, "pointmerge verts=%hv merge_co=%v", BM_ELEM_SELECT, mergevert->co)) + if (!EDBM_op_callf( + em, wmop, "pointmerge verts=%hv merge_co=%v", BM_ELEM_SELECT, mergevert->co)) { return false; + } return true; } @@ -2886,14 +2900,16 @@ static bool merge_target(BMEditMesh *em, float fac; int i = 0; BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { - if (!BM_elem_flag_test(v, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(v, BM_ELEM_SELECT)) { continue; + } add_v3_v3(cent, v->co); i++; } - if (!i) + if (!i) { return false; + } fac = 1.0f / (float)i; mul_v3_fl(cent, fac); @@ -2901,16 +2917,19 @@ static bool merge_target(BMEditMesh *em, vco = co; } - if (!vco) + if (!vco) { return false; + } if (use_uvmerge) { - if (!EDBM_op_callf(em, wmop, "average_vert_facedata verts=%hv", BM_ELEM_SELECT)) + if (!EDBM_op_callf(em, wmop, "average_vert_facedata verts=%hv", BM_ELEM_SELECT)) { return false; + } } - if (!EDBM_op_callf(em, wmop, "pointmerge verts=%hv merge_co=%v", BM_ELEM_SELECT, co)) + if (!EDBM_op_callf(em, wmop, "pointmerge verts=%hv merge_co=%v", BM_ELEM_SELECT, co)) { return false; + } return true; } @@ -2994,8 +3013,9 @@ static const EnumPropertyItem *merge_type_itemf(bContext *C, EnumPropertyItem *item = NULL; int totitem = 0; - if (!C) /* needed for docs */ + if (!C) { /* needed for docs */ return merge_type_items; + } obedit = CTX_data_edit_object(C); if (obedit && obedit->type == OB_MESH) { @@ -3092,12 +3112,15 @@ static int edbm_remove_doubles_exec(bContext *C, wmOperator *op) /* avoid losing selection state (select -> tags) */ char htype_select; - if (em->selectmode & SCE_SELECT_VERTEX) + if (em->selectmode & SCE_SELECT_VERTEX) { htype_select = BM_VERT; - else if (em->selectmode & SCE_SELECT_EDGE) + } + else if (em->selectmode & SCE_SELECT_EDGE) { htype_select = BM_EDGE; - else + } + else { htype_select = BM_FACE; + } /* store selection as tags */ BM_mesh_elem_hflag_enable_test(em->bm, htype_select, BM_ELEM_TAG, true, true, BM_ELEM_SELECT); @@ -3146,8 +3169,8 @@ static int edbm_remove_doubles_exec(bContext *C, wmOperator *op) void MESH_OT_remove_doubles(wmOperatorType *ot) { /* identifiers */ - ot->name = "Remove Doubles"; - ot->description = "Remove duplicate vertices"; + ot->name = "Merge by Distance"; + ot->description = "Merge vertices based on their proximity"; ot->idname = "MESH_OT_remove_doubles"; /* api callbacks */ @@ -3330,8 +3353,9 @@ static int edbm_blend_from_shape_exec(bContext *C, wmOperator *op) if (kb) { /* Perform blending on selected vertices. */ BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { - if (!BM_elem_flag_test(eve, BM_ELEM_SELECT) || BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) + if (!BM_elem_flag_test(eve, BM_ELEM_SELECT) || BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) { continue; + } /* Get coordinates of shapekey we're blending from. */ sco = CustomData_bmesh_get_n(&em->bm->vdata, eve->head.data, CD_SHAPEKEY, shape); @@ -3381,8 +3405,9 @@ static const EnumPropertyItem *shape_itemf(bContext *C, int a; for (a = 0; a < em->bm->vdata.totlayer; a++) { - if (em->bm->vdata.layers[a].type != CD_SHAPEKEY) + if (em->bm->vdata.layers[a].type != CD_SHAPEKEY) { continue; + } tmp.value = totitem; tmp.identifier = em->bm->vdata.layers[a].name; @@ -3425,7 +3450,8 @@ void MESH_OT_blend_from_shape(wmOperatorType *ot) /* api callbacks */ ot->exec = edbm_blend_from_shape_exec; - // ot->invoke = WM_operator_props_popup_call; /* disable because search popup closes too easily */ + /* disable because search popup closes too easily */ + // ot->invoke = WM_operator_props_popup_call; ot->ui = edbm_blend_from_shape_ui; ot->poll = ED_operator_editmesh; @@ -3547,7 +3573,7 @@ static float bm_edge_seg_isect(const float sco_a[2], float threshold = 0.0; int i; - //threshold = 0.000001; /* tolerance for vertex intersection */ + // threshold = 0.000001; /* tolerance for vertex intersection */ // XXX threshold = scene->toolsettings->select_thresh / 100; /* Get screen coords of verts */ @@ -3616,11 +3642,13 @@ static float bm_edge_seg_isect(const float sco_a[2], /* sqrt(m2 * m2 + 1); Only looking for change in sign. Skip extra math .*/ dist = (y12 - m2 * x12 - b2); } - else + else { dist = x22 - x12; + } - if (i == 0) + if (i == 0) { lastdist = dist; + } /* if dist changes sign, and intersect point in edge's Bound Box */ if ((lastdist * dist) <= 0) { @@ -3681,11 +3709,13 @@ static float bm_edge_seg_isect(const float sco_a[2], } } } - if ((m2 <= 1.0f) && (m2 >= -1.0f)) + if ((m2 <= 1.0f) && (m2 >= -1.0f)) { perc = (xi - x21) / (x22 - x21); - else + } + else { perc = (yi - y21) / (y22 - y21); /* lower slope more accurate */ - //isect = 32768.0 * (perc + 0.0000153); /* Percentage in 1 / 32768ths */ + } + // isect = 32768.0 * (perc + 0.0000153); /* Percentage in 1 / 32768ths */ break; } @@ -3717,8 +3747,9 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op) float(*screen_vert_coords)[2], (*sco)[2], (*mouse_path)[2]; /* edit-object needed for matrix, and ar->regiondata for projections to work */ - if (ELEM(NULL, obedit, ar, ar->regiondata)) + if (ELEM(NULL, obedit, ar, ar->regiondata)) { return OPERATOR_CANCELLED; + } if (bm->totvertsel < 2) { BKE_report(op->reports, RPT_ERROR, "No edges are selected to operate on"); @@ -3794,8 +3825,9 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op) BMO_slot_buffer_from_enabled_flag(bm, &bmop, bmop.slots_in, "edges", BM_EDGE, ELE_EDGE_CUT); - if (mode == KNIFE_MIDPOINT) + if (mode == KNIFE_MIDPOINT) { numcuts = 1; + } BMO_slot_int_set(bmop.slots_in, "cuts", numcuts); BMO_slot_int_set(bmop.slots_in, "quad_corner_type", SUBD_CORNER_STRAIGHT_CUT); @@ -4267,7 +4299,7 @@ void MESH_OT_separate(wmOperatorType *ot) static const EnumPropertyItem prop_separate_types[] = { {MESH_SEPARATE_SELECTED, "SELECTED", 0, "Selection", ""}, {MESH_SEPARATE_MATERIAL, "MATERIAL", 0, "By Material", ""}, - {MESH_SEPARATE_LOOSE, "LOOSE", 0, "By loose parts", ""}, + {MESH_SEPARATE_LOOSE, "LOOSE", 0, "By Loose Parts", ""}, {0, NULL, 0, NULL, NULL}, }; @@ -5904,19 +5936,28 @@ void MESH_OT_split(wmOperatorType *ot) * \{ */ enum { - SRT_VIEW_ZAXIS = 1, /* Use view Z (deep) axis. */ - SRT_VIEW_XAXIS, /* Use view X (left to right) axis. */ - SRT_CURSOR_DISTANCE, /* Use distance from element to 3D cursor. */ - SRT_MATERIAL, /* Face only: use mat number. */ - SRT_SELECTED, /* Move selected elements in first, without modifying - * relative order of selected and unselected elements. */ - SRT_RANDOMIZE, /* Randomize selected elements. */ - SRT_REVERSE, /* Reverse current order of selected elements. */ + /** Use view Z (deep) axis. */ + SRT_VIEW_ZAXIS = 1, + /** Use view X (left to right) axis. */ + SRT_VIEW_XAXIS, + /** Use distance from element to 3D cursor. */ + SRT_CURSOR_DISTANCE, + /** Face only: use mat number. */ + SRT_MATERIAL, + /** Move selected elements in first, without modifying + * relative order of selected and unselected elements. */ + SRT_SELECTED, + /** Randomize selected elements. */ + SRT_RANDOMIZE, + /** Reverse current order of selected elements. */ + SRT_REVERSE, }; typedef struct BMElemSort { - float srt; /* Sort factor */ - int org_idx; /* Original index of this element _in its mempool_ */ + /** Sort factor */ + float srt; + /** Original index of this element _in its mempool_ */ + int org_idx; } BMElemSort; static int bmelemsort_comp(const void *v1, const void *v2) @@ -5953,15 +5994,19 @@ static void sort_bmelem_flag(bContext *C, int affected[3] = {0, 0, 0}; int i, j; - if (!(types && flag && action)) + if (!(types && flag && action)) { return; + } - if (types & BM_VERT) + if (types & BM_VERT) { totelem[0] = em->bm->totvert; - if (types & BM_EDGE) + } + if (types & BM_EDGE) { totelem[1] = em->bm->totedge; - if (types & BM_FACE) + } + if (types & BM_FACE) { totelem[2] = em->bm->totface; + } if (ELEM(action, SRT_VIEW_ZAXIS, SRT_VIEW_XAXIS)) { float mat[4][4]; @@ -6173,8 +6218,9 @@ static void sort_bmelem_flag(bContext *C, int aff = affected[j]; tb = tbuf[j]; mp = map[j]; - if (!(tb && mp)) + if (!(tb && mp)) { continue; + } if (ELEM(aff, 0, tot)) { MEM_freeN(tb); MEM_freeN(mp); @@ -6315,12 +6361,15 @@ static void sort_bmelem_flag(bContext *C, /* printf("%d faces: %d to be affected...\n", totelem[2], affected[2]);*/ if (affected[0] == 0 && affected[1] == 0 && affected[2] == 0) { for (j = 3; j--;) { - if (pblock[j]) + if (pblock[j]) { MEM_freeN(pblock[j]); - if (sblock[j]) + } + if (sblock[j]) { MEM_freeN(sblock[j]); - if (map[j]) + } + if (map[j]) { MEM_freeN(map[j]); + } } return; } @@ -6350,10 +6399,12 @@ static void sort_bmelem_flag(bContext *C, } } } - if (pb) + if (pb) { MEM_freeN(pb); - if (sb) + } + if (sb) { MEM_freeN(sb); + } } BM_mesh_remap(em->bm, map[0], map[1], map[2]); @@ -6361,8 +6412,9 @@ static void sort_bmelem_flag(bContext *C, WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); for (j = 3; j--;) { - if (map[j]) + if (map[j]) { MEM_freeN(map[j]); + } } } @@ -6394,12 +6446,15 @@ static int edbm_sort_elements_exec(bContext *C, wmOperator *op) } else { BMEditMesh *em = BKE_editmesh_from_object(ob_active); - if (em->selectmode & SCE_SELECT_VERTEX) + if (em->selectmode & SCE_SELECT_VERTEX) { elem_types |= BM_VERT; - if (em->selectmode & SCE_SELECT_EDGE) + } + if (em->selectmode & SCE_SELECT_EDGE) { elem_types |= BM_EDGE; - if (em->selectmode & SCE_SELECT_FACE) + } + if (em->selectmode & SCE_SELECT_FACE) { elem_types |= BM_FACE; + } RNA_enum_set(op->ptr, "elements", elem_types); } @@ -6441,18 +6496,22 @@ static bool edbm_sort_elements_poll_property(const bContext *UNUSED(C), /* Only show seed for randomize action! */ if (STREQ(prop_id, "seed")) { - if (action == SRT_RANDOMIZE) + if (action == SRT_RANDOMIZE) { return true; - else + } + else { return false; + } } /* Hide seed for reverse and randomize actions! */ if (STREQ(prop_id, "reverse")) { - if (ELEM(action, SRT_RANDOMIZE, SRT_REVERSE)) + if (ELEM(action, SRT_RANDOMIZE, SRT_REVERSE)) { return false; - else + } + else { return true; + } } return true; @@ -6953,7 +7012,8 @@ void MESH_OT_offset_edge_loops(wmOperatorType *ot) ot->exec = edbm_offset_edgeloop_exec; ot->poll = ED_operator_editmesh; - /* Keep internal, since this is only meant to be accessed via 'MESH_OT_offset_edge_loops_slide' */ + /* Keep internal, since this is only meant to be accessed via + * 'MESH_OT_offset_edge_loops_slide'. */ /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; @@ -7589,8 +7649,9 @@ wmKeyMap *point_normals_modal_keymap(wmKeyConfig *keyconf) wmKeyMap *keymap = WM_modalkeymap_get(keyconf, keymap_name); /* We only need to add map once */ - if (keymap && keymap->modal_items) + if (keymap && keymap->modal_items) { return NULL; + } keymap = WM_modalkeymap_add(keyconf, keymap_name, modal_items); @@ -7721,7 +7782,8 @@ static void point_normals_apply(bContext *C, wmOperator *op, float target[3], co copy_v3_v3(lnor_ed->nloc, lnor_ed->niloc); } else if (do_spherize) { - /* Note that this is *not* real spherical interpolation. Probably good enough in this case though? */ + /* Note that this is *not* real spherical interpolation. + * Probably good enough in this case though? */ const float strength = RNA_float_get(op->ptr, "spherize_strength"); float spherized_normal[3]; @@ -8801,12 +8863,13 @@ static int edbm_smoothen_normals_exec(bContext *C, wmOperator *op) float(*smooth_normal)[3] = MEM_callocN(sizeof(*smooth_normal) * lnors_ed_arr->totloop, __func__); - /* This is weird choice of operation, taking all loops of faces of current vertex... Could lead to some rather - * far away loops weighting as much as very close ones (topologically speaking), with complex polygons. - * Using topological distance here (rather than geometrical one) makes sense imho, but would rather go with - * a more consistent and flexible code, we could even add max topological distance to take into account, - * and a weighting curve... - * Would do that later though, think for now we can live with that choice. --mont29 */ + /* This is weird choice of operation, taking all loops of faces of current vertex. + * Could lead to some rather far away loops weighting as much as very close ones + * (topologically speaking), with complex polygons. + * Using topological distance here (rather than geometrical one) + * makes sense imho, but would rather go with a more consistent and flexible code, + * we could even add max topological distance to take into account, * and a weighting curve. + * Would do that later though, think for now we can live with that choice. --mont29. */ BMLoopNorEditData *lnor_ed = lnors_ed_arr->lnor_editdata; for (int i = 0; i < lnors_ed_arr->totloop; i++, lnor_ed++) { l = lnor_ed->loop; @@ -8864,7 +8927,7 @@ static int edbm_smoothen_normals_exec(bContext *C, wmOperator *op) void MESH_OT_smoothen_normals(struct wmOperatorType *ot) { /* identifiers */ - ot->name = "Smoothen Normals"; + ot->name = "Smooth Normals Vectors"; ot->description = "Smoothen custom normals based on adjacent vertex normals"; ot->idname = "MESH_OT_smoothen_normals"; @@ -8941,7 +9004,7 @@ static int edbm_mod_weighted_strength_exec(bContext *C, wmOperator *op) void MESH_OT_mod_weighted_strength(struct wmOperatorType *ot) { /* identifiers */ - ot->name = "Face Strength"; + ot->name = "Face Normals Strength"; ot->description = "Set/Get strength of face (used in Weighted Normal modifier)"; ot->idname = "MESH_OT_mod_weighted_strength"; diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c index 2e855d9c5de..28b14b0060d 100644 --- a/source/blender/editors/mesh/editmesh_undo.c +++ b/source/blender/editors/mesh/editmesh_undo.c @@ -93,13 +93,13 @@ typedef struct UndoMesh { int selectmode; /** \note - * this isn't a prefect solution, if you edit keys and change shapes this works well (fixing [#32442]), - * but editing shape keys, going into object mode, removing or changing their order, - * then go back into editmode and undo will give issues - where the old index will be out of sync - * with the new object index. + * this isn't a prefect solution, if you edit keys and change shapes this works well + * (fixing T32442), but editing shape keys, going into object mode, removing or changing their + * order, then go back into editmode and undo will give issues - where the old index will be + * out of sync with the new object index. * * There are a few ways this could be made to work but for now its a known limitation with mixing - * object and editmode operations - Campbell */ + * object and editmode operations - Campbell. */ int shapenr; #ifdef USE_ARRAY_STORE diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index 1cb550fccc4..d7ed14184fa 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -363,10 +363,8 @@ void EDBM_mesh_load(Main *bmain, Object *ob) * cycles. */ #if 0 - for (Object *other_object = bmain->objects.first; - other_object != NULL; - other_object = other_object->id.next) - { + for (Object *other_object = bmain->objects.first; other_object != NULL; + other_object = other_object->id.next) { if (other_object->data == ob->data) { BKE_object_free_derived_caches(other_object); } @@ -575,8 +573,7 @@ UvVertMap *BM_uv_vert_map_create(BMesh *bm, tf_uv = (float(*)[2])BLI_buffer_reinit_data(&tf_uv_buf, vec2f, efa->len); } - BM_ITER_ELEM_INDEX(l, &liter, efa, BM_LOOPS_OF_FACE, i) - { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { buf->loop_of_poly_index = i; buf->poly_index = a; buf->separate = 0; @@ -629,10 +626,12 @@ UvVertMap *BM_uv_vert_map_create(BMesh *bm, if (fabsf(uvdiff[0]) < limit[0] && fabsf(uvdiff[1]) < limit[1] && (!use_winding || winding[iterv->poly_index] == winding[v->poly_index])) { - if (lastv) + if (lastv) { lastv->next = next; - else + } + else { vlist = next; + } iterv->next = newvlist; newvlist = iterv; } @@ -725,8 +724,7 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm, tf_uv = (float(*)[2])BLI_buffer_reinit_data(&tf_uv_buf, vec2f, efa->len); } - BM_ITER_ELEM_INDEX(l, &liter, efa, BM_LOOPS_OF_FACE, i) - { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { buf->l = l; buf->separate = 0; buf->island = INVALID_ISLAND; @@ -780,10 +778,12 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm, if (fabsf(uvdiff[0]) < STD_UV_CONNECT_LIMIT && fabsf(uvdiff[1]) < STD_UV_CONNECT_LIMIT && (!use_winding || winding[BM_elem_index_get(iterv->l->f)] == winding[BM_elem_index_get(v->l->f)])) { - if (lastv) + if (lastv) { lastv->next = next; - else + } + else { vlist = next; + } iterv->next = newvlist; newvlist = iterv; } @@ -837,8 +837,9 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm, UvElement *element, *initelement = element_map->vert[BM_elem_index_get(l->v)]; for (element = initelement; element; element = element->next) { - if (element->separate) + if (element->separate) { initelement = element; + } if (element->l->f == efa) { /* found the uv corresponding to our face and vertex. @@ -852,8 +853,9 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm, islandbufsize++; for (element = initelement; element; element = element->next) { - if (element->separate && element != initelement) + if (element->separate && element != initelement) { break; + } if (island_number[BM_elem_index_get(element->l->f)] == INVALID_ISLAND) { stack[stacksize++] = element->l->f; @@ -875,8 +877,9 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm, /* remap */ for (i = 0; i < bm->totvert; i++) { /* important since we may do selection only. Some of these may be NULL */ - if (element_map->vert[i]) + if (element_map->vert[i]) { element_map->vert[i] = &islandbuf[map[element_map->vert[i] - element_map->buf]]; + } } element_map->islandIndices = MEM_callocN(sizeof(*element_map->islandIndices) * nislands, @@ -884,10 +887,12 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm, j = 0; for (i = 0; i < totuv; i++) { UvElement *element = element_map->buf[i].next; - if (element == NULL) + if (element == NULL) { islandbuf[map[i]].next = NULL; - else + } + else { islandbuf[map[i]].next = &islandbuf[map[element - element_map->buf]]; + } if (islandbuf[i].island != j) { j++; @@ -911,10 +916,12 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm, void BM_uv_vert_map_free(UvVertMap *vmap) { if (vmap) { - if (vmap->vert) + if (vmap->vert) { MEM_freeN(vmap->vert); - if (vmap->buf) + } + if (vmap->buf) { MEM_freeN(vmap->buf); + } MEM_freeN(vmap); } } @@ -922,12 +929,15 @@ void BM_uv_vert_map_free(UvVertMap *vmap) void BM_uv_element_map_free(UvElementMap *element_map) { if (element_map) { - if (element_map->vert) + if (element_map->vert) { MEM_freeN(element_map->vert); - if (element_map->buf) + } + if (element_map->buf) { MEM_freeN(element_map->buf); - if (element_map->islandIndices) + } + if (element_map->islandIndices) { MEM_freeN(element_map->islandIndices); + } MEM_freeN(element_map); } } @@ -1021,7 +1031,8 @@ static BMVert *cache_mirr_intptr_as_bmvert(intptr_t *index_lookup, int index) * \param use_select: Restrict to selected verts. * \param use_topology: Use topology mirror. * \param maxdist: Distance for close point test. - * \param r_index: Optional array to write into, as an alternative to a customdata layer (length of total verts). + * \param r_index: Optional array to write into, as an alternative to a customdata layer + * (length of total verts). */ void EDBM_verts_mirror_cache_begin_ex(BMEditMesh *em, const int axis, @@ -1246,12 +1257,15 @@ bool EDBM_mesh_hide(BMEditMesh *em, bool swap) char hflag_swap = swap ? BM_ELEM_SELECT : 0; bool changed = true; - if (em->selectmode & SCE_SELECT_VERTEX) + if (em->selectmode & SCE_SELECT_VERTEX) { itermode = BM_VERTS_OF_MESH; - else if (em->selectmode & SCE_SELECT_EDGE) + } + else if (em->selectmode & SCE_SELECT_EDGE) { itermode = BM_EDGES_OF_MESH; - else + } + else { itermode = BM_FACES_OF_MESH; + } BM_ITER_MESH (ele, &iter, em->bm, itermode) { if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN)) { diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 2f4fbcab9bc..385b3c69422 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -183,8 +183,7 @@ static void mesh_uv_reset_bmface(BMFace *f, const int cd_loop_uv_offset) BMLoop *l; int i; - BM_ITER_ELEM_INDEX(l, &liter, f, BM_LOOPS_OF_FACE, i) - { + BM_ITER_ELEM_INDEX (l, &liter, f, BM_LOOPS_OF_FACE, i) { fuv[i] = ((MLoopUV *)BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset))->uv; } @@ -218,8 +217,9 @@ void ED_mesh_uv_loop_reset_ex(struct Mesh *me, const int layernum) BLI_assert(cd_loop_uv_offset != -1); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } mesh_uv_reset_bmface(efa, cd_loop_uv_offset); } @@ -262,8 +262,9 @@ int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set, co em = me->edit_mesh; layernum_dst = CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPUV); - if (layernum_dst >= MAX_MTFACE) + if (layernum_dst >= MAX_MTFACE) { return -1; + } /* CD_MLOOPUV */ BM_data_layer_add_named(em->bm, &em->bm->ldata, CD_MLOOPUV, name); @@ -280,8 +281,9 @@ int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set, co } else { layernum_dst = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); - if (layernum_dst >= MAX_MTFACE) + if (layernum_dst >= MAX_MTFACE) { return -1; + } if (me->mloopuv && do_init) { CustomData_add_layer_named( @@ -323,13 +325,15 @@ void ED_mesh_uv_texture_ensure(struct Mesh *me, const char *name) em = me->edit_mesh; layernum_dst = CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPUV); - if (layernum_dst == 0) + if (layernum_dst == 0) { ED_mesh_uv_texture_add(me, name, true, true); + } } else { layernum_dst = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); - if (layernum_dst == 0) + if (layernum_dst == 0) { ED_mesh_uv_texture_add(me, name, true, true); + } } } @@ -342,8 +346,9 @@ bool ED_mesh_uv_texture_remove_index(Mesh *me, const int n) index = CustomData_get_layer_index_n(ldata, CD_MLOOPUV, n); cdlu = (index == -1) ? NULL : &ldata->layers[index]; - if (!cdlu) + if (!cdlu) { return false; + } delete_customdata_layer(me, cdlu); @@ -456,8 +461,9 @@ bool ED_mesh_color_remove_index(Mesh *me, const int n) index = CustomData_get_layer_index_n(ldata, CD_MLOOPCOL, n); cdl = (index == -1) ? NULL : &ldata->layers[index]; - if (!cdl) + if (!cdl) { return false; + } delete_customdata_layer(me, cdl); DEG_id_tag_update(&me->id, 0); @@ -502,8 +508,9 @@ static int mesh_uv_texture_add_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_object_context(C); Mesh *me = ob->data; - if (ED_mesh_uv_texture_add(me, NULL, true, true) == -1) + if (ED_mesh_uv_texture_add(me, NULL, true, true) == -1) { return OPERATOR_CANCELLED; + } if (ob->mode & OB_MODE_TEXTURE_PAINT) { Scene *scene = CTX_data_scene(C); @@ -534,8 +541,9 @@ static int mesh_uv_texture_remove_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_object_context(C); Mesh *me = ob->data; - if (!ED_mesh_uv_texture_remove_active(me)) + if (!ED_mesh_uv_texture_remove_active(me)) { return OPERATOR_CANCELLED; + } if (ob->mode & OB_MODE_TEXTURE_PAINT) { Scene *scene = CTX_data_scene(C); @@ -568,8 +576,9 @@ static int mesh_vertex_color_add_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_object_context(C); Mesh *me = ob->data; - if (ED_mesh_color_add(me, NULL, true, true) == -1) + if (ED_mesh_color_add(me, NULL, true, true) == -1) { return OPERATOR_CANCELLED; + } return OPERATOR_FINISHED; } @@ -594,8 +603,9 @@ static int mesh_vertex_color_remove_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_object_context(C); Mesh *me = ob->data; - if (!ED_mesh_color_remove_active(me)) + if (!ED_mesh_color_remove_active(me)) { return OPERATOR_CANCELLED; + } return OPERATOR_FINISHED; } @@ -785,7 +795,8 @@ static int mesh_customdata_custom_splitnormals_add_exec(bContext *C, wmOperator CustomData *data = GET_CD_DATA(me, ldata); if (me->edit_mesh) { - /* Tag edges as sharp according to smooth threshold if needed, to preserve autosmooth shading. */ + /* Tag edges as sharp according to smooth threshold if needed, + * to preserve autosmooth shading. */ if (me->flag & ME_AUTOSMOOTH) { BM_edges_sharp_from_angle_set(me->edit_mesh->bm, me->smoothresh); } @@ -793,7 +804,8 @@ static int mesh_customdata_custom_splitnormals_add_exec(bContext *C, wmOperator BM_data_layer_add(me->edit_mesh->bm, data, CD_CUSTOMLOOPNORMAL); } else { - /* Tag edges as sharp according to smooth threshold if needed, to preserve autosmooth shading. */ + /* Tag edges as sharp according to smooth threshold if needed, + * to preserve autosmooth shading. */ if (me->flag & ME_AUTOSMOOTH) { float(*polynors)[3] = MEM_mallocN(sizeof(*polynors) * (size_t)me->totpoly, __func__); @@ -891,8 +903,9 @@ void ED_mesh_update( BKE_mesh_calc_edges_loose(mesh); } - if (calc_edges || ((mesh->totpoly || mesh->totface) && mesh->totedge == 0)) + if (calc_edges || ((mesh->totpoly || mesh->totface) && mesh->totedge == 0)) { BKE_mesh_calc_edges(mesh, calc_edges, true); + } if (calc_tessface) { if (tessface_input == false) { @@ -916,15 +929,17 @@ static void mesh_add_verts(Mesh *mesh, int len) MVert *mvert; int i, totvert; - if (len == 0) + if (len == 0) { return; + } totvert = mesh->totvert + len; CustomData_copy(&mesh->vdata, &vdata, CD_MASK_MESH.vmask, CD_DEFAULT, totvert); CustomData_copy_data(&mesh->vdata, &vdata, 0, 0, mesh->totvert); - if (!CustomData_has_layer(&vdata, CD_MVERT)) + if (!CustomData_has_layer(&vdata, CD_MVERT)) { CustomData_add_layer(&vdata, CD_MVERT, CD_CALLOC, NULL, totvert); + } CustomData_free(&mesh->vdata, mesh->totvert); mesh->vdata = vdata; @@ -934,8 +949,9 @@ static void mesh_add_verts(Mesh *mesh, int len) /* set default flags */ mvert = &mesh->mvert[mesh->totvert]; - for (i = 0; i < len; i++, mvert++) + for (i = 0; i < len; i++, mvert++) { mvert->flag |= SELECT; + } /* set final vertex list size */ mesh->totvert = totvert; @@ -947,8 +963,9 @@ static void mesh_add_edges(Mesh *mesh, int len) MEdge *medge; int i, totedge; - if (len == 0) + if (len == 0) { return; + } totedge = mesh->totedge + len; @@ -956,8 +973,9 @@ static void mesh_add_edges(Mesh *mesh, int len) CustomData_copy(&mesh->edata, &edata, CD_MASK_MESH.emask, CD_DEFAULT, totedge); CustomData_copy_data(&mesh->edata, &edata, 0, 0, mesh->totedge); - if (!CustomData_has_layer(&edata, CD_MEDGE)) + if (!CustomData_has_layer(&edata, CD_MEDGE)) { CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, totedge); + } CustomData_free(&mesh->edata, mesh->totedge); mesh->edata = edata; @@ -965,8 +983,9 @@ static void mesh_add_edges(Mesh *mesh, int len) /* set default flags */ medge = &mesh->medge[mesh->totedge]; - for (i = 0; i < len; i++, medge++) + for (i = 0; i < len; i++, medge++) { medge->flag = ME_EDGEDRAW | ME_EDGERENDER | SELECT; + } mesh->totedge = totedge; } @@ -977,8 +996,9 @@ static void mesh_add_tessfaces(Mesh *mesh, int len) MFace *mface; int i, totface; - if (len == 0) + if (len == 0) { return; + } totface = mesh->totface + len; /* new face count */ @@ -986,8 +1006,9 @@ static void mesh_add_tessfaces(Mesh *mesh, int len) CustomData_copy(&mesh->fdata, &fdata, CD_MASK_MESH.fmask, CD_DEFAULT, totface); CustomData_copy_data(&mesh->fdata, &fdata, 0, 0, mesh->totface); - if (!CustomData_has_layer(&fdata, CD_MFACE)) + if (!CustomData_has_layer(&fdata, CD_MFACE)) { CustomData_add_layer(&fdata, CD_MFACE, CD_CALLOC, NULL, totface); + } CustomData_free(&mesh->fdata, mesh->totface); mesh->fdata = fdata; @@ -995,8 +1016,9 @@ static void mesh_add_tessfaces(Mesh *mesh, int len) /* set default flags */ mface = &mesh->mface[mesh->totface]; - for (i = 0; i < len; i++, mface++) + for (i = 0; i < len; i++, mface++) { mface->flag = ME_FACE_SEL; + } mesh->totface = totface; } @@ -1006,8 +1028,9 @@ static void mesh_add_loops(Mesh *mesh, int len) CustomData ldata; int totloop; - if (len == 0) + if (len == 0) { return; + } totloop = mesh->totloop + len; /* new face count */ @@ -1015,8 +1038,9 @@ static void mesh_add_loops(Mesh *mesh, int len) CustomData_copy(&mesh->ldata, &ldata, CD_MASK_MESH.lmask, CD_DEFAULT, totloop); CustomData_copy_data(&mesh->ldata, &ldata, 0, 0, mesh->totloop); - if (!CustomData_has_layer(&ldata, CD_MLOOP)) + if (!CustomData_has_layer(&ldata, CD_MLOOP)) { CustomData_add_layer(&ldata, CD_MLOOP, CD_CALLOC, NULL, totloop); + } CustomData_free(&mesh->ldata, mesh->totloop); mesh->ldata = ldata; @@ -1031,8 +1055,9 @@ static void mesh_add_polys(Mesh *mesh, int len) MPoly *mpoly; int i, totpoly; - if (len == 0) + if (len == 0) { return; + } totpoly = mesh->totpoly + len; /* new face count */ @@ -1040,8 +1065,9 @@ static void mesh_add_polys(Mesh *mesh, int len) CustomData_copy(&mesh->pdata, &pdata, CD_MASK_MESH.pmask, CD_DEFAULT, totpoly); CustomData_copy_data(&mesh->pdata, &pdata, 0, 0, mesh->totpoly); - if (!CustomData_has_layer(&pdata, CD_MPOLY)) + if (!CustomData_has_layer(&pdata, CD_MPOLY)) { CustomData_add_layer(&pdata, CD_MPOLY, CD_CALLOC, NULL, totpoly); + } CustomData_free(&mesh->pdata, mesh->totpoly); mesh->pdata = pdata; @@ -1049,8 +1075,9 @@ static void mesh_add_polys(Mesh *mesh, int len) /* set default flags */ mpoly = &mesh->mpoly[mesh->totpoly]; - for (i = 0; i < len; i++, mpoly++) + for (i = 0; i < len; i++, mpoly++) { mpoly->flag = ME_FACE_SEL; + } mesh->totpoly = totpoly; } @@ -1059,8 +1086,9 @@ static void mesh_remove_verts(Mesh *mesh, int len) { int totvert; - if (len == 0) + if (len == 0) { return; + } totvert = mesh->totvert - len; CustomData_free_elem(&mesh->vdata, totvert, len); @@ -1073,8 +1101,9 @@ static void mesh_remove_edges(Mesh *mesh, int len) { int totedge; - if (len == 0) + if (len == 0) { return; + } totedge = mesh->totedge - len; CustomData_free_elem(&mesh->edata, totedge, len); @@ -1086,8 +1115,9 @@ static void mesh_remove_faces(Mesh *mesh, int len) { int totface; - if (len == 0) + if (len == 0) { return; + } totface = mesh->totface - len; /* new face count */ CustomData_free_elem(&mesh->fdata, totface, len); diff --git a/source/blender/editors/mesh/mesh_mirror.c b/source/blender/editors/mesh/mesh_mirror.c index 7d0ee19b5ea..eec0c4a57fa 100644 --- a/source/blender/editors/mesh/mesh_mirror.c +++ b/source/blender/editors/mesh/mesh_mirror.c @@ -50,8 +50,9 @@ int ED_mesh_mirror_spatial_table( Object *ob, BMEditMesh *em, Mesh *me_eval, const float co[3], char mode) { if (mode == 'u') { /* use table */ - if (MirrKdStore.tree == NULL) + if (MirrKdStore.tree == NULL) { ED_mesh_mirror_spatial_table(ob, em, me_eval, NULL, 's'); + } if (MirrKdStore.tree) { KDTreeNearest_3d nearest; @@ -70,8 +71,9 @@ int ED_mesh_mirror_spatial_table( const bool use_em = (!me_eval && em && me->edit_mesh == em); const int totvert = use_em ? em->bm->totvert : me_eval ? me_eval->totvert : me->totvert; - if (MirrKdStore.tree) /* happens when entering this call without ending it */ + if (MirrKdStore.tree) { /* happens when entering this call without ending it */ ED_mesh_mirror_spatial_table(ob, em, me_eval, co, 'e'); + } MirrKdStore.tree = BLI_kdtree_3d_new(totvert); @@ -126,19 +128,23 @@ typedef struct MirrTopoVert_t { static int mirrtopo_hash_sort(const void *l1, const void *l2) { - if ((MirrTopoHash_t)(intptr_t)l1 > (MirrTopoHash_t)(intptr_t)l2) + if ((MirrTopoHash_t)(intptr_t)l1 > (MirrTopoHash_t)(intptr_t)l2) { return 1; - else if ((MirrTopoHash_t)(intptr_t)l1 < (MirrTopoHash_t)(intptr_t)l2) + } + else if ((MirrTopoHash_t)(intptr_t)l1 < (MirrTopoHash_t)(intptr_t)l2) { return -1; + } return 0; } static int mirrtopo_vert_sort(const void *v1, const void *v2) { - if (((MirrTopoVert_t *)v1)->hash > ((MirrTopoVert_t *)v2)->hash) + if (((MirrTopoVert_t *)v1)->hash > ((MirrTopoVert_t *)v2)->hash) { return 1; - else if (((MirrTopoVert_t *)v1)->hash < ((MirrTopoVert_t *)v2)->hash) + } + else if (((MirrTopoVert_t *)v1)->hash < ((MirrTopoVert_t *)v2)->hash) { return -1; + } return 0; } diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index 8a51b9ba54e..ed5e6c39f85 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -242,7 +242,7 @@ void ED_operatormacros_mesh(void) OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "MESH_OT_duplicate"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); ot = WM_operatortype_append_macro("MESH_OT_rip_move", @@ -251,7 +251,7 @@ void ED_operatormacros_mesh(void) OPTYPE_UNDO | OPTYPE_REGISTER); otmacro = WM_operatortype_macro_define(ot, "MESH_OT_rip"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); ot = WM_operatortype_append_macro("MESH_OT_rip_edge_move", @@ -260,7 +260,7 @@ void ED_operatormacros_mesh(void) OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "MESH_OT_rip_edge"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); ot = WM_operatortype_append_macro("MESH_OT_extrude_region_move", @@ -269,7 +269,7 @@ void ED_operatormacros_mesh(void) OPTYPE_UNDO | OPTYPE_REGISTER); otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_region"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); ot = WM_operatortype_append_macro("MESH_OT_extrude_context_move", @@ -278,7 +278,7 @@ void ED_operatormacros_mesh(void) OPTYPE_UNDO | OPTYPE_REGISTER); otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_context"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); ot = WM_operatortype_append_macro("MESH_OT_extrude_region_shrink_fatten", @@ -287,7 +287,7 @@ void ED_operatormacros_mesh(void) OPTYPE_UNDO | OPTYPE_REGISTER); otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_region"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_shrink_fatten"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); ot = WM_operatortype_append_macro("MESH_OT_extrude_faces_move", @@ -296,7 +296,7 @@ void ED_operatormacros_mesh(void) OPTYPE_UNDO | OPTYPE_REGISTER); otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_faces_indiv"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_shrink_fatten"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); ot = WM_operatortype_append_macro("MESH_OT_extrude_edges_move", @@ -305,7 +305,7 @@ void ED_operatormacros_mesh(void) OPTYPE_UNDO | OPTYPE_REGISTER); otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_edges_indiv"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); ot = WM_operatortype_append_macro("MESH_OT_extrude_vertices_move", @@ -314,7 +314,7 @@ void ED_operatormacros_mesh(void) OPTYPE_UNDO | OPTYPE_REGISTER); otmacro = WM_operatortype_macro_define(ot, "MESH_OT_extrude_verts_indiv"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); ot = WM_operatortype_append_macro("MESH_OT_polybuild_face_at_cursor_move", @@ -323,7 +323,7 @@ void ED_operatormacros_mesh(void) OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "MESH_OT_polybuild_face_at_cursor"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); ot = WM_operatortype_append_macro("MESH_OT_polybuild_split_at_cursor_move", @@ -332,7 +332,7 @@ void ED_operatormacros_mesh(void) OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "MESH_OT_polybuild_split_at_cursor"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); RNA_boolean_set(otmacro->ptr, "mirror", false); } diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index ce7908bf0a3..c32fef42d27 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -150,9 +150,11 @@ static void join_mesh_single(Depsgraph *depsgraph, mul_m4_v3(cmat, mvert->co); } - /* for each shapekey in destination mesh: - * - if there's a matching one, copy it across (will need to transform vertices into new space...) - * - otherwise, just copy own coordinates of mesh (no need to transform vertex coordinates into new space) + /* For each shapekey in destination mesh: + * - if there's a matching one, copy it across + * (will need to transform vertices into new space...). + * - otherwise, just copy own coordinates of mesh + * (no need to transform vertex coordinates into new space). */ if (key) { /* if this mesh has any shapekeys, check first, otherwise just copy coordinates */ @@ -321,12 +323,14 @@ int join_mesh_exec(bContext *C, wmOperator *op) totpoly += me->totpoly; totmat += ob_iter->totcol; - if (ob_iter == ob) + if (ob_iter == ob) { ok = true; + } /* check for shapekeys */ - if (me->key) + if (me->key) { haskey++; + } } } CTX_DATA_END; @@ -337,7 +341,8 @@ int join_mesh_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - /* only join meshes if there are verts to join, there aren't too many, and we only had one mesh selected */ + /* Only join meshes if there are verts to join, + * there aren't too many, and we only had one mesh selected. */ me = (Mesh *)ob->data; key = me->key; @@ -383,8 +388,9 @@ int join_mesh_exec(bContext *C, wmOperator *op) /* for all keys in old block, clear data-arrays */ for (kb = key->block.first; kb; kb = kb->next) { - if (kb->data) + if (kb->data) { MEM_freeN(kb->data); + } kb->data = MEM_callocN(sizeof(float) * 3 * totvert, "join_shapekey"); kb->totelem = totvert; } @@ -410,8 +416,9 @@ int join_mesh_exec(bContext *C, wmOperator *op) BLI_addtail(&ob->defbase, odg); } } - if (ob->defbase.first && ob->actdef == 0) + if (ob->defbase.first && ob->actdef == 0) { ob->actdef = 1; + } if (me->totvert) { /* Add this object's materials to the base one's if they don't exist already @@ -606,13 +613,15 @@ int join_mesh_exec(bContext *C, wmOperator *op) /* old material array */ for (a = 1; a <= ob->totcol; a++) { ma = ob->mat[a - 1]; - if (ma) + if (ma) { id_us_min(&ma->id); + } } for (a = 1; a <= me->totcol; a++) { ma = me->mat[a - 1]; - if (ma) + if (ma) { id_us_min(&ma->id); + } } MEM_SAFE_FREE(ob->mat); MEM_SAFE_FREE(ob->matbits); @@ -680,21 +689,25 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) if (ob_iter->type == OB_MESH) { selme = (Mesh *)ob_iter->data; - if (selme->totvert == me->totvert) + if (selme->totvert == me->totvert) { ok = true; - else + } + else { nonequal_verts = 1; + } } } CTX_DATA_END; if (!ok) { - if (nonequal_verts) + if (nonequal_verts) { BKE_report(op->reports, RPT_WARNING, "Selected meshes must have equal numbers of vertices"); - else + } + else { BKE_report(op->reports, RPT_WARNING, "No additional selected meshes with equal vertex count to join"); + } return OPERATOR_CANCELLED; } @@ -748,9 +761,10 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) static MirrTopoStore_t mesh_topo_store = {NULL, -1. - 1, -1}; -/* mode is 's' start, or 'e' end, or 'u' use */ -/* if end, ob can be NULL */ -/* note, is supposed return -1 on error, which callers are currently checking for, but is not used so far */ +/** mode is 's' start, or 'e' end, or 'u' use + * if end, ob can be NULL. + * \note, is supposed return -1 on error, + * which callers are currently checking for, but is not used so far. */ int ED_mesh_mirror_topo_table(Object *ob, Mesh *me_eval, char mode) { if (mode == 'u') { /* use table */ @@ -789,8 +803,9 @@ static int mesh_get_x_mirror_vert_spatial(Object *ob, Mesh *mesh, int index) static int mesh_get_x_mirror_vert_topo(Object *ob, Mesh *mesh, int index) { - if (ED_mesh_mirror_topo_table(ob, mesh, 'u') == -1) + if (ED_mesh_mirror_topo_table(ob, mesh, 'u') == -1) { return -1; + } return mesh_topo_store.index_lookup[index]; } @@ -832,8 +847,9 @@ static BMVert *editbmesh_get_x_mirror_vert_topo(Object *ob, int index) { intptr_t poinval; - if (ED_mesh_mirror_topo_table(ob, NULL, 'u') == -1) + if (ED_mesh_mirror_topo_table(ob, NULL, 'u') == -1) { return NULL; + } if (index == -1) { BMIter iter; @@ -841,8 +857,9 @@ static BMVert *editbmesh_get_x_mirror_vert_topo(Object *ob, index = 0; BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { - if (v == eve) + if (v == eve) { break; + } index++; } @@ -853,8 +870,9 @@ static BMVert *editbmesh_get_x_mirror_vert_topo(Object *ob, poinval = mesh_topo_store.index_lookup[index]; - if (poinval != -1) + if (poinval != -1) { return (BMVert *)(poinval); + } return NULL; } @@ -900,17 +918,15 @@ int ED_mesh_mirror_get_vert(Object *ob, int index) #if 0 -static float *editmesh_get_mirror_uv(BMEditMesh *em, int axis, float *uv, float *mirrCent, float *face_cent) +static float *editmesh_get_mirror_uv( + BMEditMesh *em, int axis, float *uv, float *mirrCent, float *face_cent) { float vec[2]; float cent_vec[2]; float cent[2]; /* ignore nan verts */ - if (isnan(uv[0]) || !isfinite(uv[0]) || - isnan(uv[1]) || !isfinite(uv[1]) - ) - { + if (isnan(uv[0]) || !isfinite(uv[0]) || isnan(uv[1]) || !isfinite(uv[1])) { return NULL; } @@ -937,15 +953,14 @@ static float *editmesh_get_mirror_uv(BMEditMesh *em, int axis, float *uv, float BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { uv_poly_center(efa, cent, cd_loop_uv_offset); - if ( (fabsf(cent[0] - cent_vec[0]) < 0.001f) && (fabsf(cent[1] - cent_vec[1]) < 0.001f) ) { + if ((fabsf(cent[0] - cent_vec[0]) < 0.001f) && (fabsf(cent[1] - cent_vec[1]) < 0.001f)) { BMIter liter; BMLoop *l; BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { MLoopUV *luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - if ( (fabsf(luv->uv[0] - vec[0]) < 0.001f) && (fabsf(luv->uv[1] - vec[1]) < 0.001f) ) { + if ((fabsf(luv->uv[0] - vec[0]) < 0.001f) && (fabsf(luv->uv[1] - vec[1]) < 0.001f)) { return luv->uv; - } } } @@ -977,22 +992,29 @@ static unsigned int mirror_facehash(const void *ptr) static int mirror_facerotation(MFace *a, MFace *b) { if (b->v4) { - if (a->v1 == b->v1 && a->v2 == b->v2 && a->v3 == b->v3 && a->v4 == b->v4) + if (a->v1 == b->v1 && a->v2 == b->v2 && a->v3 == b->v3 && a->v4 == b->v4) { return 0; - else if (a->v4 == b->v1 && a->v1 == b->v2 && a->v2 == b->v3 && a->v3 == b->v4) + } + else if (a->v4 == b->v1 && a->v1 == b->v2 && a->v2 == b->v3 && a->v3 == b->v4) { return 1; - else if (a->v3 == b->v1 && a->v4 == b->v2 && a->v1 == b->v3 && a->v2 == b->v4) + } + else if (a->v3 == b->v1 && a->v4 == b->v2 && a->v1 == b->v3 && a->v2 == b->v4) { return 2; - else if (a->v2 == b->v1 && a->v3 == b->v2 && a->v4 == b->v3 && a->v1 == b->v4) + } + else if (a->v2 == b->v1 && a->v3 == b->v2 && a->v4 == b->v3 && a->v1 == b->v4) { return 3; + } } else { - if (a->v1 == b->v1 && a->v2 == b->v2 && a->v3 == b->v3) + if (a->v1 == b->v1 && a->v2 == b->v2 && a->v3 == b->v3) { return 0; - else if (a->v3 == b->v1 && a->v1 == b->v2 && a->v2 == b->v3) + } + else if (a->v3 == b->v1 && a->v1 == b->v2 && a->v2 == b->v3) { return 1; - else if (a->v2 == b->v1 && a->v3 == b->v2 && a->v1 == b->v3) + } + else if (a->v2 == b->v1 && a->v3 == b->v2 && a->v1 == b->v3) { return 2; + } } return -1; @@ -1027,14 +1049,16 @@ int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em, Mesh *me_eval) ED_mesh_mirror_spatial_table(ob, em, me_eval, NULL, 's'); - for (a = 0, mv = mvert; a < totvert; a++, mv++) + for (a = 0, mv = mvert; a < totvert; a++, mv++) { mirrorverts[a] = mesh_get_x_mirror_vert(ob, me_eval, a, use_topology); + } ED_mesh_mirror_spatial_table(ob, em, me_eval, NULL, 'e'); fhash = BLI_ghash_new_ex(mirror_facehash, mirror_facecmp, "mirror_facehash gh", me->totface); - for (a = 0, mf = mface; a < totface; a++, mf++) + for (a = 0, mf = mface; a < totface; a++, mf++) { BLI_ghash_insert(fhash, mf, mf); + } for (a = 0, mf = mface; a < totface; a++, mf++) { mirrormf.v1 = mirrorverts[mf->v3]; @@ -1053,8 +1077,9 @@ int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em, Mesh *me_eval) mirrorfaces[a * 2] = hashmf - mface; mirrorfaces[a * 2 + 1] = mirror_facerotation(&mirrormf, hashmf); } - else + else { mirrorfaces[a * 2] = -1; + } } BLI_ghash_free(fhash, NULL, NULL); @@ -1079,8 +1104,9 @@ bool ED_mesh_pick_face(bContext *C, Object *ob, const int mval[2], uint dist_px, BLI_assert(me && GS(me->id.name) == ID_ME); - if (!me || me->totpoly == 0) + if (!me || me->totpoly == 0) { return false; + } ED_view3d_viewcontext_init(C, &vc); @@ -1260,8 +1286,9 @@ bool ED_mesh_pick_vert( BLI_assert(me && GS(me->id.name) == ID_ME); - if (!me || me->totvert == 0) + if (!me || me->totvert == 0) { return false; + } ED_view3d_viewcontext_init(C, &vc); @@ -1335,15 +1362,17 @@ MDeformVert *ED_mesh_active_dvert_get_em(Object *ob, BMVert **r_eve) BMVert *eve = BM_mesh_active_vert_get(bm); if (eve) { - if (r_eve) + if (r_eve) { *r_eve = eve; + } return BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); } } } - if (r_eve) + if (r_eve) { *r_eve = NULL; + } return NULL; } @@ -1351,8 +1380,9 @@ MDeformVert *ED_mesh_active_dvert_get_ob(Object *ob, int *r_index) { Mesh *me = ob->data; int index = BKE_mesh_mselect_active_get(me, ME_VSEL); - if (r_index) + if (r_index) { *r_index = index; + } if (index == -1 || me->dvert == NULL) { return NULL; } diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c index 45eb66c228b..54143822b61 100644 --- a/source/blender/editors/metaball/mball_edit.c +++ b/source/blender/editors/metaball/mball_edit.c @@ -15,8 +15,6 @@ * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. - * - */ /** \file diff --git a/source/blender/editors/metaball/mball_ops.c b/source/blender/editors/metaball/mball_ops.c index 4de277901f4..c203ca56d74 100644 --- a/source/blender/editors/metaball/mball_ops.c +++ b/source/blender/editors/metaball/mball_ops.c @@ -59,7 +59,7 @@ void ED_operatormacros_metaball(void) OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "MBALL_OT_duplicate_metaelems"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", 0); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); } void ED_keymap_metaball(wmKeyConfig *keyconf) diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt index 8ef0d85bcfd..eaef9313431 100644 --- a/source/blender/editors/object/CMakeLists.txt +++ b/source/blender/editors/object/CMakeLists.txt @@ -22,19 +22,19 @@ set(INC ../../blentranslation ../../bmesh ../../depsgraph + ../../gpencil_modifiers ../../gpu ../../ikplugin ../../imbuf ../../makesdna ../../makesrna ../../modifiers - ../../gpencil_modifiers - ../../shader_fx ../../python + ../../shader_fx ../../render/extern/include ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index c050b579aa6..f8a13579732 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -216,14 +216,17 @@ void ED_object_base_init_transform(bContext *C, Base *base, const float loc[3], Scene *scene = CTX_data_scene(C); Depsgraph *depsgraph = CTX_data_depsgraph(C); - if (!scene) + if (!scene) { return; + } - if (loc) + if (loc) { copy_v3_v3(ob->loc, loc); + } - if (rot) + if (rot) { copy_v3_v3(ob->rot, rot); + } BKE_object_where_is_calc(depsgraph, scene, ob); } @@ -342,11 +345,13 @@ bool ED_object_add_generic_get_opts(bContext *C, /* Switch to Edit mode? optional prop */ if ((prop = RNA_struct_find_property(op->ptr, "enter_editmode"))) { bool _enter_editmode; - if (!enter_editmode) + if (!enter_editmode) { enter_editmode = &_enter_editmode; + } - if (RNA_property_is_set(op->ptr, prop) && enter_editmode) + if (RNA_property_is_set(op->ptr, prop) && enter_editmode) { *enter_editmode = RNA_property_boolean_get(op->ptr, prop); + } else { *enter_editmode = (U.flag & USER_ADD_EDITMODE) != 0; RNA_property_boolean_set(op->ptr, prop, *enter_editmode); @@ -363,8 +368,9 @@ bool ED_object_add_generic_get_opts(bContext *C, /* Location! */ { float _loc[3]; - if (!loc) + if (!loc) { loc = _loc; + } if (RNA_struct_property_is_set(op->ptr, "location")) { RNA_float_get_array(op->ptr, "location", loc); @@ -379,15 +385,19 @@ bool ED_object_add_generic_get_opts(bContext *C, { bool _is_view_aligned; float _rot[3]; - if (!is_view_aligned) + if (!is_view_aligned) { is_view_aligned = &_is_view_aligned; - if (!rot) + } + if (!rot) { rot = _rot; + } - if (RNA_struct_property_is_set(op->ptr, "rotation")) + if (RNA_struct_property_is_set(op->ptr, "rotation")) { *is_view_aligned = false; - else if (RNA_struct_property_is_set(op->ptr, "view_align")) + } + else if (RNA_struct_property_is_set(op->ptr, "view_align")) { *is_view_aligned = RNA_boolean_get(op->ptr, "view_align"); + } else { *is_view_aligned = (U.flag & USER_ADD_VIEWALIGNED) != 0; RNA_boolean_set(op->ptr, "view_align", *is_view_aligned); @@ -397,8 +407,9 @@ bool ED_object_add_generic_get_opts(bContext *C, ED_object_rotation_from_view(C, rot, view_align_axis); RNA_float_set_array(op->ptr, "rotation", rot); } - else + else { RNA_float_get_array(op->ptr, "rotation", rot); + } } return true; @@ -625,15 +636,17 @@ static int effector_add_exec(bContext *C, wmOperator *op) ED_object_new_primitive_matrix(C, ob, loc, rot, mat); BLI_addtail(&cu->editnurb->nurbs, ED_curve_add_nurbs_primitive(C, ob, mat, CU_NURBS | CU_PRIM_PATH, dia)); - if (!enter_editmode) + if (!enter_editmode) { ED_object_editmode_exit(C, EM_FREEDATA); + } } else { const char *name = CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Field"); ob = ED_object_add_type(C, OB_EMPTY, name, loc, rot, false, local_view_bits); BKE_object_obdata_size_init(ob, dia); - if (ELEM(type, PFIELD_WIND, PFIELD_VORTEX)) + if (ELEM(type, PFIELD_WIND, PFIELD_VORTEX)) { ob->empty_drawtype = OB_SINGLE_ARROW; + } } ob->pd = BKE_partdeflect_new(type); @@ -686,8 +699,9 @@ static int object_camera_add_exec(bContext *C, wmOperator *op) ob = ED_object_add_type(C, OB_CAMERA, NULL, loc, rot, false, local_view_bits); if (v3d) { - if (v3d->camera == NULL) + if (v3d->camera == NULL) { v3d->camera = ob; + } if (v3d->scenelock && scene->camera == NULL) { scene->camera = ob; } @@ -797,8 +811,9 @@ static int object_add_text_exec(bContext *C, wmOperator *op) C, op, 'Z', loc, rot, &enter_editmode, &local_view_bits, NULL)) { return OPERATOR_CANCELLED; } - if (obedit && obedit->type == OB_FONT) + if (obedit && obedit->type == OB_FONT) { return OPERATOR_CANCELLED; + } obedit = ED_object_add_type(C, OB_FONT, NULL, loc, rot, enter_editmode, local_view_bits); BKE_object_obdata_size_init(obedit, RNA_float_get(op->ptr, "radius")); @@ -862,8 +877,9 @@ static int object_armature_add_exec(bContext *C, wmOperator *op) ED_armature_ebone_add_primitive(obedit, dia, view_aligned); /* userdef */ - if (newob && !enter_editmode) + if (newob && !enter_editmode) { ED_object_editmode_exit(C, EM_FREEDATA); + } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); @@ -1246,8 +1262,9 @@ static int collection_instance_add_exec(bContext *C, wmOperator *op) RNA_float_set_array(op->ptr, "location", loc); } } - else + else { collection = BLI_findlink(&CTX_data_main(C)->collections, RNA_enum_get(op->ptr, "collection")); + } if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, &local_view_bits, NULL)) { return OPERATOR_CANCELLED; @@ -1392,8 +1409,9 @@ static int object_delete_exec(bContext *C, wmOperator *op) const bool use_global = RNA_boolean_get(op->ptr, "use_global"); uint changed_count = 0; - if (CTX_data_edit_object(C)) + if (CTX_data_edit_object(C)) { return OPERATOR_CANCELLED; + } CTX_DATA_BEGIN (C, Object *, ob, selected_objects) { const bool is_indirectly_used = BKE_library_ID_is_indirectly_used(bmain, ob); @@ -1421,8 +1439,9 @@ static int object_delete_exec(bContext *C, wmOperator *op) DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); } - /* This is sort of a quick hack to address T51243 - Proper thing to do here would be to nuke most of all this - * custom scene/object/base handling, and use generic lib remap/query for that. + /* This is sort of a quick hack to address T51243 - + * Proper thing to do here would be to nuke most of all this custom scene/object/base handling, + * and use generic lib remap/query for that. * But this is for later (aka 2.8, once layers & co are settled and working). */ if (use_global && ob->id.lib == NULL) { @@ -1433,7 +1452,8 @@ static int object_delete_exec(bContext *C, wmOperator *op) } /* remove from Grease Pencil parent */ - /* XXX This is likely not correct? Will also remove parent from grease pencil from other scenes, + /* XXX This is likely not correct? + * Will also remove parent from grease pencil from other scenes, * even when use_global is false... */ for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) { for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { @@ -1535,8 +1555,10 @@ static void copy_object_set_idnew(bContext *C) /********************* Make Duplicates Real ************************/ /** - * \note regarding hashing dupli-objects when using OB_DUPLICOLLECTION, skip the first member of #DupliObject.persistent_id - * since its a unique index and we only want to know if the group objects are from the same dupli-group instance. + * \note regarding hashing dupli-objects when using OB_DUPLICOLLECTION, + * skip the first member of #DupliObject.persistent_id + * since its a unique index and we only want to know if the group objects are from the same + * dupli-group instance. */ static unsigned int dupliobject_group_hash(const void *ptr) { @@ -1550,8 +1572,10 @@ static unsigned int dupliobject_group_hash(const void *ptr) } /** - * \note regarding hashing dupli-objects when NOT using OB_DUPLICOLLECTION, include the first member of #DupliObject.persistent_id - * since its the index of the vertex/face the object is instantiated on and we want to identify objects on the same vertex/face. + * \note regarding hashing dupli-objects when NOT using OB_DUPLICOLLECTION, + * include the first member of #DupliObject.persistent_id + * since its the index of the vertex/face the object is instantiated on and we want to identify + * objects on the same vertex/face. */ static unsigned int dupliobject_hash(const void *ptr) { @@ -1827,7 +1851,8 @@ static void convert_ensure_curve_cache(Depsgraph *depsgraph, Scene *scene, Objec if (ob->runtime.curve_cache == NULL) { /* Force creation. This is normally not needed but on operator * redo we might end up with an object which isn't evaluated yet. - * Also happens in case we are working on a copy of the object (all its caches have been nuked then). + * Also happens in case we are working on a copy of the object + * (all its caches have been nuked then). */ if (ELEM(ob->type, OB_SURF, OB_CURVE, OB_FONT)) { /* We need 'for render' ON here, to enable computing bevel dipslist if needed. @@ -1932,8 +1957,9 @@ static int convert_exec(bContext *C, wmOperator *op) Base *base = link->ptr.data; Object *ob = base->object; - /* The way object type conversion works currently (enforcing conversion of *all* objects using converted - * object-data, even some un-selected/hidden/another scene ones, sounds totally bad to me. + /* The way object type conversion works currently (enforcing conversion of *all* objects + * using converted object-data, even some un-selected/hidden/another scene ones, + * sounds totally bad to me. * However, changing this is more design than bug-fix, not to mention convoluted code below, * so that will be for later. * But at the very least, do not do that with linked IDs! */ @@ -2093,8 +2119,9 @@ static int convert_exec(bContext *C, wmOperator *op) } } - for (nu = cu->nurb.first; nu; nu = nu->next) + for (nu = cu->nurb.first; nu; nu = nu->next) { nu->charidx = 0; + } cu->flag &= ~CU_3D; BKE_curve_curve_dimension_update(cu); @@ -2159,8 +2186,9 @@ static int convert_exec(bContext *C, wmOperator *op) me->totcol = mb->totcol; if (newob->totcol) { me->mat = MEM_dupallocN(mb->mat); - for (a = 0; a < newob->totcol; a++) + for (a = 0; a < newob->totcol; a++) { id_us_plus((ID *)me->mat[a]); + } } convert_ensure_curve_cache(depsgraph, scene, baseob); @@ -2269,9 +2297,10 @@ void OBJECT_OT_convert(wmOperatorType *ot) /* * dupflag: a flag made from constants declared in DNA_userdef_types.h - * The flag tells adduplicate() whether to copy data linked to the object, or to reference the existing data. + * The flag tells adduplicate() whether to copy data linked to the object, + * or to reference the existing data. * U.dupflag for default operations or you can construct a flag as python does - * if the dupflag is 0 then no data will be copied (linked duplicate) */ + * if the dupflag is 0 then no data will be copied (linked duplicate). */ /* used below, assumes id.new is correct */ /* leaves selection of base/object unaltered */ @@ -2310,8 +2339,9 @@ static Base *object_add_duplicate_internal( if (ob->rigidbody_object || ob->rigidbody_constraint) { Collection *collection; for (collection = bmain->collections.first; collection; collection = collection->id.next) { - if (BKE_collection_has_object(collection, ob)) + if (BKE_collection_has_object(collection, ob)) { BKE_collection_object_add(bmain, collection, obn); + } } } } @@ -2372,8 +2402,9 @@ static int duplicate_exec(bContext *C, wmOperator *op) } /* new object becomes active */ - if (BASACT(view_layer) == base) + if (BASACT(view_layer) == base) { ED_object_base_activate(C, basen); + } if (basen->object->data) { DEG_id_tag_update(basen->object->data, 0); @@ -2450,7 +2481,6 @@ static int add_named_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - BKE_scene_object_base_flag_sync_from_object(basen); basen->object->restrictflag &= ~OB_RESTRICT_VIEW; if (event) { @@ -2503,13 +2533,16 @@ static bool join_poll(bContext *C) { Object *ob = CTX_data_active_object(C); - if (!ob || ID_IS_LINKED(ob)) + if (!ob || ID_IS_LINKED(ob)) { return 0; + } - if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_ARMATURE, OB_GPENCIL)) + if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_ARMATURE, OB_GPENCIL)) { return ED_operator_screenactive(C); - else + } + else { return 0; + } } static int join_exec(bContext *C, wmOperator *op) @@ -2532,14 +2565,18 @@ static int join_exec(bContext *C, wmOperator *op) } } - if (ob->type == OB_MESH) + if (ob->type == OB_MESH) { return join_mesh_exec(C, op); - else if (ELEM(ob->type, OB_CURVE, OB_SURF)) + } + else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { return join_curve_exec(C, op); - else if (ob->type == OB_ARMATURE) + } + else if (ob->type == OB_ARMATURE) { return join_armature_exec(C, op); - else if (ob->type == OB_GPENCIL) + } + else if (ob->type == OB_GPENCIL) { return ED_gpencil_join_objects_exec(C, op); + } return OPERATOR_CANCELLED; } @@ -2565,14 +2602,17 @@ static bool join_shapes_poll(bContext *C) { Object *ob = CTX_data_active_object(C); - if (!ob || ID_IS_LINKED(ob)) + if (!ob || ID_IS_LINKED(ob)) { return 0; + } /* only meshes supported at the moment */ - if (ob->type == OB_MESH) + if (ob->type == OB_MESH) { return ED_operator_screenactive(C); - else + } + else { return 0; + } } static int join_shapes_exec(bContext *C, wmOperator *op) @@ -2588,8 +2628,9 @@ static int join_shapes_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - if (ob->type == OB_MESH) + if (ob->type == OB_MESH) { return join_mesh_shapes_exec(C, op); + } return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c index f3138c5afec..70a9870e6ae 100644 --- a/source/blender/editors/object/object_bake.c +++ b/source/blender/editors/object/object_bake.c @@ -196,14 +196,17 @@ static bool multiresbake_check(bContext *C, wmOperator *op) ok = false; } else { - if (ibuf->rect == NULL && ibuf->rect_float == NULL) + if (ibuf->rect == NULL && ibuf->rect_float == NULL) { ok = false; + } - if (ibuf->rect_float && !(ibuf->channels == 0 || ibuf->channels == 4)) + if (ibuf->rect_float && !(ibuf->channels == 0 || ibuf->channels == 4)) { ok = false; + } - if (!ok) + if (!ok) { BKE_report(op->reports, RPT_ERROR, "Baking to unsupported image type"); + } } BKE_image_release_ibuf(ima, ibuf, NULL); @@ -211,8 +214,9 @@ static bool multiresbake_check(bContext *C, wmOperator *op) } } - if (!ok) + if (!ok) { break; + } } CTX_DATA_END; @@ -289,12 +293,15 @@ static void clear_single_image(Image *image, ClearFlag flag) if ((image->id.tag & LIB_TAG_DOIT) == 0) { ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL); - if (flag == CLEAR_TANGENT_NORMAL) + if (flag == CLEAR_TANGENT_NORMAL) { IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? nor_alpha : nor_solid); - else if (flag == CLEAR_DISPLACEMENT) + } + else if (flag == CLEAR_DISPLACEMENT) { IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? disp_alpha : disp_solid); - else + } + else { IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? vec_alpha : vec_solid); + } image->id.tag |= LIB_TAG_DOIT; @@ -332,8 +339,9 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); int objects_baked = 0; - if (!multiresbake_check(C, op)) + if (!multiresbake_check(C, op)) { return OPERATOR_CANCELLED; + } if (scene->r.bake_flag & R_BAKE_CLEAR) { /* clear images */ CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) { @@ -374,7 +382,7 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op) bkr.number_of_rays = scene->r.bake_samples; bkr.threads = BKE_scene_num_threads(scene); bkr.user_scale = (scene->r.bake_flag & R_BAKE_USERSCALE) ? scene->r.bake_user_scale : -1.0f; - //bkr.reports= op->reports; + // bkr.reports= op->reports; /* create low-resolution DM (to bake to) and hi-resolution DM (to bake from) */ bkr.ob_image.array = bake_object_image_get_array(ob); @@ -396,8 +404,9 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op) } CTX_DATA_END; - if (!objects_baked) + if (!objects_baked) { BKE_report(op->reports, RPT_ERROR, "No objects found to bake from"); + } return OPERATOR_FINISHED; } @@ -418,7 +427,7 @@ static void init_multiresbake_job(bContext *C, MultiresBakeJob *bkj) bkj->number_of_rays = scene->r.bake_samples; bkj->threads = BKE_scene_num_threads(scene); bkj->user_scale = (scene->r.bake_flag & R_BAKE_USERSCALE) ? scene->r.bake_user_scale : -1.0f; - //bkj->reports = op->reports; + // bkj->reports = op->reports; CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) { MultiresBakerJobData *data; @@ -475,7 +484,7 @@ static void multiresbake_startjob(void *bkv, short *stop, short *do_update, floa bkr.mode = bkj->mode; bkr.use_lores_mesh = bkj->use_lores_mesh; bkr.user_scale = bkj->user_scale; - //bkr.reports = bkj->reports; + // bkr.reports = bkj->reports; bkr.ob_image.array = data->ob_image.array; bkr.ob_image.len = data->ob_image.len; @@ -541,8 +550,9 @@ static int multiresbake_image_exec(bContext *C, wmOperator *op) MultiresBakeJob *bkr; wmJob *wm_job; - if (!multiresbake_check(C, op)) + if (!multiresbake_check(C, op)) { return OPERATOR_CANCELLED; + } bkr = MEM_callocN(sizeof(MultiresBakeJob), "MultiresBakeJob data"); init_multiresbake_job(C, bkr); @@ -580,8 +590,9 @@ static int multiresbake_image_exec(bContext *C, wmOperator *op) static int objects_bake_render_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) { /* no running blender, remove handler and pass through */ - if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_OBJECT_BAKE_TEXTURE)) + if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_OBJECT_BAKE_TEXTURE)) { return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; + } /* running render */ switch (event->type) { @@ -593,8 +604,9 @@ static int objects_bake_render_modal(bContext *C, wmOperator *UNUSED(op), const static bool is_multires_bake(Scene *scene) { - if (ELEM(scene->r.bake_mode, RE_BAKE_NORMALS, RE_BAKE_DISPLACEMENT, RE_BAKE_AO)) + if (ELEM(scene->r.bake_mode, RE_BAKE_NORMALS, RE_BAKE_DISPLACEMENT, RE_BAKE_AO)) { return scene->r.bake_flag & R_BAKE_MULTIRES; + } return 0; } diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c index fba5a4e281e..5ae757cac56 100644 --- a/source/blender/editors/object/object_bake_api.c +++ b/source/blender/editors/object/object_bake_api.c @@ -137,8 +137,9 @@ static void bake_progress_update(void *bjv, float progress) static int bake_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) { /* no running blender, remove handler and pass through */ - if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_OBJECT_BAKE)) + if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_OBJECT_BAKE)) { return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; + } /* running render */ switch (event->type) { @@ -154,8 +155,9 @@ static int bake_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) * note: this wont check for the escape key being pressed, but doing so isnt threadsafe */ static int bake_break(void *UNUSED(rjv)) { - if (G.is_break) + if (G.is_break) { return 1; + } return 0; } @@ -163,8 +165,9 @@ static void bake_update_image(ScrArea *sa, Image *image) { if (sa && sa->spacetype == SPACE_IMAGE) { /* in case the user changed while baking */ SpaceImage *sima = sa->spacedata.first; - if (sima) + if (sima) { sima->image = image; + } } } @@ -185,8 +188,9 @@ static bool write_internal_bake_pixels(Image *image, ibuf = BKE_image_acquire_ibuf(image, NULL, &lock); - if (!ibuf) + if (!ibuf) { return false; + } if (margin > 0 || !is_clear) { mask_buffer = MEM_callocN(sizeof(char) * num_pixels, "Bake Mask"); @@ -202,14 +206,17 @@ static bool write_internal_bake_pixels(Image *image, from_colorspace = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR); - if (is_float) + if (is_float) { to_colorspace = IMB_colormanagement_get_float_colorspace(ibuf); - else + } + else { to_colorspace = IMB_colormanagement_get_rect_colorspace(ibuf); + } - if (from_colorspace != to_colorspace) + if (from_colorspace != to_colorspace) { IMB_colormanagement_transform( buffer, ibuf->x, ibuf->y, ibuf->channels, from_colorspace, to_colorspace, false); + } } /* populates the ImBuf */ @@ -266,13 +273,15 @@ static bool write_internal_bake_pixels(Image *image, } /* margins */ - if (margin > 0) + if (margin > 0) { RE_bake_margin(ibuf, mask_buffer, margin); + } ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID | IB_BITMAPDIRTY; - if (ibuf->rect_float) + if (ibuf->rect_float) { ibuf->userflags |= IB_RECT_INVALID; + } /* force mipmap recalc */ if (ibuf->mipmap[0]) { @@ -282,8 +291,9 @@ static bool write_internal_bake_pixels(Image *image, BKE_image_release_ibuf(image, ibuf, NULL); - if (mask_buffer) + if (mask_buffer) { MEM_freeN(mask_buffer); + } return true; } @@ -319,8 +329,9 @@ static bool write_external_bake_pixels(const char *filepath, /* create a new ImBuf */ ibuf = IMB_allocImBuf(width, height, im_format->planes, (is_float ? IB_rectfloat : IB_rect)); - if (!ibuf) + if (!ibuf) { return false; + } /* populates the ImBuf */ if (is_float) { @@ -366,15 +377,16 @@ static bool write_external_bake_pixels(const char *filepath, RE_bake_mask_fill(pixel_array, num_pixels, mask_buffer); RE_bake_margin(ibuf, mask_buffer, margin); - if (mask_buffer) + if (mask_buffer) { MEM_freeN(mask_buffer); + } } if ((ok = BKE_imbuf_write(ibuf, filepath, im_format))) { #ifndef WIN32 chmod(filepath, S_IRUSR | S_IWUSR); #endif - //printf("%s saving bake map: '%s'\n", __func__, filepath); + // printf("%s saving bake map: '%s'\n", __func__, filepath); } /* garbage collection */ @@ -570,14 +582,16 @@ static bool bake_objects_check(Main *bmain, if (is_selected_to_active) { int tot_objects = 0; - if (!bake_object_check(view_layer, ob, reports)) + if (!bake_object_check(view_layer, ob, reports)) { return false; + } for (link = selected_objects->first; link; link = link->next) { Object *ob_iter = (Object *)link->ptr.data; - if (ob_iter == ob) + if (ob_iter == ob) { continue; + } if (ELEM(ob_iter->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL) == false) { BKE_reportf(reports, @@ -602,8 +616,9 @@ static bool bake_objects_check(Main *bmain, } for (link = selected_objects->first; link; link = link->next) { - if (!bake_object_check(view_layer, link->ptr.data, reports)) + if (!bake_object_check(view_layer, link->ptr.data, reports)) { return false; + } } } return true; @@ -847,8 +862,9 @@ static int bake(Render *re, for (link = selected_objects->first; link; link = link->next) { Object *ob_iter = link->ptr.data; - if (ob_iter == ob_low) + if (ob_iter == ob_low) { continue; + } tot_highpoly++; } @@ -890,8 +906,9 @@ static int bake(Render *re, me_low = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_low_eval); /* populate the pixel array with the face data */ - if ((is_selected_to_active && (ob_cage == NULL) && is_cage) == false) + if ((is_selected_to_active && (ob_cage == NULL) && is_cage) == false) { RE_bake_pixels_populate(me_low, pixel_array_low, num_pixels, &bake_images, uv_layer); + } /* else populate the pixel array with the 'cage' mesh (the smooth version of the mesh) */ if (is_selected_to_active) { @@ -939,8 +956,9 @@ static int bake(Render *re, for (link = selected_objects->first; link; link = link->next) { Object *ob_iter = link->ptr.data; - if (ob_iter == ob_low) + if (ob_iter == ob_low) { continue; + } /* initialize highpoly_data */ highpoly[i].ob = ob_iter; @@ -1082,8 +1100,9 @@ static int bake(Render *re, ob_low_eval->obmat); BKE_id_free(bmain, me_nores); - if (md) + if (md) { md->mode = mode; + } } break; } @@ -1193,43 +1212,53 @@ static int bake(Render *re, } } - if (is_save_internal) + if (is_save_internal) { refresh_images(&bake_images); + } cleanup: if (highpoly) { int i; for (i = 0; i < tot_highpoly; i++) { - if (highpoly[i].me) + if (highpoly[i].me) { BKE_id_free(bmain, highpoly[i].me); + } } MEM_freeN(highpoly); } - if (mmd_low) + if (mmd_low) { mmd_low->flags = mmd_flags_low; + } - if (pixel_array_low) + if (pixel_array_low) { MEM_freeN(pixel_array_low); + } - if (pixel_array_high) + if (pixel_array_high) { MEM_freeN(pixel_array_high); + } - if (bake_images.data) + if (bake_images.data) { MEM_freeN(bake_images.data); + } - if (bake_images.lookup) + if (bake_images.lookup) { MEM_freeN(bake_images.lookup); + } - if (result) + if (result) { MEM_freeN(result); + } - if (me_low) + if (me_low) { BKE_id_free(bmain, me_low); + } - if (me_cage) + if (me_cage) { BKE_id_free(bmain, me_cage); + } DEG_graph_free(depsgraph); @@ -1492,8 +1521,9 @@ static void bake_startjob(void *bkv, short *UNUSED(stop), short *do_update, floa bkr->sa, bkr->uv_layer); - if (bkr->result == OPERATOR_CANCELLED) + if (bkr->result == OPERATOR_CANCELLED) { return; + } } } @@ -1613,8 +1643,9 @@ static int bake_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event) bake_set_props(op, scene); /* only one render job at a time */ - if (WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_OBJECT_BAKE)) + if (WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_OBJECT_BAKE)) { return OPERATOR_CANCELLED; + } bkr = MEM_mallocN(sizeof(BakeAPIRender), "render bake"); diff --git a/source/blender/editors/object/object_collection.c b/source/blender/editors/object/object_collection.c index 0b22dec99c7..fcaefaf220d 100644 --- a/source/blender/editors/object/object_collection.c +++ b/source/blender/editors/object/object_collection.c @@ -79,8 +79,9 @@ static const EnumPropertyItem *collection_object_active_itemf(bContext *C, /* if 2 or more collections, add option to add to all collections */ collection = NULL; - while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) + while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) { count++; + } if (count >= 2) { item_tmp.identifier = item_tmp.name = "All Collections"; @@ -135,20 +136,23 @@ static int objects_add_active_exec(bContext *C, wmOperator *op) bool is_cycle = false; bool updated = false; - if (ob == NULL) + if (ob == NULL) { return OPERATOR_CANCELLED; + } /* now add all selected objects to the collection(s) */ - FOREACH_COLLECTION_BEGIN(bmain, scene, Collection *, collection) - { - if (single_collection && collection != single_collection) + FOREACH_COLLECTION_BEGIN (bmain, scene, Collection *, collection) { + if (single_collection && collection != single_collection) { continue; - if (!BKE_collection_has_object(collection, ob)) + } + if (!BKE_collection_has_object(collection, ob)) { continue; + } CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) { - if (BKE_collection_has_object(collection, base->object)) + if (BKE_collection_has_object(collection, base->object)) { continue; + } if (!BKE_collection_object_cyclic_check(bmain, base->object, collection)) { BKE_collection_object_add(bmain, collection, base->object); @@ -163,11 +167,13 @@ static int objects_add_active_exec(bContext *C, wmOperator *op) } FOREACH_COLLECTION_END; - if (is_cycle) + if (is_cycle) { BKE_report(op->reports, RPT_WARNING, "Skipped some collections because of cycle detected"); + } - if (!updated) + if (!updated) { return OPERATOR_CANCELLED; + } DEG_relations_tag_update(bmain); WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL); @@ -215,15 +221,16 @@ static int objects_remove_active_exec(bContext *C, wmOperator *op) bmain, scene, ob, single_collection_index); bool ok = false; - if (ob == NULL) + if (ob == NULL) { return OPERATOR_CANCELLED; + } /* Linking to same collection requires its own loop so we can avoid * looking up the active objects collections each time. */ - FOREACH_COLLECTION_BEGIN(bmain, scene, Collection *, collection) - { - if (single_collection && collection != single_collection) + FOREACH_COLLECTION_BEGIN (bmain, scene, Collection *, collection) { + if (single_collection && collection != single_collection) { continue; + } if (BKE_collection_has_object(collection, ob)) { /* Remove collections from selected objects */ @@ -237,8 +244,9 @@ static int objects_remove_active_exec(bContext *C, wmOperator *op) } FOREACH_COLLECTION_END; - if (!ok) + if (!ok) { BKE_report(op->reports, RPT_ERROR, "Active object contains no collections"); + } DEG_relations_tag_update(bmain); WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL); @@ -316,15 +324,17 @@ static int collection_objects_remove_exec(bContext *C, wmOperator *op) bmain, scene, ob, single_collection_index); bool updated = false; - if (ob == NULL) + if (ob == NULL) { return OPERATOR_CANCELLED; + } - FOREACH_COLLECTION_BEGIN(bmain, scene, Collection *, collection) - { - if (single_collection && collection != single_collection) + FOREACH_COLLECTION_BEGIN (bmain, scene, Collection *, collection) { + if (single_collection && collection != single_collection) { continue; - if (!BKE_collection_has_object(collection, ob)) + } + if (!BKE_collection_has_object(collection, ob)) { continue; + } /* now remove all selected objects from the collection */ CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) { @@ -336,8 +346,9 @@ static int collection_objects_remove_exec(bContext *C, wmOperator *op) } FOREACH_COLLECTION_END; - if (!updated) + if (!updated) { return OPERATOR_CANCELLED; + } DEG_relations_tag_update(bmain); WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL); @@ -421,8 +432,9 @@ static int collection_add_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_object_context(C); Main *bmain = CTX_data_main(C); - if (ob == NULL) + if (ob == NULL) { return OPERATOR_CANCELLED; + } Collection *collection = BKE_collection_add(bmain, NULL, "Collection"); id_fake_user_set(&collection->id); @@ -457,8 +469,9 @@ static int collection_link_exec(bContext *C, wmOperator *op) Object *ob = ED_object_context(C); Collection *collection = BLI_findlink(&bmain->collections, RNA_enum_get(op->ptr, "collection")); - if (ELEM(NULL, ob, collection)) + if (ELEM(NULL, ob, collection)) { return OPERATOR_CANCELLED; + } /* Early return check, if the object is already in collection * we could skip all the dependency check and just consider @@ -468,7 +481,7 @@ static int collection_link_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } - /* Adding object to collection which is used as duplicollection for self is bad idea. + /* Adding object to collection which is used as dupli-collection for self is bad idea. * * It is also bad idea to add object to collection which is in collection which * contains our current object. @@ -520,8 +533,9 @@ static int collection_remove_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_object_context(C); Collection *collection = CTX_data_pointer_get_type(C, "collection", &RNA_Collection).data; - if (!ob || !collection) + if (!ob || !collection) { return OPERATOR_CANCELLED; + } BKE_collection_object_remove(bmain, collection, ob, false); @@ -553,8 +567,9 @@ static int collection_unlink_exec(bContext *C, wmOperator *UNUSED(op)) Main *bmain = CTX_data_main(C); Collection *collection = CTX_data_pointer_get_type(C, "collection", &RNA_Collection).data; - if (!collection) + if (!collection) { return OPERATOR_CANCELLED; + } BKE_id_delete(bmain, collection); @@ -586,8 +601,9 @@ static int select_grouped_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene = CTX_data_scene(C); Collection *collection = CTX_data_pointer_get_type(C, "collection", &RNA_Collection).data; - if (!collection) + if (!collection) { return OPERATOR_CANCELLED; + } CTX_DATA_BEGIN (C, Base *, base, visible_bases) { if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLE) != 0)) { diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index c571fc6821e..6a587bd6e2a 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -79,18 +79,21 @@ /* if object in posemode, active bone constraints, else object constraints */ ListBase *get_active_constraints(Object *ob) { - if (ob == NULL) + if (ob == NULL) { return NULL; + } if (ob->mode & OB_MODE_POSE) { bPoseChannel *pchan; pchan = BKE_pose_channel_active(ob); - if (pchan) + if (pchan) { return &pchan->constraints; + } } - else + else { return &ob->constraints; + } return NULL; } @@ -99,11 +102,13 @@ ListBase *get_active_constraints(Object *ob) * and/or also get the posechannel this is from (if applicable) */ ListBase *get_constraint_lb(Object *ob, bConstraint *con, bPoseChannel **r_pchan) { - if (r_pchan) + if (r_pchan) { *r_pchan = NULL; + } - if (ELEM(NULL, ob, con)) + if (ELEM(NULL, ob, con)) { return NULL; + } /* try object constraints first */ if ((BLI_findindex(&ob->constraints, con) != -1)) { @@ -120,8 +125,9 @@ ListBase *get_constraint_lb(Object *ob, bConstraint *con, bPoseChannel **r_pchan for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { if ((BLI_findindex(&pchan->constraints, con) != -1)) { - if (r_pchan) + if (r_pchan) { *r_pchan = pchan; + } return &pchan->constraints; } @@ -153,8 +159,9 @@ static void validate_pyconstraint_cb(Main *bmain, void *arg1, void *arg2) /* exception for no script */ if (index) { /* innovative use of a for...loop to search */ - for (text = bmain->texts.first, i = 1; text && index != i; i++, text = text->id.next) + for (text = bmain->texts.first, i = 1; text && index != i; i++, text = text->id.next) { ; + } } data->text = text; } @@ -173,14 +180,16 @@ static char *buildmenu_pyconstraints(Main *bmain, Text *con_text, int *pyconinde BLI_dynstr_append(pupds, buf); /* init active-index first */ - if (con_text == NULL) + if (con_text == NULL) { *pyconindex = 0; + } /* loop through markers, adding them */ for (text = bmain->texts.first, i = 1; text; i++, text = text->id.next) { /* this is important to ensure that right script is shown as active */ - if (text == con_text) + if (text == con_text) { *pyconindex = i; + } /* only include valid pyconstraint scripts */ if (BPY_is_pyconstraint(text)) { @@ -189,8 +198,9 @@ static char *buildmenu_pyconstraints(Main *bmain, Text *con_text, int *pyconinde sprintf(buf, "%%x%d", i); BLI_dynstr_append(pupds, buf); - if (text->id.next) + if (text->id.next) { BLI_dynstr_append(pupds, "|"); + } } } @@ -234,10 +244,12 @@ static void set_constraint_nth_target(bConstraint *con, num_targets = BLI_listbase_count(&targets); if (index < 0) { - if (abs(index) < num_targets) + if (abs(index) < num_targets) { index = num_targets - abs(index); - else + } + else { index = num_targets - 1; + } } else if (index >= num_targets) { index = num_targets - 1; @@ -251,8 +263,9 @@ static void set_constraint_nth_target(bConstraint *con, } } - if (cti->flush_constraint_targets) + if (cti->flush_constraint_targets) { cti->flush_constraint_targets(con, &targets, 0); + } } } @@ -338,27 +351,33 @@ static void test_constraint( bFollowPathConstraint *data = con->data; /* don't allow track/up axes to be the same */ - if (data->upflag == data->trackflag) + if (data->upflag == data->trackflag) { con->flag |= CONSTRAINT_DISABLE; - if (data->upflag + 3 == data->trackflag) + } + if (data->upflag + 3 == data->trackflag) { con->flag |= CONSTRAINT_DISABLE; + } } else if (con->type == CONSTRAINT_TYPE_TRACKTO) { bTrackToConstraint *data = con->data; /* don't allow track/up axes to be the same */ - if (data->reserved2 == data->reserved1) + if (data->reserved2 == data->reserved1) { con->flag |= CONSTRAINT_DISABLE; - if (data->reserved2 + 3 == data->reserved1) + } + if (data->reserved2 + 3 == data->reserved1) { con->flag |= CONSTRAINT_DISABLE; + } } else if (con->type == CONSTRAINT_TYPE_LOCKTRACK) { bLockTrackConstraint *data = con->data; - if (data->lockflag == data->trackflag) + if (data->lockflag == data->trackflag) { con->flag |= CONSTRAINT_DISABLE; - if (data->lockflag + 3 == data->trackflag) + } + if (data->lockflag + 3 == data->trackflag) { con->flag |= CONSTRAINT_DISABLE; + } } else if (con->type == CONSTRAINT_TYPE_SPLINEIK) { bSplineIKConstraint *data = con->data; @@ -385,17 +404,20 @@ static void test_constraint( MovieTracking *tracking = &data->clip->tracking; MovieTrackingObject *tracking_object; - if (data->object[0]) + if (data->object[0]) { tracking_object = BKE_tracking_object_get_named(tracking, data->object); - else + } + else { tracking_object = BKE_tracking_object_get_camera(tracking); + } if (!tracking_object) { con->flag |= CONSTRAINT_DISABLE; } else { - if (!BKE_tracking_track_get_named(tracking, tracking_object, data->track)) + if (!BKE_tracking_track_get_named(tracking, tracking_object, data->track)) { con->flag |= CONSTRAINT_DISABLE; + } } } else { @@ -406,14 +428,16 @@ static void test_constraint( else if (con->type == CONSTRAINT_TYPE_CAMERASOLVER) { bCameraSolverConstraint *data = con->data; - if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == NULL)) + if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == NULL)) { con->flag |= CONSTRAINT_DISABLE; + } } else if (con->type == CONSTRAINT_TYPE_OBJECTSOLVER) { bObjectSolverConstraint *data = con->data; - if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == NULL)) + if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == NULL)) { con->flag |= CONSTRAINT_DISABLE; + } } else if (con->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) { bTransformCacheConstraint *data = con->data; @@ -494,8 +518,9 @@ static void test_constraint( } /* free any temporary targets */ - if (cti->flush_constraint_targets) + if (cti->flush_constraint_targets) { cti->flush_constraint_targets(con, &targets, 0); + } } } @@ -513,8 +538,9 @@ static int constraint_type_get(Object *owner, bPoseChannel *pchan) break; } } - else + else { type = CONSTRAINT_OBTYPE_OBJECT; + } return type; } @@ -527,8 +553,9 @@ static void test_constraints(Main *bmain, Object *owner, bPoseChannel *pchan) ListBase *conlist = NULL; int type; - if (owner == NULL) + if (owner == NULL) { return; + } type = constraint_type_get(owner, pchan); @@ -552,15 +579,17 @@ static void test_constraints(Main *bmain, Object *owner, bPoseChannel *pchan) void object_test_constraints(Main *bmain, Object *owner) { - if (owner->constraints.first) + if (owner->constraints.first) { test_constraints(bmain, owner, NULL); + } if (owner->type == OB_ARMATURE && owner->pose) { bPoseChannel *pchan; for (pchan = owner->pose->chanbase.first; pchan; pchan = pchan->next) { - if (pchan->constraints.first) + if (pchan->constraints.first) { test_constraints(bmain, owner, pchan); + } } } } @@ -586,7 +615,7 @@ static void object_test_constraint(Main *bmain, Object *owner, bConstraint *con) } } -/************************ generic functions for operators using constraint names and data context *********************/ +/*** generic functions for operators using constraint names and data context *********************/ #define EDIT_CONSTRAINT_OWNER_OBJECT 0 #define EDIT_CONSTRAINT_OWNER_BONE 1 @@ -653,8 +682,9 @@ static int edit_constraint_invoke_properties(bContext *C, wmOperator *op) ListBase *list; if (RNA_struct_property_is_set(op->ptr, "constraint") && - RNA_struct_property_is_set(op->ptr, "owner")) + RNA_struct_property_is_set(op->ptr, "owner")) { return 1; + } if (ptr.data) { con = ptr.data; @@ -662,10 +692,12 @@ static int edit_constraint_invoke_properties(bContext *C, wmOperator *op) list = get_constraint_lb(ob, con, NULL); - if (&ob->constraints == list) + if (&ob->constraints == list) { RNA_enum_set(op->ptr, "owner", EDIT_CONSTRAINT_OWNER_OBJECT); - else + } + else { RNA_enum_set(op->ptr, "owner", EDIT_CONSTRAINT_OWNER_BONE); + } return 1; } @@ -687,26 +719,38 @@ static bConstraint *edit_constraint_property_get(wmOperator *op, Object *ob, int } else if (owner == EDIT_CONSTRAINT_OWNER_BONE) { bPoseChannel *pchan = BKE_pose_channel_active(ob); - if (pchan) + if (pchan) { list = &pchan->constraints; + } else { - //if (G.debug & G_DEBUG) - //printf("edit_constraint_property_get: No active bone for object '%s'\n", (ob) ? ob->id.name + 2 : "<None>"); +#if 0 + if (G.debug & G_DEBUG) { + printf("edit_constraint_property_get: No active bone for object '%s'\n", + (ob) ? ob->id.name + 2 : "<None>"); + } +#endif return NULL; } } else { - //if (G.debug & G_DEBUG) - //printf("edit_constraint_property_get: defaulting to getting list in the standard way\n"); +#if 0 + if (G.debug & G_DEBUG) { + printf("edit_constraint_property_get: defaulting to getting list in the standard way\n"); + } +#endif list = get_active_constraints(ob); } con = BKE_constraints_find_name(list, constraint_name); - //if (G.debug & G_DEBUG) - //printf("constraint found = %p, %s\n", (void *)con, (con) ? con->name : "<Not found>"); +#if 0 + if (G.debug & G_DEBUG) { + printf("constraint found = %p, %s\n", (void *)con, (con) ? con->name : "<Not found>"); + } +#endif - if (con && (type != 0) && (con->type != type)) + if (con && (type != 0) && (con->type != type)) { con = NULL; + } return con; } @@ -724,8 +768,9 @@ static int stretchto_reset_exec(bContext *C, wmOperator *op) bStretchToConstraint *data = (con) ? (bStretchToConstraint *)con->data : NULL; /* despite 3 layers of checks, we may still not be able to find a constraint */ - if (data == NULL) + if (data == NULL) { return OPERATOR_CANCELLED; + } /* just set original length to 0.0, which will cause a reset on next recalc */ data->orglength = 0.0f; @@ -737,10 +782,12 @@ static int stretchto_reset_exec(bContext *C, wmOperator *op) static int stretchto_reset_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_constraint_invoke_properties(C, op)) + if (edit_constraint_invoke_properties(C, op)) { return stretchto_reset_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void CONSTRAINT_OT_stretchto_reset(wmOperatorType *ot) @@ -770,8 +817,9 @@ static int limitdistance_reset_exec(bContext *C, wmOperator *op) bDistLimitConstraint *data = (con) ? (bDistLimitConstraint *)con->data : NULL; /* despite 3 layers of checks, we may still not be able to find a constraint */ - if (data == NULL) + if (data == NULL) { return OPERATOR_CANCELLED; + } /* just set original length to 0.0, which will cause a reset on next recalc */ data->dist = 0.0f; @@ -783,10 +831,12 @@ static int limitdistance_reset_exec(bContext *C, wmOperator *op) static int limitdistance_reset_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_constraint_invoke_properties(C, op)) + if (edit_constraint_invoke_properties(C, op)) { return limitdistance_reset_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void CONSTRAINT_OT_limitdistance_reset(wmOperatorType *ot) @@ -928,10 +978,12 @@ static int childof_set_inverse_exec(bContext *C, wmOperator *op) static int childof_set_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_constraint_invoke_properties(C, op)) + if (edit_constraint_invoke_properties(C, op)) { return childof_set_inverse_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void CONSTRAINT_OT_childof_set_inverse(wmOperatorType *ot) @@ -977,10 +1029,12 @@ static int childof_clear_inverse_exec(bContext *C, wmOperator *op) static int childof_clear_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_constraint_invoke_properties(C, op)) + if (edit_constraint_invoke_properties(C, op)) { return childof_clear_inverse_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void CONSTRAINT_OT_childof_clear_inverse(wmOperatorType *ot) @@ -1065,8 +1119,9 @@ static int followpath_path_animate_exec(bContext *C, wmOperator *op) data->followflag |= FOLLOWPATH_STATIC; /* path needs to be freed */ - if (path) + if (path) { MEM_freeN(path); + } } /* setup dummy 'generator' modifier here to get 1-1 correspondence still working @@ -1171,10 +1226,12 @@ static int objectsolver_set_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_constraint_invoke_properties(C, op)) + if (edit_constraint_invoke_properties(C, op)) { return objectsolver_set_inverse_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void CONSTRAINT_OT_objectsolver_set_inverse(wmOperatorType *ot) @@ -1219,10 +1276,12 @@ static int objectsolver_clear_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_constraint_invoke_properties(C, op)) + if (edit_constraint_invoke_properties(C, op)) { return objectsolver_clear_inverse_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void CONSTRAINT_OT_objectsolver_clear_inverse(wmOperatorType *ot) @@ -1252,33 +1311,38 @@ void ED_object_constraint_set_active(Object *ob, bConstraint *con) /* lets be nice and escape if its active already */ /* NOTE: this assumes that the stack doesn't have other active ones set... */ - if ((lb && con) && (con->flag & CONSTRAINT_ACTIVE)) + if ((lb && con) && (con->flag & CONSTRAINT_ACTIVE)) { return; + } BKE_constraints_active_set(lb, con); } void ED_object_constraint_update(Main *bmain, Object *ob) { - if (ob->pose) + if (ob->pose) { BKE_pose_update_constraint_flags(ob->pose); + } object_test_constraints(bmain, ob); - if (ob->type == OB_ARMATURE) + if (ob->type == OB_ARMATURE) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_TRANSFORM); - else + } + else { DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM); + } } static void object_pose_tag_update(Main *bmain, Object *ob) { BKE_pose_tag_recalc(bmain, ob->pose); /* Checks & sort pose channels. */ if (ob->proxy && ob->adt) { - /* We need to make use of ugly POSE_ANIMATION_WORKAROUND here too, else anim data are not reloaded - * after calling `BKE_pose_rebuild()`, which causes T43872. - * Note that this is a bit wide here, since we cannot be sure whether there are some locked proxy bones - * or not... + /* We need to make use of ugly #POSE_ANIMATION_WORKAROUND here too, + * else anim data are not reloaded after calling `BKE_pose_rebuild()`, + * which causes T43872. + * Note that this is a bit wide here, since we cannot be sure whether there are some locked + * proxy bones or not. * XXX Temp hack until new depsgraph hopefully solves this. */ DEG_id_tag_update(&ob->id, ID_RECALC_ANIMATION); } @@ -1304,10 +1368,12 @@ void ED_object_constraint_tag_update(Main *bmain, Object *ob, bConstraint *con) object_test_constraint(bmain, ob, con); } - if (ob->type == OB_ARMATURE) + if (ob->type == OB_ARMATURE) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_TRANSFORM); - else + } + else { DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM); + } /* Do Copy-on-Write tag here too, otherwise constraint * influence/mute buttons in UI have no effect @@ -1398,10 +1464,12 @@ static int constraint_move_down_exec(bContext *C, wmOperator *op) static int constraint_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_constraint_invoke_properties(C, op)) + if (edit_constraint_invoke_properties(C, op)) { return constraint_move_down_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void CONSTRAINT_OT_move_down(wmOperatorType *ot) @@ -1446,10 +1514,12 @@ static int constraint_move_up_exec(bContext *C, wmOperator *op) static int constraint_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_constraint_invoke_properties(C, op)) + if (edit_constraint_invoke_properties(C, op)) { return constraint_move_up_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void CONSTRAINT_OT_move_up(wmOperatorType *ot) @@ -1479,8 +1549,7 @@ static int pose_constraints_clear_exec(bContext *C, wmOperator *UNUSED(op)) Object *prev_ob = NULL; /* free constraints for all selected bones */ - CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) - { + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) { BKE_constraints_free(&pchan->constraints); pchan->constflag &= ~(PCHAN_HAS_IK | PCHAN_HAS_SPLINEIK | PCHAN_HAS_CONST); @@ -1561,8 +1630,7 @@ static int pose_constraint_copy_exec(bContext *C, wmOperator *op) Object *prev_ob = NULL; /* copy all constraints from active posebone to all selected posebones */ - CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, chan, selected_pose_bones, Object *, ob) - { + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, chan, selected_pose_bones, Object *, ob) { /* if we're not handling the object we're copying from, copy all constraints over */ if (pchan != chan) { BKE_constraints_copy(&chan->constraints, &pchan->constraints, true); @@ -1760,13 +1828,14 @@ static bool get_new_constraint_target( /* transform cent to global coords for loc */ if (pchanact) { - /* since by default, IK targets the tip of the last bone, use the tip of the active PoseChannel - * if adding a target for an IK Constraint - */ - if (con_type == CONSTRAINT_TYPE_KINEMATIC) + /* Since by default, IK targets the tip of the last bone, + * use the tip of the active PoseChannel if adding a target for an IK Constraint. */ + if (con_type == CONSTRAINT_TYPE_KINEMATIC) { mul_v3_m4v3(obt->loc, obact->obmat, pchanact->pose_tail); - else + } + else { mul_v3_m4v3(obt->loc, obact->obmat, pchanact->pose_head); + } } else { copy_v3_v3(obt->loc, obact->obmat[3]); @@ -1774,7 +1843,7 @@ static bool get_new_constraint_target( /* restore, BKE_object_add sets active */ BASACT(view_layer) = base; - base->flag |= BASE_SELECTED; + ED_object_base_select(base, BA_SELECT); /* make our new target the new object */ *tar_ob = obt; @@ -1818,11 +1887,14 @@ static int constraint_add_exec( return OPERATOR_CANCELLED; } - /* create a new constraint of the type required, and add it to the active/given constraints list */ - if (pchan) + /* Create a new constraint of the type required, + * and add it to the active/given constraints list. */ + if (pchan) { con = BKE_constraint_add_for_pose(ob, pchan, NULL, type); - else + } + else { con = BKE_constraint_add_for_object(ob, NULL, type); + } /* get the first selected object/bone, and make that the target * - apart from the buttons-window add buttons, we shouldn't add in this way @@ -1833,13 +1905,15 @@ static int constraint_add_exec( /* get the target objects, adding them as need be */ if (get_new_constraint_target(C, type, &tar_ob, &tar_pchan, 1)) { - /* method of setting target depends on the type of target we've got - * - by default, just set the first target (distinction here is only for multiple-targeted constraints) + /* Method of setting target depends on the type of target we've got - by default, + * just set the first target (distinction here is only for multiple-targeted constraints). */ - if (tar_pchan) + if (tar_pchan) { set_constraint_nth_target(con, tar_ob, tar_pchan->name, 0); - else + } + else { set_constraint_nth_target(con, tar_ob, "", 0); + } } } @@ -1874,8 +1948,9 @@ static int constraint_add_exec( /* make sure all settings are valid - similar to above checks, but sometimes can be wrong */ object_test_constraints(bmain, ob); - if (pchan) + if (pchan) { BKE_pose_update_constraint_flags(ob->pose); + } /* force depsgraph to get recalculated since new relationships added */ DEG_relations_tag_update(bmain); @@ -1883,15 +1958,16 @@ static int constraint_add_exec( if ((ob->type == OB_ARMATURE) && (pchan)) { BKE_pose_tag_recalc(bmain, ob->pose); /* sort pose channels */ if (BKE_constraints_proxylocked_owner(ob, pchan) && ob->adt) { - /* We need to make use of ugly POSE_ANIMATION_WORKAROUND here too, else anim data are not reloaded - * after calling `BKE_pose_rebuild()`, which causes T43872. + /* We need to make use of ugly POSE_ANIMATION_WORKAROUND here too, + * else anim data are not reloaded after calling `BKE_pose_rebuild()`, which causes T43872. * XXX Temp hack until new depsgraph hopefully solves this. */ DEG_id_tag_update(&ob->id, ID_RECALC_ANIMATION); } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_TRANSFORM); } - else + else { DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM); + } /* notifiers for updates */ WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_ADDED, ob); @@ -1916,8 +1992,9 @@ static int object_constraint_add_exec(bContext *C, wmOperator *op) /* hack: set constraint targets from selected objects in context is allowed when * operator name included 'with_targets', since the menu doesn't allow multiple properties */ - if (strstr(op->idname, "with_targets")) + if (strstr(op->idname, "with_targets")) { with_targets = 1; + } return constraint_add_exec(C, op, ob, &ob->constraints, type, with_targets); } @@ -1937,8 +2014,9 @@ static int pose_constraint_add_exec(bContext *C, wmOperator *op) /* hack: set constraint targets from selected objects in context is allowed when * operator name included 'with_targets', since the menu doesn't allow multiple properties */ - if (strstr(op->idname, "with_targets")) + if (strstr(op->idname, "with_targets")) { with_targets = 1; + } return constraint_add_exec(C, op, ob, get_active_constraints(ob), type, with_targets); } @@ -2049,8 +2127,9 @@ static int pose_ik_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED /* bone must not have any constraints already */ for (con = pchan->constraints.first; con; con = con->next) { - if (con->type == CONSTRAINT_TYPE_KINEMATIC) + if (con->type == CONSTRAINT_TYPE_KINEMATIC) { break; + } } if (con) { BKE_report(op->reports, RPT_ERROR, "Bone already has an IK constraint"); @@ -2066,12 +2145,14 @@ static int pose_ik_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED /* bone target, or object target? * - the only thing that matters is that we want a target... */ - if (tar_pchan) + if (tar_pchan) { uiItemBooleanO( layout, IFACE_("To Active Bone"), ICON_NONE, "POSE_OT_ik_add", "with_targets", 1); - else + } + else { uiItemBooleanO( layout, IFACE_("To Active Object"), ICON_NONE, "POSE_OT_ik_add", "with_targets", 1); + } } else { /* we have a choice of adding to a new empty, or not setting any target (targetless IK) */ @@ -2093,7 +2174,8 @@ static int pose_ik_add_exec(bContext *C, wmOperator *op) Object *ob = CTX_data_active_object(C); const bool with_targets = RNA_boolean_get(op->ptr, "with_targets"); - /* add the constraint - all necessary checks should have been done by the invoke() callback already... */ + /* add the constraint - all necessary checks should have + * been done by the invoke() callback already... */ return constraint_add_exec( C, op, ob, get_active_constraints(ob), CONSTRAINT_TYPE_KINEMATIC, with_targets); } @@ -2129,11 +2211,11 @@ static int pose_ik_clear_exec(bContext *C, wmOperator *UNUSED(op)) Object *prev_ob = NULL; /* only remove IK Constraints */ - CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) - { + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) { bConstraint *con, *next; - /* TODO: should we be checking if these constraints were local before we try and remove them? */ + /* TODO: should we be checking if these constraints were local + * before we try and remove them? */ for (con = pchan->constraints.first; con; con = next) { next = con->next; if (con->type == CONSTRAINT_TYPE_KINEMATIC) { diff --git a/source/blender/editors/object/object_data_transfer.c b/source/blender/editors/object/object_data_transfer.c index 57c7ff1535d..690bc270605 100644 --- a/source/blender/editors/object/object_data_transfer.c +++ b/source/blender/editors/object/object_data_transfer.c @@ -65,11 +65,12 @@ static const EnumPropertyItem DT_layer_items[] = { "Vertex Group(s)", "Transfer active or all vertex groups"}, #if 0 /* XXX For now, would like to finish/merge work from 2014 gsoc first. */ - {DT_TYPE_SHAPEKEY, "SHAPEKEYS", 0, "Shapekey(s)", "Transfer active or all shape keys"}, + {DT_TYPE_SHAPEKEY, "SHAPEKEYS", 0, "Shapekey(s)", "Transfer active or all shape keys"}, #endif -#if 0 /* XXX When SkinModifier is enabled, - * it seems to erase its own CD_MVERT_SKIN layer from final DM :( */ - {DT_TYPE_SKIN, "SKIN", 0, "Skin Weight", "Transfer skin weights"}, +/* XXX When SkinModifier is enabled, + * it seems to erase its own CD_MVERT_SKIN layer from final DM :( */ +#if 0 + {DT_TYPE_SKIN, "SKIN", 0, "Skin Weight", "Transfer skin weights"}, #endif {DT_TYPE_BWEIGHT_VERT, "BEVEL_WEIGHT_VERT", 0, "Bevel Weight", "Transfer bevel weights"}, {0, "", 0, "Edge Data", ""}, @@ -519,7 +520,8 @@ static int data_transfer_exec(bContext *C, wmOperator *op) } /* Used by both OBJECT_OT_data_transfer and OBJECT_OT_datalayout_transfer */ -/* Note this context poll is only really partial, it cannot check for all possible invalid cases. */ +/* Note this context poll is only really partial, + * it cannot check for all possible invalid cases. */ static bool data_transfer_poll(bContext *C) { Object *ob = ED_object_active_context(C); @@ -772,8 +774,8 @@ static int datalayout_transfer_exec(bContext *C, wmOperator *op) dtmd = (DataTransferModifierData *)edit_modifier_property_get( op, ob_act, eModifierType_DataTransfer); - /* If we have a modifier, we transfer data layout from this modifier's source object to active one. - * Else, we transfer data layout from active object to all selected ones. */ + /* If we have a modifier, we transfer data layout from this modifier's source object to + * active one. Else, we transfer data layout from active object to all selected ones. */ if (dtmd) { Object *ob_src = dtmd->ob_source; Object *ob_dst = ob_act; @@ -840,6 +842,7 @@ static int datalayout_transfer_exec(bContext *C, wmOperator *op) BLI_freelistN(&ctx_objects); } + DEG_relations_tag_update(CTX_data_main(C)); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, NULL); return OPERATOR_FINISHED; diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 4e532b0ab41..795e1dd66a5 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -139,8 +139,9 @@ Object *ED_object_active_context(bContext *C) Object *ob = NULL; if (C) { ob = ED_object_context(C); - if (!ob) + if (!ob) { ob = CTX_data_active_object(C); + } } return ob; } @@ -702,8 +703,6 @@ static int editmode_toggle_exec(bContext *C, wmOperator *op) } } - ED_space_image_uv_sculpt_update(bmain, CTX_wm_manager(C), scene); - WM_msg_publish_rna_prop(mbus, &obact->id, obact, Object, mode); if (G.background == false) { @@ -718,8 +717,9 @@ static bool editmode_toggle_poll(bContext *C) Object *ob = CTX_data_active_object(C); /* covers proxies too */ - if (ELEM(NULL, ob, ob->data) || ID_IS_LINKED(ob->data)) + if (ELEM(NULL, ob, ob->data) || ID_IS_LINKED(ob->data)) { return 0; + } /* if hidden but in edit mode, we still display */ if ((ob->restrictflag & OB_RESTRICT_VIEW) && !(ob->mode & OB_MODE_EDIT)) { @@ -857,12 +857,15 @@ static int forcefield_toggle_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = CTX_data_active_object(C); - if (ob->pd == NULL) + if (ob->pd == NULL) { ob->pd = BKE_partdeflect_new(PFIELD_FORCE); - else if (ob->pd->forcefield == 0) + } + else if (ob->pd->forcefield == 0) { ob->pd->forcefield = PFIELD_FORCE; - else + } + else { ob->pd->forcefield = 0; + } ED_object_check_force_modifiers(CTX_data_main(C), CTX_data_scene(C), ob); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); @@ -935,8 +938,9 @@ static int object_calculate_paths_invoke(bContext *C, wmOperator *op, const wmEv { Object *ob = CTX_data_active_object(C); - if (ob == NULL) + if (ob == NULL) { return OPERATOR_CANCELLED; + } /* set default settings from existing/stored settings */ { @@ -1032,8 +1036,9 @@ static int object_update_paths_exec(bContext *C, wmOperator *UNUSED(op)) { Scene *scene = CTX_data_scene(C); - if (scene == NULL) + if (scene == NULL) { return OPERATOR_CANCELLED; + } /* calculate the paths for objects that have them (and are tagged to get refreshed) */ ED_objects_recalculate_paths(C, scene, false); @@ -1204,10 +1209,12 @@ static int shade_smooth_exec(bContext *C, wmOperator *op) cu = ob->data; for (nu = cu->nurb.first; nu; nu = nu->next) { - if (!clear) + if (!clear) { nu->flag |= ME_SMOOTH; - else + } + else { nu->flag &= ~ME_SMOOTH; + } } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); @@ -1218,8 +1225,9 @@ static int shade_smooth_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - if (linked_data) + if (linked_data) { BKE_report(op->reports, RPT_WARNING, "Can't edit linked mesh or curve data"); + } return (done) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } @@ -1271,8 +1279,9 @@ static const EnumPropertyItem *object_mode_set_itemsf(bContext *C, Object *ob; int totitem = 0; - if (!C) /* needed for docs */ + if (!C) { /* needed for docs */ return rna_enum_object_mode_items; + } ob = CTX_data_active_object(C); if (ob) { @@ -1320,10 +1329,12 @@ static bool object_mode_set_poll(bContext *C) * to still work in that case when there's no active object * so that users can exit editmode this way as per normal. */ - if (ED_operator_object_active_editable(C)) + if (ED_operator_object_active_editable(C)) { return true; - else + } + else { return (CTX_data_gpencil_data(C) != NULL); + } } static int object_mode_set_exec(bContext *C, wmOperator *op) @@ -1354,8 +1365,9 @@ static int object_mode_set_exec(bContext *C, wmOperator *op) mode = OB_MODE_EDIT_GPENCIL; } - if (!ob || !ED_object_mode_compat_test(ob, mode)) + if (!ob || !ED_object_mode_compat_test(ob, mode)) { return OPERATOR_PASS_THROUGH; + } if (ob->mode != mode) { /* we should be able to remove this call, each operator calls */ @@ -1406,7 +1418,7 @@ void OBJECT_OT_mode_set(wmOperatorType *ot) /* api callbacks */ ot->exec = object_mode_set_exec; - ot->poll = object_mode_set_poll; //ED_operator_object_active_editable; + ot->poll = object_mode_set_poll; // ED_operator_object_active_editable; /* flags */ ot->flag = 0; /* no register/undo here, leave it to operators being called */ @@ -1432,7 +1444,7 @@ void OBJECT_OT_mode_set_or_submode(wmOperatorType *ot) /* api callbacks */ ot->exec = object_mode_set_exec; - ot->poll = object_mode_set_poll; //ED_operator_object_active_editable; + ot->poll = object_mode_set_poll; // ED_operator_object_active_editable; /* flags */ ot->flag = 0; /* no register/undo here, leave it to operators being called */ diff --git a/source/blender/editors/object/object_facemap_ops.c b/source/blender/editors/object/object_facemap_ops.c index a77cfab031d..0081e18f33c 100644 --- a/source/blender/editors/object/object_facemap_ops.c +++ b/source/blender/editors/object/object_facemap_ops.c @@ -56,8 +56,9 @@ void ED_object_facemap_face_add(Object *ob, bFaceMap *fmap, int facenum) { int fmap_nr; - if (GS(((ID *)ob->data)->name) != ID_ME) + if (GS(((ID *)ob->data)->name) != ID_ME) { return; + } /* get the face map number, exit if it can't be found */ fmap_nr = BLI_findindex(&ob->fmaps, fmap); @@ -67,8 +68,9 @@ void ED_object_facemap_face_add(Object *ob, bFaceMap *fmap, int facenum) Mesh *me = ob->data; /* if there's is no facemap layer then create one */ - if ((facemap = CustomData_get_layer(&me->pdata, CD_FACEMAP)) == NULL) + if ((facemap = CustomData_get_layer(&me->pdata, CD_FACEMAP)) == NULL) { facemap = CustomData_add_layer(&me->pdata, CD_FACEMAP, CD_DEFAULT, NULL, me->totpoly); + } facemap[facenum] = fmap_nr; } @@ -78,8 +80,9 @@ void ED_object_facemap_face_add(Object *ob, bFaceMap *fmap, int facenum) void ED_object_facemap_face_remove(Object *ob, bFaceMap *fmap, int facenum) { int fmap_nr; - if (GS(((ID *)ob->data)->name) != ID_ME) + if (GS(((ID *)ob->data)->name) != ID_ME) { return; + } /* get the face map number, exit if it can't be found */ fmap_nr = BLI_findindex(&ob->fmaps, fmap); @@ -88,8 +91,9 @@ void ED_object_facemap_face_remove(Object *ob, bFaceMap *fmap, int facenum) int *facemap; Mesh *me = ob->data; - if ((facemap = CustomData_get_layer(&me->pdata, CD_FACEMAP)) == NULL) + if ((facemap = CustomData_get_layer(&me->pdata, CD_FACEMAP)) == NULL) { return; + } facemap[facenum] = -1; } @@ -114,10 +118,12 @@ static void object_fmap_swap_edit_mode(Object *ob, int num1, int num2) if (map) { if (num1 != -1) { - if (*map == num1) + if (*map == num1) { *map = num2; - else if (*map == num2) + } + else if (*map == num2) { *map = num1; + } } } } @@ -138,10 +144,12 @@ static void object_fmap_swap_object_mode(Object *ob, int num1, int num2) if (map) { for (i = 0; i < me->totpoly; i++) { if (num1 != -1) { - if (map[i] == num1) + if (map[i] == num1) { map[i] = num2; - else if (map[i] == num2) + } + else if (map[i] == num2) { map[i] = num1; + } } } } @@ -151,10 +159,12 @@ static void object_fmap_swap_object_mode(Object *ob, int num1, int num2) static void object_facemap_swap(Object *ob, int num1, int num2) { - if (BKE_object_is_in_editmode(ob)) + if (BKE_object_is_in_editmode(ob)) { object_fmap_swap_edit_mode(ob, num1, num2); - else + } + else { object_fmap_swap_object_mode(ob, num1, num2); + } } static bool face_map_supported_poll(bContext *C) @@ -245,8 +255,9 @@ static int face_map_assign_exec(bContext *C, wmOperator *UNUSED(op)) int *map; int cd_fmap_offset; - if (!CustomData_has_layer(&em->bm->pdata, CD_FACEMAP)) + if (!CustomData_has_layer(&em->bm->pdata, CD_FACEMAP)) { BM_data_layer_add(em->bm, &em->bm->pdata, CD_FACEMAP); + } cd_fmap_offset = CustomData_get_offset(&em->bm->pdata, CD_FACEMAP); @@ -294,8 +305,9 @@ static int face_map_remove_from_exec(bContext *C, wmOperator *UNUSED(op)) int cd_fmap_offset; int mapindex = ob->actfmap - 1; - if (!CustomData_has_layer(&em->bm->pdata, CD_FACEMAP)) + if (!CustomData_has_layer(&em->bm->pdata, CD_FACEMAP)) { return OPERATOR_CANCELLED; + } cd_fmap_offset = CustomData_get_offset(&em->bm->pdata, CD_FACEMAP); @@ -339,8 +351,9 @@ static void fmap_select(Object *ob, bool select) int cd_fmap_offset; int mapindex = ob->actfmap - 1; - if (!CustomData_has_layer(&em->bm->pdata, CD_FACEMAP)) + if (!CustomData_has_layer(&em->bm->pdata, CD_FACEMAP)) { BM_data_layer_add(em->bm, &em->bm->pdata, CD_FACEMAP); + } cd_fmap_offset = CustomData_get_offset(&em->bm->pdata, CD_FACEMAP); diff --git a/source/blender/editors/object/object_gpencil_modifier.c b/source/blender/editors/object/object_gpencil_modifier.c index a726e2c9f00..383974270f4 100644 --- a/source/blender/editors/object/object_gpencil_modifier.c +++ b/source/blender/editors/object/object_gpencil_modifier.c @@ -109,8 +109,9 @@ static bool UNUSED_FUNCTION(gpencil_object_has_modifier)(const Object *ob, GpencilModifierData *md; for (md = ob->greasepencil_modifiers.first; md; md = md->next) { - if ((md != exclude) && (md->type == type)) + if ((md != exclude) && (md->type == type)) { return true; + } } return false; @@ -163,8 +164,9 @@ void ED_object_gpencil_modifier_clear(Main *bmain, Object *ob) GpencilModifierData *md = ob->greasepencil_modifiers.first; bool sort_depsgraph = false; - if (!md) + if (!md) { return; + } while (md) { GpencilModifierData *next_md; @@ -257,8 +259,9 @@ int ED_object_gpencil_modifier_apply(Main *bmain, return 0; } - if (md != ob->greasepencil_modifiers.first) + if (md != ob->greasepencil_modifiers.first) { BKE_report(reports, RPT_INFO, "Applied modifier was not first, result may not be as expected"); + } if (!gpencil_modifier_apply_obdata(reports, bmain, depsgraph, ob, md)) { return 0; @@ -300,8 +303,9 @@ static int gpencil_modifier_add_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); int type = RNA_enum_get(op->ptr, "type"); - if (!ED_object_gpencil_modifier_add(op->reports, bmain, scene, ob, NULL, type)) + if (!ED_object_gpencil_modifier_add(op->reports, bmain, scene, ob, NULL, type)) { return OPERATOR_CANCELLED; + } WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -319,16 +323,18 @@ static const EnumPropertyItem *gpencil_modifier_add_itemf(bContext *C, const GpencilModifierTypeInfo *mti; int totitem = 0, a; - if (!ob) + if (!ob) { return rna_enum_object_greasepencil_modifier_type_items; + } for (a = 0; rna_enum_object_greasepencil_modifier_type_items[a].identifier; a++) { md_item = &rna_enum_object_greasepencil_modifier_type_items[a]; if (md_item->identifier[0]) { mti = BKE_gpencil_modifierType_getInfo(md_item->value); - if (mti->flags & eGpencilModifierTypeFlag_NoUserAdd) + if (mti->flags & eGpencilModifierTypeFlag_NoUserAdd) { continue; + } } else { group_item = md_item; @@ -379,19 +385,22 @@ void OBJECT_OT_gpencil_modifier_add(wmOperatorType *ot) ot->prop = prop; } -/************************ generic functions for operators using mod names and data context *********************/ +/********** generic functions for operators using mod names and data context *********************/ static int gpencil_edit_modifier_poll_generic(bContext *C, StructRNA *rna_type, int obtype_flag) { PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", rna_type); Object *ob = (ptr.id.data) ? ptr.id.data : ED_object_active_context(C); - if (!ob || ID_IS_LINKED(ob)) + if (!ob || ID_IS_LINKED(ob)) { return 0; - if (obtype_flag && ((1 << ob->type) & obtype_flag) == 0) + } + if (obtype_flag && ((1 << ob->type) & obtype_flag) == 0) { return 0; - if (ptr.id.data && ID_IS_LINKED(ptr.id.data)) + } + if (ptr.id.data && ID_IS_LINKED(ptr.id.data)) { return 0; + } if (ID_IS_STATIC_OVERRIDE(ob)) { CTX_wm_operator_poll_msg_set(C, "Cannot edit modifiers coming from static override"); @@ -443,8 +452,9 @@ static GpencilModifierData *gpencil_edit_modifier_property_get(wmOperator *op, md = BKE_gpencil_modifiers_findByName(ob, modifier_name); - if (md && type != 0 && md->type != type) + if (md && type != 0 && md->type != type) { md = NULL; + } return md; } @@ -457,8 +467,9 @@ static int gpencil_modifier_remove_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); GpencilModifierData *md = gpencil_edit_modifier_property_get(op, ob, 0); - if (!md || !ED_object_gpencil_modifier_remove(op->reports, bmain, ob, md)) + if (!md || !ED_object_gpencil_modifier_remove(op->reports, bmain, ob, md)) { return OPERATOR_CANCELLED; + } WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -469,10 +480,12 @@ static int gpencil_modifier_remove_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (gpencil_edit_modifier_invoke_properties(C, op)) + if (gpencil_edit_modifier_invoke_properties(C, op)) { return gpencil_modifier_remove_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_gpencil_modifier_remove(wmOperatorType *ot) @@ -497,8 +510,9 @@ static int gpencil_modifier_move_up_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); GpencilModifierData *md = gpencil_edit_modifier_property_get(op, ob, 0); - if (!md || !ED_object_gpencil_modifier_move_up(op->reports, ob, md)) + if (!md || !ED_object_gpencil_modifier_move_up(op->reports, ob, md)) { return OPERATOR_CANCELLED; + } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -510,10 +524,12 @@ static int gpencil_modifier_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (gpencil_edit_modifier_invoke_properties(C, op)) + if (gpencil_edit_modifier_invoke_properties(C, op)) { return gpencil_modifier_move_up_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_gpencil_modifier_move_up(wmOperatorType *ot) @@ -538,8 +554,9 @@ static int gpencil_modifier_move_down_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); GpencilModifierData *md = gpencil_edit_modifier_property_get(op, ob, 0); - if (!md || !ED_object_gpencil_modifier_move_down(op->reports, ob, md)) + if (!md || !ED_object_gpencil_modifier_move_down(op->reports, ob, md)) { return OPERATOR_CANCELLED; + } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -551,10 +568,12 @@ static int gpencil_modifier_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (gpencil_edit_modifier_invoke_properties(C, op)) + if (gpencil_edit_modifier_invoke_properties(C, op)) { return gpencil_modifier_move_down_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_gpencil_modifier_move_down(wmOperatorType *ot) @@ -594,10 +613,12 @@ static int gpencil_modifier_apply_exec(bContext *C, wmOperator *op) static int gpencil_modifier_apply_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (gpencil_edit_modifier_invoke_properties(C, op)) + if (gpencil_edit_modifier_invoke_properties(C, op)) { return gpencil_modifier_apply_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } static const EnumPropertyItem gpencil_modifier_apply_as_items[] = { @@ -639,8 +660,9 @@ static int gpencil_modifier_copy_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); GpencilModifierData *md = gpencil_edit_modifier_property_get(op, ob, 0); - if (!md || !ED_object_gpencil_modifier_copy(op->reports, ob, md)) + if (!md || !ED_object_gpencil_modifier_copy(op->reports, ob, md)) { return OPERATOR_CANCELLED; + } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -650,10 +672,12 @@ static int gpencil_modifier_copy_exec(bContext *C, wmOperator *op) static int gpencil_modifier_copy_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (gpencil_edit_modifier_invoke_properties(C, op)) + if (gpencil_edit_modifier_invoke_properties(C, op)) { return gpencil_modifier_copy_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_gpencil_modifier_copy(wmOperatorType *ot) diff --git a/source/blender/editors/object/object_hook.c b/source/blender/editors/object/object_hook.c index d4e5ba42be2..c939cb0a61d 100644 --- a/source/blender/editors/object/object_hook.c +++ b/source/blender/editors/object/object_hook.c @@ -75,11 +75,13 @@ static int return_editmesh_indexar(BMEditMesh *em, int *r_tot, int **r_indexar, int *index, nr, totvert = 0; BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { - if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) + if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { totvert++; + } } - if (totvert == 0) + if (totvert == 0) { return 0; + } *r_indexar = index = MEM_mallocN(4 * totvert, "hook indexar"); *r_tot = totvert; @@ -144,14 +146,16 @@ static void select_editbmesh_hook(Object *ob, HookModifierData *hmd) BMIter iter; int index = 0, nr = 0; - if (hmd->indexar == NULL) + if (hmd->indexar == NULL) { return; + } BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { if (nr == hmd->indexar[index]) { BM_vert_select_set(em->bm, eve, true); - if (index < hmd->totindex - 1) + if (index < hmd->totindex - 1) { index++; + } } nr++; @@ -173,14 +177,16 @@ static int return_editlattice_indexar(Lattice *editlatt, bp = editlatt->def; while (a--) { if (bp->f1 & SELECT) { - if (bp->hide == 0) + if (bp->hide == 0) { totvert++; + } } bp++; } - if (totvert == 0) + if (totvert == 0) { return 0; + } *r_indexar = index = MEM_mallocN(4 * totvert, "hook indexar"); *r_tot = totvert; @@ -219,8 +225,9 @@ static void select_editlattice_hook(Object *obedit, HookModifierData *hmd) while (a--) { if (hmd->indexar[index] == nr) { bp->f1 |= SELECT; - if (index < hmd->totindex - 1) + if (index < hmd->totindex - 1) { index++; + } } nr++; bp++; @@ -240,12 +247,15 @@ static int return_editcurve_indexar(Object *obedit, int *r_tot, int **r_indexar, bezt = nu->bezt; a = nu->pntsu; while (a--) { - if (bezt->f1 & SELECT) + if (bezt->f1 & SELECT) { totvert++; - if (bezt->f2 & SELECT) + } + if (bezt->f2 & SELECT) { totvert++; - if (bezt->f3 & SELECT) + } + if (bezt->f3 & SELECT) { totvert++; + } bezt++; } } @@ -253,14 +263,16 @@ static int return_editcurve_indexar(Object *obedit, int *r_tot, int **r_indexar, bp = nu->bp; a = nu->pntsu * nu->pntsv; while (a--) { - if (bp->f1 & SELECT) + if (bp->f1 & SELECT) { totvert++; + } bp++; } } } - if (totvert == 0) + if (totvert == 0) { return 0; + } *r_indexar = index = MEM_mallocN(sizeof(*index) * totvert, "hook indexar"); *r_tot = totvert; @@ -376,20 +388,23 @@ static void select_editcurve_hook(Object *obedit, HookModifierData *hmd) while (a--) { if (nr == hmd->indexar[index]) { bezt->f1 |= SELECT; - if (index < hmd->totindex - 1) + if (index < hmd->totindex - 1) { index++; + } } nr++; if (nr == hmd->indexar[index]) { bezt->f2 |= SELECT; - if (index < hmd->totindex - 1) + if (index < hmd->totindex - 1) { index++; + } } nr++; if (nr == hmd->indexar[index]) { bezt->f3 |= SELECT; - if (index < hmd->totindex - 1) + if (index < hmd->totindex - 1) { index++; + } } nr++; @@ -402,8 +417,9 @@ static void select_editcurve_hook(Object *obedit, HookModifierData *hmd) while (a--) { if (nr == hmd->indexar[index]) { bp->f1 |= SELECT; - if (index < hmd->totindex - 1) + if (index < hmd->totindex - 1) { index++; + } } nr++; bp++; @@ -439,17 +455,22 @@ static void object_hook_from_context( static void object_hook_select(Object *ob, HookModifierData *hmd) { - if (hmd->indexar == NULL) + if (hmd->indexar == NULL) { return; + } - if (ob->type == OB_MESH) + if (ob->type == OB_MESH) { select_editbmesh_hook(ob, hmd); - else if (ob->type == OB_LATTICE) + } + else if (ob->type == OB_LATTICE) { select_editlattice_hook(ob, hmd); - else if (ob->type == OB_CURVE) + } + else if (ob->type == OB_CURVE) { select_editcurve_hook(ob, hmd); - else if (ob->type == OB_SURF) + } + else if (ob->type == OB_SURF) { select_editcurve_hook(ob, hmd); + } } /* special poll operators for hook operators */ @@ -459,13 +480,16 @@ static bool hook_op_edit_poll(bContext *C) Object *obedit = CTX_data_edit_object(C); if (obedit) { - if (ED_operator_editmesh(C)) + if (ED_operator_editmesh(C)) { return 1; - if (ED_operator_editsurfcurve(C)) + } + if (ED_operator_editsurfcurve(C)) { return 1; - if (ED_operator_editlattice(C)) + } + if (ED_operator_editlattice(C)) { return 1; - //if (ED_operator_editmball(C)) return 1; + } + // if (ED_operator_editmball(C)) return 1; } return 0; @@ -715,8 +739,9 @@ static const EnumPropertyItem *hook_mod_itemf(bContext *C, ModifierData *md = NULL; int a, totitem = 0; - if (!ob) + if (!ob) { return DummyRNA_NULL_items; + } for (a = 0, md = ob->modifiers.first; md; md = md->next, a++) { if (md->type == eModifierType_Hook) { @@ -880,8 +905,9 @@ static int object_hook_assign_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_WARNING, "Requires selected vertices or active vertex group"); return OPERATOR_CANCELLED; } - if (hmd->indexar) + if (hmd->indexar) { MEM_freeN(hmd->indexar); + } copy_v3_v3(hmd->cent, cent); hmd->indexar = indexar; diff --git a/source/blender/editors/object/object_modes.c b/source/blender/editors/object/object_modes.c index 7c881aa7cab..cc28ceaf95b 100644 --- a/source/blender/editors/object/object_modes.c +++ b/source/blender/editors/object/object_modes.c @@ -54,28 +54,39 @@ static const char *object_mode_op_string(eObjectMode mode) { - if (mode & OB_MODE_EDIT) + if (mode & OB_MODE_EDIT) { return "OBJECT_OT_editmode_toggle"; - if (mode == OB_MODE_SCULPT) + } + if (mode == OB_MODE_SCULPT) { return "SCULPT_OT_sculptmode_toggle"; - if (mode == OB_MODE_VERTEX_PAINT) + } + if (mode == OB_MODE_VERTEX_PAINT) { return "PAINT_OT_vertex_paint_toggle"; - if (mode == OB_MODE_WEIGHT_PAINT) + } + if (mode == OB_MODE_WEIGHT_PAINT) { return "PAINT_OT_weight_paint_toggle"; - if (mode == OB_MODE_TEXTURE_PAINT) + } + if (mode == OB_MODE_TEXTURE_PAINT) { return "PAINT_OT_texture_paint_toggle"; - if (mode == OB_MODE_PARTICLE_EDIT) + } + if (mode == OB_MODE_PARTICLE_EDIT) { return "PARTICLE_OT_particle_edit_toggle"; - if (mode == OB_MODE_POSE) + } + if (mode == OB_MODE_POSE) { return "OBJECT_OT_posemode_toggle"; - if (mode == OB_MODE_EDIT_GPENCIL) + } + if (mode == OB_MODE_EDIT_GPENCIL) { return "GPENCIL_OT_editmode_toggle"; - if (mode == OB_MODE_PAINT_GPENCIL) + } + if (mode == OB_MODE_PAINT_GPENCIL) { return "GPENCIL_OT_paintmode_toggle"; - if (mode == OB_MODE_SCULPT_GPENCIL) + } + if (mode == OB_MODE_SCULPT_GPENCIL) { return "GPENCIL_OT_sculptmode_toggle"; - if (mode == OB_MODE_WEIGHT_GPENCIL) + } + if (mode == OB_MODE_WEIGHT_GPENCIL) { return "GPENCIL_OT_weightmode_toggle"; + } return NULL; } @@ -86,8 +97,9 @@ static const char *object_mode_op_string(eObjectMode mode) bool ED_object_mode_compat_test(const Object *ob, eObjectMode mode) { if (ob) { - if (mode == OB_MODE_OBJECT) + if (mode == OB_MODE_OBJECT) { return true; + } switch (ob->type) { case OB_MESH: @@ -100,16 +112,19 @@ bool ED_object_mode_compat_test(const Object *ob, eObjectMode mode) case OB_SURF: case OB_FONT: case OB_MBALL: - if (mode & (OB_MODE_EDIT)) + if (mode & (OB_MODE_EDIT)) { return true; + } break; case OB_LATTICE: - if (mode & (OB_MODE_EDIT | OB_MODE_WEIGHT_PAINT)) + if (mode & (OB_MODE_EDIT | OB_MODE_WEIGHT_PAINT)) { return true; + } break; case OB_ARMATURE: - if (mode & (OB_MODE_EDIT | OB_MODE_POSE)) + if (mode & (OB_MODE_EDIT | OB_MODE_POSE)) { return true; + } break; case OB_GPENCIL: if (mode & (OB_MODE_EDIT | OB_MODE_EDIT_GPENCIL | OB_MODE_PAINT_GPENCIL | diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 7aae0a41c85..e555f0d940d 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -155,13 +155,15 @@ ModifierData *ED_object_modifier_add( if (mti->flags & eModifierTypeFlag_RequiresOriginalData) { md = ob->modifiers.first; - while (md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform) + while (md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform) { md = md->next; + } BLI_insertlinkbefore(&ob->modifiers, md, new_md); } - else + else { BLI_addtail(&ob->modifiers, new_md); + } if (name) { BLI_strncpy_utf8(new_md->name, name, sizeof(new_md->name)); @@ -179,8 +181,9 @@ ModifierData *ED_object_modifier_add( } } else if (type == eModifierType_Collision) { - if (!ob->pd) + if (!ob->pd) { ob->pd = BKE_partdeflect_new(0); + } ob->pd->deflect = 1; } @@ -215,8 +218,9 @@ static bool object_has_modifier(const Object *ob, const ModifierData *exclude, M ModifierData *md; for (md = ob->modifiers.first; md; md = md->next) { - if ((md != exclude) && (md->type == type)) + if ((md != exclude) && (md->type == type)) { return true; + } } return false; @@ -239,8 +243,9 @@ bool ED_object_iter_other(Main *bmain, ID *ob_data_id = orig_ob->data; int users = ob_data_id->us; - if (ob_data_id->flag & LIB_FAKEUSER) + if (ob_data_id->flag & LIB_FAKEUSER) { users--; + } /* First check that the object's data has multiple users */ if (users > 1) { @@ -249,8 +254,9 @@ bool ED_object_iter_other(Main *bmain, for (ob = bmain->objects.first; ob && totfound < users; ob = ob->id.next) { if (((ob != orig_ob) || include_orig) && (ob->data == orig_ob->data)) { - if (callback(ob, callback_data)) + if (callback(ob, callback_data)) { return true; + } totfound++; } @@ -324,8 +330,9 @@ static bool object_modifier_remove(Main *bmain, } } else if (md->type == eModifierType_Collision) { - if (ob->pd) + if (ob->pd) { ob->pd->deflect = 0; + } *r_sort_depsgraph = true; } @@ -334,13 +341,15 @@ static bool object_modifier_remove(Main *bmain, } else if (md->type == eModifierType_Multires) { /* Delete MDisps layer if not used by another multires modifier */ - if (object_modifier_safe_to_delete(bmain, ob, md, eModifierType_Multires)) + if (object_modifier_safe_to_delete(bmain, ob, md, eModifierType_Multires)) { multires_customdata_delete(ob->data); + } } else if (md->type == eModifierType_Skin) { /* Delete MVertSkin layer if not used by another skin modifier */ - if (object_modifier_safe_to_delete(bmain, ob, md, eModifierType_Skin)) + if (object_modifier_safe_to_delete(bmain, ob, md, eModifierType_Skin)) { modifier_skin_customdata_delete(ob); + } } if (ELEM(md->type, eModifierType_Softbody, eModifierType_Cloth) && @@ -378,8 +387,9 @@ void ED_object_modifier_clear(Main *bmain, Object *ob) ModifierData *md = ob->modifiers.first; bool sort_depsgraph = false; - if (!md) + if (!md) { return; + } while (md) { ModifierData *next_md; @@ -456,10 +466,12 @@ int ED_object_modifier_convert(ReportList *UNUSED(reports), int totvert = 0, totedge = 0, cvert = 0; int totpart = 0, totchild = 0; - if (md->type != eModifierType_ParticleSystem) + if (md->type != eModifierType_ParticleSystem) { return 0; - if (ob && ob->mode & OB_MODE_PARTICLE_EDIT) + } + if (ob && ob->mode & OB_MODE_PARTICLE_EDIT) { return 0; + } psys_orig = ((ParticleSystemModifierData *)md)->psys; part = psys_orig->part; @@ -475,8 +487,9 @@ int ED_object_modifier_convert(ReportList *UNUSED(reports), totpart = psys_eval->totcached; totchild = psys_eval->totchildcache; - if (totchild && (part->draw & PART_DRAW_PARENT) == 0) + if (totchild && (part->draw & PART_DRAW_PARENT) == 0) { totpart = 0; + } /* count */ cache = psys_eval->pathcache; @@ -499,8 +512,9 @@ int ED_object_modifier_convert(ReportList *UNUSED(reports), } } - if (totvert == 0) + if (totvert == 0) { return 0; + } /* add new mesh */ obn = BKE_object_add(bmain, scene, view_layer, OB_MESH, NULL); @@ -564,12 +578,11 @@ int ED_object_modifier_convert(ReportList *UNUSED(reports), static Mesh *modifier_apply_create_mesh_for_modifier(Depsgraph *depsgraph, Scene *UNUSED(scene), Object *object, - ModifierData *md, + ModifierData *md_eval, bool build_shapekey_layers) { Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *object_eval = DEG_get_evaluated_object(depsgraph, object); - ModifierData *md_eval = modifiers_findByName(object_eval, md->name); Mesh *mesh_applied = BKE_mesh_create_derived_for_modifier( depsgraph, scene_eval, object_eval, md_eval, build_shapekey_layers); return mesh_applied; @@ -580,11 +593,11 @@ static int modifier_apply_shape(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob, - ModifierData *md) + ModifierData *md_eval) { - const ModifierTypeInfo *mti = modifierType_getInfo(md->type); + const ModifierTypeInfo *mti = modifierType_getInfo(md_eval->type); - if (mti->isDisabled && mti->isDisabled(scene, md, 0)) { + if (mti->isDisabled && mti->isDisabled(scene, md_eval, 0)) { BKE_report(reports, RPT_ERROR, "Modifier is disabled, skipping apply"); return 0; } @@ -606,12 +619,12 @@ static int modifier_apply_shape(Main *bmain, Key *key = me->key; KeyBlock *kb; - if (!modifier_isSameTopology(md) || mti->type == eModifierTypeType_NonGeometrical) { + if (!modifier_isSameTopology(md_eval) || mti->type == eModifierTypeType_NonGeometrical) { BKE_report(reports, RPT_ERROR, "Only deforming modifiers can be applied to shapes"); return 0; } - mesh_applied = modifier_apply_create_mesh_for_modifier(depsgraph, scene, ob, md, false); + mesh_applied = modifier_apply_create_mesh_for_modifier(depsgraph, scene, ob, md_eval, false); if (!mesh_applied) { BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply"); return 0; @@ -626,7 +639,7 @@ static int modifier_apply_shape(Main *bmain, BKE_keyblock_convert_from_mesh(me, key, kb); } - kb = BKE_keyblock_add(key, md->name); + kb = BKE_keyblock_add(key, md_eval->name); BKE_mesh_nomain_to_meshkey(mesh_applied, me, kb); BKE_id_free(NULL, mesh_applied); @@ -639,11 +652,11 @@ static int modifier_apply_shape(Main *bmain, } static int modifier_apply_obdata( - ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md) + ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md_eval) { - const ModifierTypeInfo *mti = modifierType_getInfo(md->type); + const ModifierTypeInfo *mti = modifierType_getInfo(md_eval->type); - if (mti->isDisabled && mti->isDisabled(scene, md, 0)) { + if (mti->isDisabled && mti->isDisabled(scene, md_eval, 0)) { BKE_report(reports, RPT_ERROR, "Modifier is disabled, skipping apply"); return 0; } @@ -651,7 +664,7 @@ static int modifier_apply_obdata( if (ob->type == OB_MESH) { Mesh *mesh_applied; Mesh *me = ob->data; - MultiresModifierData *mmd = find_multires_modifier_before(scene, md); + MultiresModifierData *mmd = find_multires_modifier_before(scene, md_eval); if (me->key && mti->type != eModifierTypeType_NonGeometrical) { BKE_report(reports, RPT_ERROR, "Modifier cannot be applied to a mesh with shape keys"); @@ -659,17 +672,18 @@ static int modifier_apply_obdata( } /* Multires: ensure that recent sculpting is applied */ - if (md->type == eModifierType_Multires) + if (md_eval->type == eModifierType_Multires) { multires_force_update(ob); + } if (mmd && mmd->totlvl && mti->type == eModifierTypeType_OnlyDeform) { - if (!multiresModifier_reshapeFromDeformModifier(depsgraph, mmd, ob, md)) { + if (!multiresModifier_reshapeFromDeformModifier(depsgraph, mmd, ob, md_eval)) { BKE_report(reports, RPT_ERROR, "Multires modifier returned error, skipping apply"); return 0; } } else { - mesh_applied = modifier_apply_create_mesh_for_modifier(depsgraph, scene, ob, md, true); + mesh_applied = modifier_apply_create_mesh_for_modifier(depsgraph, scene, ob, md_eval, true); if (!mesh_applied) { BKE_report(reports, RPT_ERROR, "Modifier returned error, skipping apply"); return 0; @@ -677,8 +691,9 @@ static int modifier_apply_obdata( BKE_mesh_nomain_to_mesh(mesh_applied, me, ob, &CD_MASK_MESH, true); - if (md->type == eModifierType_Multires) + if (md_eval->type == eModifierType_Multires) { multires_customdata_delete(me); + } } } else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { @@ -700,7 +715,7 @@ static int modifier_apply_obdata( "Applied modifier only changed CV points, not tessellated/bevel vertices"); vertexCos = BKE_curve_nurbs_vertexCos_get(&curve_eval->nurb, &numVerts); - mti->deformVerts(md, &mectx, NULL, vertexCos, numVerts); + mti->deformVerts(md_eval, &mectx, NULL, vertexCos, numVerts); BK_curve_nurbs_vertexCos_apply(&curve->nurb, vertexCos); MEM_freeN(vertexCos); @@ -719,8 +734,9 @@ static int modifier_apply_obdata( for (; psys; psys = psys->next) { - if (psys->part->type != PART_HAIR) + if (psys->part->type != PART_HAIR) { continue; + } psys_apply_hair_lattice(depsgraph, scene, ob, psys); } @@ -755,8 +771,9 @@ int ED_object_modifier_apply(Main *bmain, return 0; } - if (md != ob->modifiers.first) + if (md != ob->modifiers.first) { BKE_report(reports, RPT_INFO, "Applied modifier was not first, result may not be as expected"); + } /* Get evaluated modifier, so object links pointer to evaluated data, * but still use original object it is applied to the original mesh. */ @@ -810,8 +827,9 @@ static int modifier_add_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); int type = RNA_enum_get(op->ptr, "type"); - if (!ED_object_modifier_add(op->reports, bmain, scene, ob, NULL, type)) + if (!ED_object_modifier_add(op->reports, bmain, scene, ob, NULL, type)) { return OPERATOR_CANCELLED; + } WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -829,8 +847,9 @@ static const EnumPropertyItem *modifier_add_itemf(bContext *C, const ModifierTypeInfo *mti; int totitem = 0, a; - if (!ob) + if (!ob) { return rna_enum_object_modifier_type_items; + } for (a = 0; rna_enum_object_modifier_type_items[a].identifier; a++) { md_item = &rna_enum_object_modifier_type_items[a]; @@ -838,11 +857,13 @@ static const EnumPropertyItem *modifier_add_itemf(bContext *C, if (md_item->identifier[0]) { mti = modifierType_getInfo(md_item->value); - if (mti->flags & eModifierTypeFlag_NoUserAdd) + if (mti->flags & eModifierTypeFlag_NoUserAdd) { continue; + } - if (!BKE_object_support_modifier_type_check(ob, md_item->value)) + if (!BKE_object_support_modifier_type_check(ob, md_item->value)) { continue; + } } else { group_item = md_item; @@ -889,19 +910,22 @@ void OBJECT_OT_modifier_add(wmOperatorType *ot) ot->prop = prop; } -/************************ generic functions for operators using mod names and data context *********************/ +/********** generic functions for operators using mod names and data context *********************/ bool edit_modifier_poll_generic(bContext *C, StructRNA *rna_type, int obtype_flag) { PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", rna_type); Object *ob = (ptr.id.data) ? ptr.id.data : ED_object_active_context(C); - if (!ob || ID_IS_LINKED(ob)) + if (!ob || ID_IS_LINKED(ob)) { return 0; - if (obtype_flag && ((1 << ob->type) & obtype_flag) == 0) + } + if (obtype_flag && ((1 << ob->type) & obtype_flag) == 0) { return 0; - if (ptr.id.data && ID_IS_LINKED(ptr.id.data)) + } + if (ptr.id.data && ID_IS_LINKED(ptr.id.data)) { return 0; + } if (ID_IS_STATIC_OVERRIDE(ob)) { CTX_wm_operator_poll_msg_set(C, "Cannot edit modifiers coming from static override"); @@ -950,8 +974,9 @@ ModifierData *edit_modifier_property_get(wmOperator *op, Object *ob, int type) md = modifiers_findByName(ob, modifier_name); - if (md && type != 0 && md->type != type) + if (md && type != 0 && md->type != type) { md = NULL; + } return md; } @@ -966,8 +991,9 @@ static int modifier_remove_exec(bContext *C, wmOperator *op) ModifierData *md = edit_modifier_property_get(op, ob, 0); int mode_orig = ob->mode; - if (!md || !ED_object_modifier_remove(op->reports, bmain, ob, md)) + if (!md || !ED_object_modifier_remove(op->reports, bmain, ob, md)) { return OPERATOR_CANCELLED; + } WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -984,10 +1010,12 @@ static int modifier_remove_exec(bContext *C, wmOperator *op) static int modifier_remove_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return modifier_remove_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_modifier_remove(wmOperatorType *ot) @@ -1012,8 +1040,9 @@ static int modifier_move_up_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); ModifierData *md = edit_modifier_property_get(op, ob, 0); - if (!md || !ED_object_modifier_move_up(op->reports, ob, md)) + if (!md || !ED_object_modifier_move_up(op->reports, ob, md)) { return OPERATOR_CANCELLED; + } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -1023,10 +1052,12 @@ static int modifier_move_up_exec(bContext *C, wmOperator *op) static int modifier_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return modifier_move_up_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_modifier_move_up(wmOperatorType *ot) @@ -1051,8 +1082,9 @@ static int modifier_move_down_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); ModifierData *md = edit_modifier_property_get(op, ob, 0); - if (!md || !ED_object_modifier_move_down(op->reports, ob, md)) + if (!md || !ED_object_modifier_move_down(op->reports, ob, md)) { return OPERATOR_CANCELLED; + } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -1062,10 +1094,12 @@ static int modifier_move_down_exec(bContext *C, wmOperator *op) static int modifier_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return modifier_move_down_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_modifier_move_down(wmOperatorType *ot) @@ -1106,10 +1140,12 @@ static int modifier_apply_exec(bContext *C, wmOperator *op) static int modifier_apply_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return modifier_apply_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } static const EnumPropertyItem modifier_apply_as_items[] = { @@ -1155,8 +1191,10 @@ static int modifier_convert_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); ModifierData *md = edit_modifier_property_get(op, ob, 0); - if (!md || !ED_object_modifier_convert(op->reports, bmain, depsgraph, scene, view_layer, ob, md)) + if (!md || + !ED_object_modifier_convert(op->reports, bmain, depsgraph, scene, view_layer, ob, md)) { return OPERATOR_CANCELLED; + } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -1166,10 +1204,12 @@ static int modifier_convert_exec(bContext *C, wmOperator *op) static int modifier_convert_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return modifier_convert_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_modifier_convert(wmOperatorType *ot) @@ -1194,8 +1234,9 @@ static int modifier_copy_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); ModifierData *md = edit_modifier_property_get(op, ob, 0); - if (!md || !ED_object_modifier_copy(op->reports, ob, md)) + if (!md || !ED_object_modifier_copy(op->reports, ob, md)) { return OPERATOR_CANCELLED; + } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -1205,10 +1246,12 @@ static int modifier_copy_exec(bContext *C, wmOperator *op) static int modifier_copy_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return modifier_copy_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_modifier_copy(wmOperatorType *ot) @@ -1240,8 +1283,9 @@ static int multires_higher_levels_delete_exec(bContext *C, wmOperator *op) MultiresModifierData *mmd = (MultiresModifierData *)edit_modifier_property_get( op, ob, eModifierType_Multires); - if (!mmd) + if (!mmd) { return OPERATOR_CANCELLED; + } multiresModifier_del_levels(mmd, scene, ob, 1); @@ -1257,10 +1301,12 @@ static int multires_higher_levels_delete_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return multires_higher_levels_delete_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_multires_higher_levels_delete(wmOperatorType *ot) @@ -1287,8 +1333,9 @@ static int multires_subdivide_exec(bContext *C, wmOperator *op) MultiresModifierData *mmd = (MultiresModifierData *)edit_modifier_property_get( op, ob, eModifierType_Multires); - if (!mmd) + if (!mmd) { return OPERATOR_CANCELLED; + } multiresModifier_subdivide(mmd, scene, ob, 0, mmd->simple); @@ -1308,10 +1355,12 @@ static int multires_subdivide_exec(bContext *C, wmOperator *op) static int multires_subdivide_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return multires_subdivide_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_multires_subdivide(wmOperatorType *ot) @@ -1338,8 +1387,9 @@ static int multires_reshape_exec(bContext *C, wmOperator *op) MultiresModifierData *mmd = (MultiresModifierData *)edit_modifier_property_get( op, ob, eModifierType_Multires); - if (!mmd) + if (!mmd) { return OPERATOR_CANCELLED; + } if (mmd->lvl == 0) { BKE_report(op->reports, RPT_ERROR, "Reshape can work only with higher levels of subdivisions"); @@ -1372,10 +1422,12 @@ static int multires_reshape_exec(bContext *C, wmOperator *op) static int multires_reshape_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return multires_reshape_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_multires_reshape(wmOperatorType *ot) @@ -1403,16 +1455,19 @@ static int multires_external_save_exec(bContext *C, wmOperator *op) char path[FILE_MAX]; const bool relative = RNA_boolean_get(op->ptr, "relative_path"); - if (!me) + if (!me) { return OPERATOR_CANCELLED; + } - if (CustomData_external_test(&me->ldata, CD_MDISPS)) + if (CustomData_external_test(&me->ldata, CD_MDISPS)) { return OPERATOR_CANCELLED; + } RNA_string_get(op->ptr, "filepath", path); - if (relative) + if (relative) { BLI_path_rel(path, BKE_main_blendfile_path(bmain)); + } CustomData_external_add(&me->ldata, &me->id, CD_MDISPS, me->totloop, path); CustomData_external_write(&me->ldata, &me->id, CD_MASK_MESH.lmask, me->totloop, 0); @@ -1427,19 +1482,23 @@ static int multires_external_save_invoke(bContext *C, wmOperator *op, const wmEv Mesh *me = ob->data; char path[FILE_MAX]; - if (!edit_modifier_invoke_properties(C, op)) + if (!edit_modifier_invoke_properties(C, op)) { return OPERATOR_CANCELLED; + } mmd = (MultiresModifierData *)edit_modifier_property_get(op, ob, eModifierType_Multires); - if (!mmd) + if (!mmd) { return OPERATOR_CANCELLED; + } - if (CustomData_external_test(&me->ldata, CD_MDISPS)) + if (CustomData_external_test(&me->ldata, CD_MDISPS)) { return OPERATOR_CANCELLED; + } - if (RNA_struct_property_is_set(op->ptr, "filepath")) + if (RNA_struct_property_is_set(op->ptr, "filepath")) { return multires_external_save_exec(C, op); + } op->customdata = me; @@ -1482,8 +1541,9 @@ static int multires_external_pack_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_object_active_context(C); Mesh *me = ob->data; - if (!CustomData_external_test(&me->ldata, CD_MDISPS)) + if (!CustomData_external_test(&me->ldata, CD_MDISPS)) { return OPERATOR_CANCELLED; + } /* XXX don't remove.. */ CustomData_external_remove(&me->ldata, &me->id, CD_MDISPS, me->totloop); @@ -1512,8 +1572,9 @@ static int multires_base_apply_exec(bContext *C, wmOperator *op) MultiresModifierData *mmd = (MultiresModifierData *)edit_modifier_property_get( op, ob, eModifierType_Multires); - if (!mmd) + if (!mmd) { return OPERATOR_CANCELLED; + } multiresModifier_base_apply(mmd, scene, ob); @@ -1525,10 +1586,12 @@ static int multires_base_apply_exec(bContext *C, wmOperator *op) static int multires_base_apply_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return multires_base_apply_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_multires_base_apply(wmOperatorType *ot) @@ -1553,10 +1616,12 @@ static void modifier_skin_customdata_delete(Object *ob) Mesh *me = ob->data; BMEditMesh *em = me->edit_mesh; - if (em) + if (em) { BM_data_layer_free(em->bm, &em->bm->vdata, CD_MVERT_SKIN); - else + } + else { CustomData_free_layer_active(&me->vdata, CD_MVERT_SKIN, me->totvert); + } } static bool skin_poll(bContext *C) @@ -1757,8 +1822,9 @@ static void skin_armature_bone_create(Object *skin_ob, int v; /* ignore edge if already visited */ - if (BLI_BITMAP_TEST(edges_visited, endx)) + if (BLI_BITMAP_TEST(edges_visited, endx)) { continue; + } BLI_BITMAP_ENABLE(edges_visited, endx); v = (e->v1 == parent_v ? e->v2 : e->v1); @@ -1894,10 +1960,12 @@ static int skin_armature_create_exec(bContext *C, wmOperator *op) static int skin_armature_create_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return skin_armature_create_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_skin_armature_create(wmOperatorType *ot) @@ -1967,10 +2035,12 @@ static int correctivesmooth_bind_exec(bContext *C, wmOperator *op) static int correctivesmooth_bind_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return correctivesmooth_bind_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_correctivesmooth_bind(wmOperatorType *ot) @@ -2022,7 +2092,8 @@ static int meshdeform_bind_exec(bContext *C, wmOperator *op) mmd->totinfluence = 0; } else { - /* Force modifier to run, it will call binding routine (this has to happen outside of depsgraph evaluation). */ + /* Force modifier to run, it will call binding routine + * (this has to happen outside of depsgraph evaluation). */ MeshDeformModifierData *mmd_eval = (MeshDeformModifierData *)modifier_get_evaluated( depsgraph, ob, &mmd->modifier); mmd_eval->bindfunc = ED_mesh_deform_bind_callback; @@ -2037,10 +2108,12 @@ static int meshdeform_bind_exec(bContext *C, wmOperator *op) static int meshdeform_bind_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return meshdeform_bind_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_meshdeform_bind(wmOperatorType *ot) @@ -2073,8 +2146,9 @@ static int explode_refresh_exec(bContext *C, wmOperator *op) ExplodeModifierData *emd = (ExplodeModifierData *)edit_modifier_property_get( op, ob, eModifierType_Explode); - if (!emd) + if (!emd) { return OPERATOR_CANCELLED; + } emd->flag |= eExplodeFlag_CalcFaces; @@ -2086,10 +2160,12 @@ static int explode_refresh_exec(bContext *C, wmOperator *op) static int explode_refresh_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return explode_refresh_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_explode_refresh(wmOperatorType *ot) @@ -2134,8 +2210,8 @@ static void oceanbake_free(void *customdata) /* called by oceanbake, only to check job 'stop' value */ static int oceanbake_breakjob(void *UNUSED(customdata)) { - //OceanBakeJob *ob = (OceanBakeJob *)customdata; - //return *(ob->stop); + // OceanBakeJob *ob = (OceanBakeJob *)customdata; + // return *(ob->stop); /* this is not nice yet, need to make the jobs list template better * for identifying/acting upon various different jobs */ @@ -2148,8 +2224,9 @@ static void oceanbake_update(void *customdata, float progress, int *cancel) { OceanBakeJob *oj = customdata; - if (oceanbake_breakjob(oj)) + if (oceanbake_breakjob(oj)) { *cancel = 1; + } *(oj->do_update) = true; *(oj->progress) = progress; @@ -2202,8 +2279,9 @@ static int ocean_bake_exec(bContext *C, wmOperator *op) wmJob *wm_job; OceanBakeJob *oj; - if (!omd) + if (!omd) { return OPERATOR_CANCELLED; + } if (free) { BKE_ocean_free_modifier_cache(omd); @@ -2281,10 +2359,12 @@ static int ocean_bake_exec(bContext *C, wmOperator *op) static int ocean_bake_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return ocean_bake_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_ocean_bake(wmOperatorType *ot) @@ -2354,10 +2434,12 @@ static int laplaciandeform_bind_exec(bContext *C, wmOperator *op) static int laplaciandeform_bind_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return laplaciandeform_bind_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_laplaciandeform_bind(wmOperatorType *ot) @@ -2417,10 +2499,12 @@ static int surfacedeform_bind_exec(bContext *C, wmOperator *op) static int surfacedeform_bind_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_modifier_invoke_properties(C, op)) + if (edit_modifier_invoke_properties(C, op)) { return surfacedeform_bind_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_surfacedeform_bind(wmOperatorType *ot) diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 8e3f916b2e4..afc0297cb01 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -271,7 +271,7 @@ void ED_operatormacros_object(void) if (ot) { WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", PROP_EDIT_OFF); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); } /* grr, should be able to pass options on... */ @@ -283,7 +283,7 @@ void ED_operatormacros_object(void) otmacro = WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate"); RNA_boolean_set(otmacro->ptr, "linked", true); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_enum_set(otmacro->ptr, "proportional", PROP_EDIT_OFF); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); } } diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index 3744632be3d..e15d85a7953 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -159,16 +159,21 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { - if (v1 == 0) + if (v1 == 0) { v1 = nr; - else if (v2 == 0) + } + else if (v2 == 0) { v2 = nr; - else if (v3 == 0) + } + else if (v3 == 0) { v3 = nr; - else if (v4 == 0) + } + else if (v4 == 0) { v4 = nr; - else + } + else { break; + } } nr++; } @@ -183,16 +188,21 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) a = nu->pntsu; while (a--) { if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) { - if (v1 == 0) + if (v1 == 0) { v1 = nr; - else if (v2 == 0) + } + else if (v2 == 0) { v2 = nr; - else if (v3 == 0) + } + else if (v3 == 0) { v3 = nr; - else if (v4 == 0) + } + else if (v4 == 0) { v4 = nr; - else + } + else { break; + } } nr++; bezt++; @@ -203,16 +213,21 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) a = nu->pntsu * nu->pntsv; while (a--) { if (bp->f1 & SELECT) { - if (v1 == 0) + if (v1 == 0) { v1 = nr; - else if (v2 == 0) + } + else if (v2 == 0) { v2 = nr; - else if (v3 == 0) + } + else if (v3 == 0) { v3 = nr; - else if (v4 == 0) + } + else if (v4 == 0) { v4 = nr; - else + } + else { break; + } } nr++; bp++; @@ -228,16 +243,21 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) bp = lt->editlatt->latt->def; while (a--) { if (bp->f1 & SELECT) { - if (v1 == 0) + if (v1 == 0) { v1 = nr; - else if (v2 == 0) + } + else if (v2 == 0) { v2 = nr; - else if (v3 == 0) + } + else if (v3 == 0) { v3 = nr; - else if (v4 == 0) + } + else if (v4 == 0) { v4 = nr; - else + } + else { break; + } } nr++; bp++; @@ -316,8 +336,9 @@ static int make_proxy_invoke(bContext *C, wmOperator *op, const wmEvent *event) Object *ob = ED_object_active_context(C); /* sanity checks */ - if (!scene || ID_IS_LINKED(scene) || !ob) + if (!scene || ID_IS_LINKED(scene) || !ob) { return OPERATOR_CANCELLED; + } /* Get object to work on - use a menu if we need to... */ if (ob->instance_collection && ID_IS_LINKED(ob->instance_collection)) { @@ -411,8 +432,9 @@ static const EnumPropertyItem *proxy_collection_object_itemf(bContext *C, int i = 0; Object *ob = ED_object_active_context(C); - if (!ob || !ob->instance_collection) + if (!ob || !ob->instance_collection) { return DummyRNA_DEFAULT_items; + } /* find the object to affect */ FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (ob->instance_collection, object) { @@ -529,8 +551,9 @@ static void object_remove_parent_deform_modifiers(Object *ob, const Object *par) void ED_object_parent_clear(Object *ob, const int type) { - if (ob->parent == NULL) + if (ob->parent == NULL) { return; + } switch (type) { case CLEAR_PARENT_ALL: { @@ -664,8 +687,9 @@ bool ED_object_parent_set(ReportList *reports, /* preconditions */ if (partype == PAR_FOLLOW || partype == PAR_PATH_CONST) { - if (par->type != OB_CURVE) + if (par->type != OB_CURVE) { return 0; + } else { Curve *cu = par->data; Curve *cu_eval = parent_eval->data; @@ -687,13 +711,15 @@ bool ED_object_parent_set(ReportList *reports, FCurve *fcu = verify_fcurve(bmain, act, NULL, NULL, "eval_time", 0, 1); /* setup dummy 'generator' modifier here to get 1-1 correspondence still working */ - if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first) + if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first) { add_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_GENERATOR, fcu); + } } /* fall back on regular parenting now (for follow only) */ - if (partype == PAR_FOLLOW) + if (partype == PAR_FOLLOW) { partype = PAR_OBJECT; + } } } else if (ELEM(partype, PAR_BONE, PAR_BONE_RELATIVE)) { @@ -730,24 +756,29 @@ bool ED_object_parent_set(ReportList *reports, } /* handle types */ - if (pchan) + if (pchan) { BLI_strncpy(ob->parsubstr, pchan->name, sizeof(ob->parsubstr)); - else + } + else { ob->parsubstr[0] = 0; + } if (partype == PAR_PATH_CONST) { /* don't do anything here, since this is not technically "parenting" */ } else if (ELEM(partype, PAR_CURVE, PAR_LATTICE) || (pararm)) { - /* partype is now set to PAROBJECT so that invisible 'virtual' modifiers don't need to be created - * NOTE: the old (2.4x) method was to set ob->partype = PARSKEL, creating the virtual modifiers + /* partype is now set to PAROBJECT so that invisible 'virtual' + * modifiers don't need to be created. + * NOTE: the old (2.4x) method was to set ob->partype = PARSKEL, + * creating the virtual modifiers. */ ob->partype = PAROBJECT; /* note, dna define, not operator property */ /* ob->partype = PARSKEL; */ /* note, dna define, not operator property */ - /* BUT, to keep the deforms, we need a modifier, and then we need to set the object that it uses - * - We need to ensure that the modifier we're adding doesn't already exist, so we check this by - * assuming that the parent is selected too... + /* BUT, to keep the deforms, we need a modifier, + * and then we need to set the object that it uses + * - We need to ensure that the modifier we're adding doesn't already exist, + * so we check this by assuming that the parent is selected too. */ /* XXX currently this should only happen for meshes, curves, surfaces, * and lattices - this stuff isn't available for metas yet */ @@ -952,8 +983,9 @@ static int parent_set_exec(bContext *C, wmOperator *op) BLI_kdtree_3d_free(tree); } - if (!ok) + if (!ok) { return OPERATOR_CANCELLED; + } DEG_relations_tag_update(bmain); WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); @@ -962,15 +994,13 @@ static int parent_set_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static int parent_set_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event)) +static int parent_set_invoke_menu(bContext *C, wmOperatorType *ot) { Object *parent = ED_object_active_context(C); uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("Set Parent To"), ICON_NONE); uiLayout *layout = UI_popup_menu_layout(pup); - wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_parent_set", true); PointerRNA opptr; - #if 0 uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_OBJECT); #else @@ -1040,6 +1070,14 @@ static int parent_set_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent return OPERATOR_INTERFACE; } +static int parent_set_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) +{ + if (RNA_property_is_set(op->ptr, op->type->prop)) { + return parent_set_exec(C, op); + } + return parent_set_invoke_menu(C, op->type); +} + static bool parent_set_poll_property(const bContext *UNUSED(C), wmOperator *op, const PropertyRNA *prop) @@ -1049,10 +1087,12 @@ static bool parent_set_poll_property(const bContext *UNUSED(C), /* Only show XMirror for PAR_ARMATURE_ENVELOPE and PAR_ARMATURE_AUTO! */ if (STREQ(prop_id, "xmirror")) { const int type = RNA_enum_get(op->ptr, "type"); - if (ELEM(type, PAR_ARMATURE_ENVELOPE, PAR_ARMATURE_AUTO)) + if (ELEM(type, PAR_ARMATURE_ENVELOPE, PAR_ARMATURE_AUTO)) { return true; - else + } + else { return false; + } } return true; @@ -1181,12 +1221,14 @@ static int object_track_clear_exec(bContext *C, wmOperator *op) if (ELEM(con->type, CONSTRAINT_TYPE_TRACKTO, CONSTRAINT_TYPE_LOCKTRACK, - CONSTRAINT_TYPE_DAMPTRACK)) + CONSTRAINT_TYPE_DAMPTRACK)) { BKE_constraint_remove(&ob->constraints, con); + } } - if (type == CLEAR_TRACK_KEEP_TRANSFORM) + if (type == CLEAR_TRACK_KEEP_TRANSFORM) { BKE_object_apply_mat4(ob, ob->obmat, true, true); + } } CTX_DATA_END; @@ -1339,11 +1381,13 @@ void OBJECT_OT_track_set(wmOperatorType *ot) #if 0 static void link_to_scene(Main *UNUSED(bmain), unsigned short UNUSED(nr)) { - Scene *sce = (Scene *) BLI_findlink(&bmain->scene, G.curscreen->scenenr - 1); + Scene *sce = (Scene *)BLI_findlink(&bmain->scene, G.curscreen->scenenr - 1); Base *base, *nbase; - if (sce == NULL) return; - if (sce->id.lib) return; + if (sce == NULL) + return; + if (sce->id.lib) + return; for (base = FIRSTBASE; base; base = base->next) { if (BASE_SELECTED(v3d, base)) { @@ -1539,20 +1583,24 @@ static int make_links_data_exec(bContext *C, wmOperator *op) break; } - if (cu_dst->vfont) + if (cu_dst->vfont) { id_us_min(&cu_dst->vfont->id); + } cu_dst->vfont = cu_src->vfont; id_us_plus((ID *)cu_dst->vfont); - if (cu_dst->vfontb) + if (cu_dst->vfontb) { id_us_min(&cu_dst->vfontb->id); + } cu_dst->vfontb = cu_src->vfontb; id_us_plus((ID *)cu_dst->vfontb); - if (cu_dst->vfonti) + if (cu_dst->vfonti) { id_us_min(&cu_dst->vfonti->id); + } cu_dst->vfonti = cu_src->vfonti; id_us_plus((ID *)cu_dst->vfonti); - if (cu_dst->vfontbi) + if (cu_dst->vfontbi) { id_us_min(&cu_dst->vfontbi->id); + } cu_dst->vfontbi = cu_src->vfontbi; id_us_plus((ID *)cu_dst->vfontbi); @@ -1680,9 +1728,10 @@ static Collection *single_object_users_collection(Main *bmain, } } - /* Since master collection has already be duplicated as part of scene copy, we do not duplictae it here. - * However, this means its children need to be re-added manually here, otherwise their parent lists are empty - * (which will lead to crashes, see T63101). */ + /* Since master collection has already be duplicated as part of scene copy, + * we do not duplictae it here. + * However, this means its children need to be re-added manually here, + * otherwise their parent lists are empty (which will lead to crashes, see T63101). */ CollectionChild *child_next, *child = collection->children.first; CollectionChild *orig_child_last = collection->children.last; for (; child != NULL; child = child_next) { @@ -1711,9 +1760,10 @@ static void single_object_users( single_object_users_collection(bmain, scene, master_collection, flag, copy_collections, true); /* duplicate collections that consist entirely of duplicated objects */ - /* XXX I guess that was designed for calls from 'make single user' operator... But since copy_collection is - * always false then, was not doing anything. And that kind of behavior should be added at operator level, - * not in a utility function also used by rather different code... */ + /* XXX I guess that was designed for calls from 'make single user' operator. + * But since copy_collection is always false then, was not doing anything. + * And that kind of behavior should be added at operator level, + * not in a utility function also used by rather different code. */ #if 0 if (copy_collections) { Collection *collection, *collectionn; @@ -1753,7 +1803,8 @@ static void single_object_users( ID_NEW_REMAP(v3d->camera); } - /* Making single user may affect other scenes if they share with current one some collections in their ViewLayer. */ + /* Making single user may affect other scenes if they share + * with current one some collections in their ViewLayer. */ BKE_main_collection_sync(bmain); } @@ -1821,8 +1872,9 @@ static void single_obdata_users( case OB_MESH: /* Needed to remap texcomesh below. */ me = ob->data = ID_NEW_SET(ob->data, BKE_mesh_copy(bmain, ob->data)); - if (me->key) /* We do not need to set me->key->id.newid here... */ + if (me->key) { /* We do not need to set me->key->id.newid here... */ BKE_animdata_copy_id_action(bmain, (ID *)me->key, false); + } break; case OB_MBALL: ob->data = ID_NEW_SET(ob->data, BKE_mball_copy(bmain, ob->data)); @@ -1833,13 +1885,15 @@ static void single_obdata_users( ob->data = cu = ID_NEW_SET(ob->data, BKE_curve_copy(bmain, ob->data)); ID_NEW_REMAP(cu->bevobj); ID_NEW_REMAP(cu->taperobj); - if (cu->key) /* We do not need to set cu->key->id.newid here... */ + if (cu->key) { /* We do not need to set cu->key->id.newid here... */ BKE_animdata_copy_id_action(bmain, (ID *)cu->key, false); + } break; case OB_LATTICE: ob->data = lat = ID_NEW_SET(ob->data, BKE_lattice_copy(bmain, ob->data)); - if (lat->key) /* We do not need to set lat->key->id.newid here... */ + if (lat->key) { /* We do not need to set lat->key->id.newid here... */ BKE_animdata_copy_id_action(bmain, (ID *)lat->key, false); + } break; case OB_ARMATURE: DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); @@ -1936,25 +1990,35 @@ static void single_mat_users_expand(Main *bmain) MetaBall *mb; bGPdata *gpd; - for (ob = bmain->objects.first; ob; ob = ob->id.next) - if (ob->id.tag & LIB_TAG_NEW) + for (ob = bmain->objects.first; ob; ob = ob->id.next) { + if (ob->id.tag & LIB_TAG_NEW) { new_id_matar(bmain, ob->mat, ob->totcol); + } + } - for (me = bmain->meshes.first; me; me = me->id.next) - if (me->id.tag & LIB_TAG_NEW) + for (me = bmain->meshes.first; me; me = me->id.next) { + if (me->id.tag & LIB_TAG_NEW) { new_id_matar(bmain, me->mat, me->totcol); + } + } - for (cu = bmain->curves.first; cu; cu = cu->id.next) - if (cu->id.tag & LIB_TAG_NEW) + for (cu = bmain->curves.first; cu; cu = cu->id.next) { + if (cu->id.tag & LIB_TAG_NEW) { new_id_matar(bmain, cu->mat, cu->totcol); + } + } - for (mb = bmain->metaballs.first; mb; mb = mb->id.next) - if (mb->id.tag & LIB_TAG_NEW) + for (mb = bmain->metaballs.first; mb; mb = mb->id.next) { + if (mb->id.tag & LIB_TAG_NEW) { new_id_matar(bmain, mb->mat, mb->totcol); + } + } - for (gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) - if (gpd->id.tag & LIB_TAG_NEW) + for (gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) { + if (gpd->id.tag & LIB_TAG_NEW) { new_id_matar(bmain, gpd->mat, gpd->totcol); + } + } } /* used for copying scenes */ @@ -2094,8 +2158,7 @@ static bool make_local_all__instance_indirect_unused(Main *bmain, BKE_collection_object_add(bmain, collection, ob); base = BKE_view_layer_base_find(view_layer, ob); - base->flag |= BASE_SELECTED; - BKE_scene_object_base_flag_sync_from_base(base); + ED_object_base_select(base, BA_SELECT); DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION); changed = true; @@ -2146,7 +2209,8 @@ static void make_local_material_tag(Material *ma) ma->id.tag &= ~LIB_TAG_PRE_EXISTING; make_local_animdata_tag(BKE_animdata_from_id(&ma->id)); - /* About nodetrees: root one is made local together with material, others we keep linked for now... */ + /* About nodetrees: root one is made local together with material, + * others we keep linked for now... */ } } @@ -2365,7 +2429,8 @@ static int make_override_static_exec(bContext *C, wmOperator *op) } FOREACH_COLLECTION_OBJECT_RECURSIVE_END; - /* Then, we remove (untag) bone shape objects, you shall never want to override those (hopefully)... */ + /* Then, we remove (untag) bone shape objects, you shall never want to override those + * (hopefully)... */ FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (collection, ob) { if (ob->type == OB_ARMATURE && ob->pose != NULL) { for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan != NULL; pchan = pchan->next) { @@ -2582,8 +2647,9 @@ static int drop_named_material_invoke(bContext *C, wmOperator *op, const wmEvent RNA_string_get(op->ptr, "name", name); ma = (Material *)BKE_libblock_find_name(bmain, ID_MA, name); - if (base == NULL || ma == NULL) + if (base == NULL || ma == NULL) { return OPERATOR_CANCELLED; + } assign_material(CTX_data_main(C), base->object, ma, 1, BKE_MAT_ASSIGN_USERPREF); diff --git a/source/blender/editors/object/object_select.c b/source/blender/editors/object/object_select.c index 06bd4d76973..afdda8d6b7f 100644 --- a/source/blender/editors/object/object_select.c +++ b/source/blender/editors/object/object_select.c @@ -87,7 +87,7 @@ * \{ */ /** - * simple API for object selection, rather than just using the flag + * Simple API for object selection, rather than just using the flag * this takes into account the 'restrict selection in 3d view' flag. * deselect works always, the restriction just prevents selection * @@ -387,10 +387,12 @@ static bool objects_selectable_poll(bContext *C) * still allowed then for inspection of scene */ Object *obact = CTX_data_active_object(C); - if (CTX_data_edit_object(C)) + if (CTX_data_edit_object(C)) { return 0; - if (obact && obact->mode) + } + if (obact && obact->mode) { return 0; + } return 1; } @@ -470,7 +472,8 @@ enum { }; static const EnumPropertyItem prop_select_linked_types[] = { - //{OBJECT_SELECT_LINKED_IPO, "IPO", 0, "Object IPO", ""}, // XXX deprecated animation system stuff... + /* XXX deprecated animation system stuff. */ + // {OBJECT_SELECT_LINKED_IPO, "IPO", 0, "Object IPO", ""}, {OBJECT_SELECT_LINKED_OBDATA, "OBDATA", 0, "Object Data", ""}, {OBJECT_SELECT_LINKED_MATERIAL, "MATERIAL", 0, "Material", ""}, {OBJECT_SELECT_LINKED_DUPGROUP, "DUPGROUP", 0, "Instanced Collection", ""}, @@ -652,13 +655,14 @@ static int object_select_linked_exec(bContext *C, wmOperator *op) if (nr == OBJECT_SELECT_LINKED_IPO) { // XXX old animation system - //if (ob->ipo == 0) return OPERATOR_CANCELLED; - //object_select_all_by_ipo(C, ob->ipo) + // if (ob->ipo == 0) return OPERATOR_CANCELLED; + // object_select_all_by_ipo(C, ob->ipo) return OPERATOR_CANCELLED; } else if (nr == OBJECT_SELECT_LINKED_OBDATA) { - if (ob->data == NULL) + if (ob->data == NULL) { return OPERATOR_CANCELLED; + } changed = object_select_all_by_obdata(C, ob->data); } @@ -666,20 +670,23 @@ static int object_select_linked_exec(bContext *C, wmOperator *op) Material *mat = NULL; mat = give_current_material(ob, ob->actcol); - if (mat == NULL) + if (mat == NULL) { return OPERATOR_CANCELLED; + } changed = object_select_all_by_material(C, mat); } else if (nr == OBJECT_SELECT_LINKED_DUPGROUP) { - if (ob->instance_collection == NULL) + if (ob->instance_collection == NULL) { return OPERATOR_CANCELLED; + } changed = object_select_all_by_instance_collection(C, ob); } else if (nr == OBJECT_SELECT_LINKED_PARTICLE) { - if (BLI_listbase_is_empty(&ob->particlesystem)) + if (BLI_listbase_is_empty(&ob->particlesystem)) { return OPERATOR_CANCELLED; + } changed = object_select_all_by_particle(C, ob); } @@ -688,13 +695,15 @@ static int object_select_linked_exec(bContext *C, wmOperator *op) changed = object_select_all_by_library(C, ob->id.lib); } else if (nr == OBJECT_SELECT_LINKED_LIBRARY_OBDATA) { - if (ob->data == NULL) + if (ob->data == NULL) { return OPERATOR_CANCELLED; + } changed = object_select_all_by_library_obdata(C, ((ID *)ob->data)->lib); } - else + else { return OPERATOR_CANCELLED; + } if (changed) { DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); @@ -829,8 +838,9 @@ static bool select_grouped_collection(bContext *C, Object *ob) } } - if (!collection_count) + if (!collection_count) { return 0; + } else if (collection_count == 1) { collection = ob_collections[0]; CTX_DATA_BEGIN (C, Base *, base, visible_bases) { @@ -1174,8 +1184,9 @@ static int object_select_same_collection_exec(bContext *C, wmOperator *op) char collection_name[MAX_ID_NAME]; /* passthrough if no objects are visible */ - if (CTX_DATA_COUNT(C, visible_bases) == 0) + if (CTX_DATA_COUNT(C, visible_bases) == 0) { return OPERATOR_PASS_THROUGH; + } RNA_string_get(op->ptr, "collection", collection_name); @@ -1251,8 +1262,9 @@ static int object_select_mirror_exec(bContext *C, wmOperator *op) } } - if (extend == false) + if (extend == false) { ED_object_base_select(primbase, BA_DESELECT); + } } CTX_DATA_END; diff --git a/source/blender/editors/object/object_shader_fx.c b/source/blender/editors/object/object_shader_fx.c index 64535d8f281..f4f944459f7 100644 --- a/source/blender/editors/object/object_shader_fx.c +++ b/source/blender/editors/object/object_shader_fx.c @@ -110,8 +110,9 @@ static bool UNUSED_FUNCTION(object_has_shaderfx)(const Object *ob, ShaderFxData *fx; for (fx = ob->shader_fx.first; fx; fx = fx->next) { - if ((fx != exclude) && (fx->type == type)) + if ((fx != exclude) && (fx->type == type)) { return true; + } } return false; @@ -161,8 +162,9 @@ void ED_object_shaderfx_clear(Main *bmain, Object *ob) ShaderFxData *fx = ob->shader_fx.first; bool sort_depsgraph = false; - if (!fx) + if (!fx) { return; + } while (fx) { ShaderFxData *next_fx; @@ -207,8 +209,9 @@ static int shaderfx_add_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); int type = RNA_enum_get(op->ptr, "type"); - if (!ED_object_shaderfx_add(op->reports, bmain, scene, ob, NULL, type)) + if (!ED_object_shaderfx_add(op->reports, bmain, scene, ob, NULL, type)) { return OPERATOR_CANCELLED; + } WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -226,16 +229,18 @@ static const EnumPropertyItem *shaderfx_add_itemf(bContext *C, const ShaderFxTypeInfo *mti; int totitem = 0, a; - if (!ob) + if (!ob) { return rna_enum_object_shaderfx_type_items; + } for (a = 0; rna_enum_object_shaderfx_type_items[a].identifier; a++) { fx_item = &rna_enum_object_shaderfx_type_items[a]; if (fx_item->identifier[0]) { mti = BKE_shaderfxType_getInfo(fx_item->value); - if (mti->flags & eShaderFxTypeFlag_NoUserAdd) + if (mti->flags & eShaderFxTypeFlag_NoUserAdd) { continue; + } } else { group_item = fx_item; @@ -281,7 +286,9 @@ void OBJECT_OT_shaderfx_add(wmOperatorType *ot) BLT_I18NCONTEXT_ID_ID); /* Abused, for "Light"... */ } -/************************ generic functions for operators using names and data context *********************/ +/* -------------------------------------------------------------------- */ +/** \name Generic Functions for Operators Using Names and Data Context + * \{ */ static bool edit_shaderfx_poll_generic(bContext *C, StructRNA *rna_type, int obtype_flag) { @@ -293,12 +300,15 @@ static bool edit_shaderfx_poll_generic(bContext *C, StructRNA *rna_type, int obt return 0; } - if (!ob || ID_IS_LINKED(ob)) + if (!ob || ID_IS_LINKED(ob)) { return 0; - if (obtype_flag && ((1 << ob->type) & obtype_flag) == 0) + } + if (obtype_flag && ((1 << ob->type) & obtype_flag) == 0) { return 0; - if (ptr.id.data && ID_IS_LINKED(ptr.id.data)) + } + if (ptr.id.data && ID_IS_LINKED(ptr.id.data)) { return 0; + } if (ID_IS_STATIC_OVERRIDE(ob)) { CTX_wm_operator_poll_msg_set(C, "Cannot edit shaderfxs coming from static override"); @@ -347,12 +357,15 @@ static ShaderFxData *edit_shaderfx_property_get(wmOperator *op, Object *ob, int fx = BKE_shaderfx_findByName(ob, shaderfx_name); - if (fx && type != 0 && fx->type != type) + if (fx && type != 0 && fx->type != type) { fx = NULL; + } return fx; } +/** \} */ + /************************ remove shaderfx operator *********************/ static int shaderfx_remove_exec(bContext *C, wmOperator *op) @@ -361,8 +374,9 @@ static int shaderfx_remove_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); ShaderFxData *fx = edit_shaderfx_property_get(op, ob, 0); - if (!fx || !ED_object_shaderfx_remove(op->reports, bmain, ob, fx)) + if (!fx || !ED_object_shaderfx_remove(op->reports, bmain, ob, fx)) { return OPERATOR_CANCELLED; + } WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -371,10 +385,12 @@ static int shaderfx_remove_exec(bContext *C, wmOperator *op) static int shaderfx_remove_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_shaderfx_invoke_properties(C, op)) + if (edit_shaderfx_invoke_properties(C, op)) { return shaderfx_remove_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_shaderfx_remove(wmOperatorType *ot) @@ -399,8 +415,9 @@ static int shaderfx_move_up_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); ShaderFxData *fx = edit_shaderfx_property_get(op, ob, 0); - if (!fx || !ED_object_shaderfx_move_up(op->reports, ob, fx)) + if (!fx || !ED_object_shaderfx_move_up(op->reports, ob, fx)) { return OPERATOR_CANCELLED; + } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -410,10 +427,12 @@ static int shaderfx_move_up_exec(bContext *C, wmOperator *op) static int shaderfx_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_shaderfx_invoke_properties(C, op)) + if (edit_shaderfx_invoke_properties(C, op)) { return shaderfx_move_up_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_shaderfx_move_up(wmOperatorType *ot) @@ -438,8 +457,9 @@ static int shaderfx_move_down_exec(bContext *C, wmOperator *op) Object *ob = ED_object_active_context(C); ShaderFxData *fx = edit_shaderfx_property_get(op, ob, 0); - if (!fx || !ED_object_shaderfx_move_down(op->reports, ob, fx)) + if (!fx || !ED_object_shaderfx_move_down(op->reports, ob, fx)) { return OPERATOR_CANCELLED; + } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -449,10 +469,12 @@ static int shaderfx_move_down_exec(bContext *C, wmOperator *op) static int shaderfx_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (edit_shaderfx_invoke_properties(C, op)) + if (edit_shaderfx_invoke_properties(C, op)) { return shaderfx_move_down_exec(C, op); - else + } + else { return OPERATOR_CANCELLED; + } } void OBJECT_OT_shaderfx_move_down(wmOperatorType *ot) diff --git a/source/blender/editors/object/object_shapekey.c b/source/blender/editors/object/object_shapekey.c index aa0c6cbeef4..fb76ba6099d 100644 --- a/source/blender/editors/object/object_shapekey.c +++ b/source/blender/editors/object/object_shapekey.c @@ -110,8 +110,9 @@ static bool object_shape_key_mirror( *r_totmirr = *r_totfail = 0; key = BKE_key_from_object(ob); - if (key == NULL) + if (key == NULL) { return 0; + } kb = BLI_findlink(&key->block, ob->shapenr - 1); @@ -335,11 +336,13 @@ static int shape_key_clear_exec(bContext *C, wmOperator *UNUSED(op)) Key *key = BKE_key_from_object(ob); KeyBlock *kb = BKE_keyblock_from_object(ob); - if (!key || !kb) + if (!key || !kb) { return OPERATOR_CANCELLED; + } - for (kb = key->block.first; kb; kb = kb->next) + for (kb = key->block.first; kb; kb = kb->next) { kb->curval = 0.0f; + } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); @@ -370,8 +373,9 @@ static int shape_key_retime_exec(bContext *C, wmOperator *UNUSED(op)) KeyBlock *kb = BKE_keyblock_from_object(ob); float cfra = 0.0f; - if (!key || !kb) + if (!key || !kb) { return OPERATOR_CANCELLED; + } for (kb = key->block.first; kb; kb = kb->next) { kb->pos = cfra; @@ -405,8 +409,9 @@ static int shape_key_mirror_exec(bContext *C, wmOperator *op) int totmirr = 0, totfail = 0; bool use_topology = RNA_boolean_get(op->ptr, "use_topology"); - if (!object_shape_key_mirror(C, ob, &totmirr, &totfail, use_topology)) + if (!object_shape_key_mirror(C, ob, &totmirr, &totfail, use_topology)) { return OPERATOR_CANCELLED; + } ED_mesh_report_mirror(op, totmirr, totfail); diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index f2f6afcac81..8836d913475 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -82,18 +82,21 @@ static void object_clear_loc(Object *ob, const bool clear_delta) /* clear location if not locked */ if ((ob->protectflag & OB_LOCK_LOCX) == 0) { ob->loc[0] = 0.0f; - if (clear_delta) + if (clear_delta) { ob->dloc[0] = 0.0f; + } } if ((ob->protectflag & OB_LOCK_LOCY) == 0) { ob->loc[1] = 0.0f; - if (clear_delta) + if (clear_delta) { ob->dloc[1] = 0.0f; + } } if ((ob->protectflag & OB_LOCK_LOCZ) == 0) { ob->loc[2] = 0.0f; - if (clear_delta) + if (clear_delta) { ob->dloc[2] = 0.0f; + } } } @@ -107,52 +110,63 @@ static void object_clear_rot(Object *ob, const bool clear_delta) if (ob->rotmode == ROT_MODE_AXISANGLE) { if ((ob->protectflag & OB_LOCK_ROTW) == 0) { ob->rotAngle = 0.0f; - if (clear_delta) + if (clear_delta) { ob->drotAngle = 0.0f; + } } if ((ob->protectflag & OB_LOCK_ROTX) == 0) { ob->rotAxis[0] = 0.0f; - if (clear_delta) + if (clear_delta) { ob->drotAxis[0] = 0.0f; + } } if ((ob->protectflag & OB_LOCK_ROTY) == 0) { ob->rotAxis[1] = 0.0f; - if (clear_delta) + if (clear_delta) { ob->drotAxis[1] = 0.0f; + } } if ((ob->protectflag & OB_LOCK_ROTZ) == 0) { ob->rotAxis[2] = 0.0f; - if (clear_delta) + if (clear_delta) { ob->drotAxis[2] = 0.0f; + } } - /* check validity of axis - axis should never be 0,0,0 (if so, then we make it rotate about y) */ - if (IS_EQF(ob->rotAxis[0], ob->rotAxis[1]) && IS_EQF(ob->rotAxis[1], ob->rotAxis[2])) + /* Check validity of axis - axis should never be 0,0,0 + * (if so, then we make it rotate about y). */ + if (IS_EQF(ob->rotAxis[0], ob->rotAxis[1]) && IS_EQF(ob->rotAxis[1], ob->rotAxis[2])) { ob->rotAxis[1] = 1.0f; + } if (IS_EQF(ob->drotAxis[0], ob->drotAxis[1]) && IS_EQF(ob->drotAxis[1], ob->drotAxis[2]) && - clear_delta) + clear_delta) { ob->drotAxis[1] = 1.0f; + } } else if (ob->rotmode == ROT_MODE_QUAT) { if ((ob->protectflag & OB_LOCK_ROTW) == 0) { ob->quat[0] = 1.0f; - if (clear_delta) + if (clear_delta) { ob->dquat[0] = 1.0f; + } } if ((ob->protectflag & OB_LOCK_ROTX) == 0) { ob->quat[1] = 0.0f; - if (clear_delta) + if (clear_delta) { ob->dquat[1] = 0.0f; + } } if ((ob->protectflag & OB_LOCK_ROTY) == 0) { ob->quat[2] = 0.0f; - if (clear_delta) + if (clear_delta) { ob->dquat[2] = 0.0f; + } } if ((ob->protectflag & OB_LOCK_ROTZ) == 0) { ob->quat[3] = 0.0f; - if (clear_delta) + if (clear_delta) { ob->dquat[3] = 0.0f; + } } /* TODO: does this quat need normalizing now? */ } @@ -160,18 +174,21 @@ static void object_clear_rot(Object *ob, const bool clear_delta) /* the flag may have been set for the other modes, so just ignore the extra flag... */ if ((ob->protectflag & OB_LOCK_ROTX) == 0) { ob->rot[0] = 0.0f; - if (clear_delta) + if (clear_delta) { ob->drot[0] = 0.0f; + } } if ((ob->protectflag & OB_LOCK_ROTY) == 0) { ob->rot[1] = 0.0f; - if (clear_delta) + if (clear_delta) { ob->drot[1] = 0.0f; + } } if ((ob->protectflag & OB_LOCK_ROTZ) == 0) { ob->rot[2] = 0.0f; - if (clear_delta) + if (clear_delta) { ob->drot[2] = 0.0f; + } } } } @@ -193,12 +210,15 @@ static void object_clear_rot(Object *ob, const bool clear_delta) eul[0] = eul[1] = eul[2] = 0.0f; - if (ob->protectflag & OB_LOCK_ROTX) + if (ob->protectflag & OB_LOCK_ROTX) { eul[0] = oldeul[0]; - if (ob->protectflag & OB_LOCK_ROTY) + } + if (ob->protectflag & OB_LOCK_ROTY) { eul[1] = oldeul[1]; - if (ob->protectflag & OB_LOCK_ROTZ) + } + if (ob->protectflag & OB_LOCK_ROTZ) { eul[2] = oldeul[2]; + } if (ob->rotmode == ROT_MODE_QUAT) { eul_to_quat(ob->quat, eul); @@ -218,18 +238,21 @@ static void object_clear_rot(Object *ob, const bool clear_delta) else { if (ob->rotmode == ROT_MODE_QUAT) { unit_qt(ob->quat); - if (clear_delta) + if (clear_delta) { unit_qt(ob->dquat); + } } else if (ob->rotmode == ROT_MODE_AXISANGLE) { unit_axis_angle(ob->rotAxis, &ob->rotAngle); - if (clear_delta) + if (clear_delta) { unit_axis_angle(ob->drotAxis, &ob->drotAngle); + } } else { zero_v3(ob->rot); - if (clear_delta) + if (clear_delta) { zero_v3(ob->drot); + } } } } @@ -240,18 +263,21 @@ static void object_clear_scale(Object *ob, const bool clear_delta) /* clear scale factors which are not locked */ if ((ob->protectflag & OB_LOCK_SCALEX) == 0) { ob->scale[0] = 1.0f; - if (clear_delta) + if (clear_delta) { ob->dscale[0] = 1.0f; + } } if ((ob->protectflag & OB_LOCK_SCALEY) == 0) { ob->scale[1] = 1.0f; - if (clear_delta) + if (clear_delta) { ob->dscale[1] = 1.0f; + } } if ((ob->protectflag & OB_LOCK_SCALEZ) == 0) { ob->scale[2] = 1.0f; - if (clear_delta) + if (clear_delta) { ob->dscale[2] = 1.0f; + } } } @@ -584,8 +610,9 @@ static int apply_objects_internal(bContext *C, } CTX_DATA_END; - if (!changed) + if (!changed) { return OPERATOR_CANCELLED; + } changed = false; @@ -593,10 +620,12 @@ static int apply_objects_internal(bContext *C, CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { /* calculate rotation/scale matrix */ - if (apply_scale && apply_rot) + if (apply_scale && apply_rot) { BKE_object_to_mat3(ob, rsmat); - else if (apply_scale) + } + else if (apply_scale) { BKE_object_scale_to_mat3(ob, rsmat); + } else if (apply_rot) { float tmat[3][3], timat[3][3]; @@ -609,8 +638,9 @@ static int apply_objects_internal(bContext *C, mul_m3_m3m3(rsmat, timat, rsmat); mul_m3_m3m3(rsmat, rsmat, tmat); } - else + else { unit_m3(rsmat); + } copy_m4_m3(mat, rsmat); @@ -632,8 +662,9 @@ static int apply_objects_internal(bContext *C, if (ob->type == OB_MESH) { Mesh *me = ob->data; - if (apply_scale) + if (apply_scale) { multiresModifier_scale_disp(depsgraph, scene, ob); + } /* adjust data */ BKE_mesh_transform(me, mat, true); @@ -686,11 +717,13 @@ static int apply_objects_internal(bContext *C, /* applying scale on camera actually scales clip's reconstruction. * of there's clip assigned to camera nothing to do actually. */ - if (!clip) + if (!clip) { continue; + } - if (apply_scale) + if (apply_scale) { BKE_tracking_reconstruction_scale(&clip->tracking, ob->scale); + } } else if (ob->type == OB_EMPTY) { /* It's possible for empties too, even though they don't @@ -734,10 +767,12 @@ static int apply_objects_internal(bContext *C, continue; } - if (apply_loc) + if (apply_loc) { zero_v3(ob->loc); - if (apply_scale) + } + if (apply_scale) { ob->scale[0] = ob->scale[1] = ob->scale[2] = 1.0f; + } if (apply_rot) { zero_v3(ob->rot); unit_qt(ob->quat); @@ -784,8 +819,9 @@ static int visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op)) } CTX_DATA_END; - if (!changed) + if (!changed) { return OPERATOR_CANCELLED; + } WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); return OPERATOR_FINISHED; @@ -958,10 +994,12 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) } for (tob = bmain->objects.first; tob; tob = tob->id.next) { - if (tob->data) + if (tob->data) { ((ID *)tob->data)->tag &= ~LIB_TAG_DOIT; - if (tob->instance_collection) + } + if (tob->instance_collection) { ((ID *)tob->instance_collection)->tag &= ~LIB_TAG_DOIT; + } } for (ctx_ob = ctx_data_list.first; ctx_ob; ctx_ob = ctx_ob->next) { @@ -1049,8 +1087,9 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) } /* don't allow Z change if curve is 2D */ - if ((ob->type == OB_CURVE) && !(cu->flag & CU_3D)) + if ((ob->type == OB_CURVE) && !(cu->flag & CU_3D)) { cent[2] = 0.0; + } negate_v3_v3(cent_neg, cent); BKE_curve_translate(cu, cent_neg, 1); @@ -1119,8 +1158,9 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) ignore_parent_tx(C, bmain, scene, ob); - if (obedit) + if (obedit) { break; + } } } else if (ob->type == OB_MBALL) { @@ -1206,8 +1246,9 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { /* skip strokes that are invalid for current view */ - if (ED_gpencil_stroke_can_use(C, gps) == false) + if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; + } for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { float mpt[3]; @@ -1257,7 +1298,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) ignore_parent_tx(C, bmain, scene, ob); /* other users? */ - //CTX_DATA_BEGIN (C, Object *, ob_other, selected_editable_objects) + // CTX_DATA_BEGIN (C, Object *, ob_other, selected_editable_objects) //{ /* use existing context looper */ @@ -1283,7 +1324,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) ignore_parent_tx(C, bmain, scene, ob_other); } } - //CTX_DATA_END; + // CTX_DATA_END; } } } @@ -1307,11 +1348,13 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) "%i object(s) not centered, %i changed:", tot_lib_error + tot_multiuser_arm_error, tot_change); - if (tot_lib_error) + if (tot_lib_error) { BKE_reportf(op->reports, RPT_WARNING, "|%i linked library object(s)", tot_lib_error); - if (tot_multiuser_arm_error) + } + if (tot_multiuser_arm_error) { BKE_reportf( op->reports, RPT_WARNING, "|%i multiuser armature object(s)", tot_multiuser_arm_error); + } } return OPERATOR_FINISHED; @@ -1385,11 +1428,12 @@ void OBJECT_OT_origin_set(wmOperatorType *ot) * - campbell. * \{ */ -/* When using multiple objects, apply their relative rotational offset to the active object. */ +/** When using multiple objects, apply their relative rotational offset to the active object. */ #define USE_RELATIVE_ROTATION -/* Disable overlays, ignoring user setting (light wire gets in the way). */ +/** Disable overlays, ignoring user setting (light wire gets in the way). */ #define USE_RENDER_OVERRIDE -/* Calculate a depth if the cursor isn't already over a depth (not essential but feels buggy without). */ +/** Calculate a depth if the cursor isn't already over a depth + * (not essential but feels buggy without). */ #define USE_FAKE_DEPTH_INIT struct XFormAxisItem { diff --git a/source/blender/editors/object/object_utils.c b/source/blender/editors/object/object_utils.c index 06a755c30bd..dbca0bbf97b 100644 --- a/source/blender/editors/object/object_utils.c +++ b/source/blender/editors/object/object_utils.c @@ -133,7 +133,7 @@ bool ED_object_calc_active_center(Object *ob, const bool select_only, float r_ce return false; } else { - if (!select_only || (ob->flag & SELECT)) { + if (!select_only || (ob->base_flag & BASE_SELECTED)) { copy_v3_v3(r_center, ob->obmat[3]); return true; } diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 9af0b64bde2..05a3d86a23c 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -58,6 +58,7 @@ #include "BKE_lattice.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_build.h" #include "DNA_armature_types.h" #include "RNA_access.h" @@ -245,7 +246,8 @@ bool ED_vgroup_parray_alloc(ID *id, * For use with tools that use ED_vgroup_parray_alloc with \a use_vert_sel == true. * This finds the unselected mirror deform verts and copies the weights to them from the selected. * - * \note \a dvert_array has mirrored weights filled in, in case cleanup operations are needed on both. + * \note \a dvert_array has mirrored weights filled in, + * in case cleanup operations are needed on both. */ void ED_vgroup_parray_mirror_sync(Object *ob, MDeformVert **dvert_array, @@ -348,8 +350,9 @@ void ED_vgroup_parray_remove_zero(MDeformVert **dvert_array, while (j--) { MDeformWeight *dw; - if (keep_single && dv->totweight == 1) + if (keep_single && dv->totweight == 1) { break; + } dw = dv->dw + j; if ((dw->def_nr < vgroup_tot) && vgroup_validmap[dw->def_nr]) { @@ -373,10 +376,12 @@ bool ED_vgroup_array_copy(Object *ob, Object *ob_from) int defbase_tot = BLI_listbase_count(&ob->defbase); bool new_vgroup = false; - if (ob == ob_from) + if (ob == ob_from) { return true; + } - /* in case we copy vgroup between two objects using same data, we only have to care about object side of things. */ + /* In case we copy vgroup between two objects using same data, + * we only have to care about object side of things. */ if (ob->data != ob_from->data) { ED_vgroup_parray_alloc(ob_from->data, &dvert_array_from, &dvert_tot_from, false); ED_vgroup_parray_alloc(ob->data, &dvert_array, &dvert_tot, false); @@ -389,10 +394,12 @@ bool ED_vgroup_array_copy(Object *ob, Object *ob_from) if (dvert_tot == 0 || (dvert_tot != dvert_tot_from) || dvert_array_from == NULL || dvert_array == NULL) { - if (dvert_array) + if (dvert_array) { MEM_freeN(dvert_array); - if (dvert_array_from) + } + if (dvert_array_from) { MEM_freeN(dvert_array_from); + } if (new_vgroup == true) { /* free the newly added vgroup since it wasn't compatible */ @@ -412,10 +419,12 @@ bool ED_vgroup_array_copy(Object *ob, Object *ob_from) if (defbase_tot_from < defbase_tot) { /* correct vgroup indices because the number of vgroups is being reduced. */ int *remap = MEM_mallocN(sizeof(int) * (defbase_tot + 1), __func__); - for (i = 0; i <= defbase_tot_from; i++) + for (i = 0; i <= defbase_tot_from; i++) { remap[i] = i; - for (; i <= defbase_tot; i++) + } + for (; i <= defbase_tot; i++) { remap[i] = 0; /* can't use these, so disable */ + } BKE_object_defgroup_remap_update_users(ob, remap); MEM_freeN(remap); @@ -530,8 +539,9 @@ static void ED_mesh_defvert_mirror_update_ob(Object *ob, int def_nr, int vidx) Mesh *me = ob->data; bool use_topology = (me->editflag & ME_EDIT_MIRROR_TOPO) != 0; - if (vidx == -1) + if (vidx == -1) { return; + } vidx_mirr = mesh_get_x_mirror_vert(ob, NULL, vidx, use_topology); @@ -702,20 +712,24 @@ const EnumPropertyItem *ED_object_vgroup_selection_itemf_helper(const bContext * } ob = CTX_data_active_object(C); - if (selection_mask & (1 << WT_VGROUP_ACTIVE)) + if (selection_mask & (1 << WT_VGROUP_ACTIVE)) { RNA_enum_items_add_value(&item, &totitem, WT_vertex_group_select_item, WT_VGROUP_ACTIVE); + } if (BKE_object_pose_armature_get(ob)) { - if (selection_mask & (1 << WT_VGROUP_BONE_SELECT)) + if (selection_mask & (1 << WT_VGROUP_BONE_SELECT)) { RNA_enum_items_add_value( &item, &totitem, WT_vertex_group_select_item, WT_VGROUP_BONE_SELECT); - if (selection_mask & (1 << WT_VGROUP_BONE_DEFORM)) + } + if (selection_mask & (1 << WT_VGROUP_BONE_DEFORM)) { RNA_enum_items_add_value( &item, &totitem, WT_vertex_group_select_item, WT_VGROUP_BONE_DEFORM); + } } - if (selection_mask & (1 << WT_VGROUP_ALL)) + if (selection_mask & (1 << WT_VGROUP_ALL)) { RNA_enum_items_add_value(&item, &totitem, WT_vertex_group_select_item, WT_VGROUP_ALL); + } RNA_enum_item_end(&item, &totitem); *r_free = true; @@ -777,12 +791,14 @@ static void ED_vgroup_nr_vert_add( /* get the vert */ BKE_object_defgroup_array_get(ob->data, &dvert, &tot); - if (dvert == NULL) + if (dvert == NULL) { return; + } /* check that vertnum is valid before trying to get the relevant dvert */ - if ((vertnum < 0) || (vertnum >= tot)) + if ((vertnum < 0) || (vertnum >= tot)) { return; + } if (dvert) { MDeformVert *dv = &dvert[vertnum]; @@ -802,8 +818,9 @@ static void ED_vgroup_nr_vert_add( break; case WEIGHT_ADD: dw->weight += weight; - if (dw->weight >= 1.0f) + if (dw->weight >= 1.0f) { dw->weight = 1.0f; + } break; case WEIGHT_SUBTRACT: dw->weight -= weight; @@ -860,8 +877,9 @@ void ED_vgroup_vert_add(Object *ob, bDeformGroup *dg, int vertnum, float weight, /* if there's no deform verts then create some, */ - if (BKE_object_defgroup_array_get(ob->data, &dv, &tot) && dv == NULL) + if (BKE_object_defgroup_array_get(ob->data, &dv, &tot) && dv == NULL) { BKE_object_defgroup_data_create(ob->data); + } /* call another function to do the work */ @@ -876,7 +894,8 @@ void ED_vgroup_vert_remove(Object *ob, bDeformGroup *dg, int vertnum) * deform group. */ - /* TODO, this is slow in a loop, better pass def_nr directly, but leave for later... - campbell */ + /* TODO(campbell): This is slow in a loop, better pass def_nr directly, + * but leave for later. */ const int def_nr = BLI_findindex(&ob->defbase, dg); if (def_nr != -1) { @@ -965,7 +984,7 @@ float ED_vgroup_vert_weight(Object *ob, bDeformGroup *dg, int vertnum) void ED_vgroup_select_by_name(Object *ob, const char *name) { /* note: ob->actdef==0 signals on painting to create a new one, - * if a bone in posemode is selected */ + * if a bone in posemode is selected */ ob->actdef = defgroup_name_index(ob, name) + 1; } @@ -1001,10 +1020,12 @@ static void vgroup_select_verts(Object *ob, int select) } /* this has to be called, because this function operates on vertices only */ - if (select) + if (select) { EDBM_select_flush(em); /* vertices to edges/faces */ - else + } + else { EDBM_deselect_flush(em); + } } } else { @@ -1019,10 +1040,12 @@ static void vgroup_select_verts(Object *ob, int select) for (i = 0; i < me->totvert; i++, mv++, dv++) { if (!(mv->flag & ME_HIDE)) { if (defvert_find_index(dv, def_nr)) { - if (select) + if (select) { mv->flag |= SELECT; - else + } + else { mv->flag &= ~SELECT; + } } } } @@ -1044,12 +1067,14 @@ static void vgroup_select_verts(Object *ob, int select) tot = lt->pntsu * lt->pntsv * lt->pntsw; for (a = 0, bp = lt->def; a < tot; a++, bp++, dv++) { if (defvert_find_index(dv, def_nr)) { - if (select) + if (select) { bp->f1 |= SELECT; + } else { bp->f1 &= ~SELECT; - if (actbp && bp == actbp) + if (actbp && bp == actbp) { lt->actbp = LT_ACTBP_NONE; + } } } } @@ -1066,8 +1091,9 @@ static void vgroup_duplicate(Object *ob) int i, idg, icdg, dvert_tot = 0; dg = BLI_findlink(&ob->defbase, (ob->actdef - 1)); - if (!dg) + if (!dg) { return; + } if (!strstr(dg->name, "_copy")) { BLI_snprintf(name, sizeof(name), "%s_copy", dg->name); @@ -1204,15 +1230,19 @@ static int *getSurroundingVerts(Mesh *me, int vert, int *count) k = BLI_array_len(verts); /* XXX Maybe a == b is enough? */ while (k-- && !(a == b && a == -1)) { - if (verts[k] == a) + if (verts[k] == a) { a = -1; - else if (verts[k] == b) + } + else if (verts[k] == b) { b = -1; + } } - if (a != -1) + if (a != -1) { BLI_array_append(verts, a); - if (b != -1) + } + if (b != -1) { BLI_array_append(verts, b); + } /* Vert found in this poly, we can go to next one! */ break; @@ -1227,8 +1257,9 @@ static int *getSurroundingVerts(Mesh *me, int vert, int *count) return verts; } -/* get a single point in space by averaging a point cloud (vectors of size 3) - * coord is the place the average is stored, points is the point cloud, count is the number of points in the cloud +/* Get a single point in space by averaging a point cloud (vectors of size 3) + * coord is the place the average is stored, + * points is the point cloud, count is the number of points in the cloud. */ static void getSingleCoordinate(MVert *points, int count, float coord[3]) { @@ -1268,7 +1299,7 @@ static void getVerticalAndHorizontalChange(const float norm[3], dists[index] = dot_v3v3(norm, end) + d; /* vertical change */ changes[index][0] = dists[index] - distToStart; - //printf("vc %f %f\n", distance(end, projB, 3) - distance(start, projA, 3), changes[index][0]); + // printf("vc %f %f\n", distance(end, projB, 3) - distance(start, projA, 3), changes[index][0]); /* horizontal change */ changes[index][1] = len_v3v3(projA, projB); } @@ -1480,8 +1511,9 @@ static void vgroup_fix( Mesh *me = ob->data; MVert *mvert = me->mvert; int *verts = NULL; - if (!(me->editflag & ME_EDIT_PAINT_VERT_SEL)) + if (!(me->editflag & ME_EDIT_PAINT_VERT_SEL)) { return; + } for (i = 0; i < me->totvert && mvert; i++, mvert++) { if (mvert->flag & SELECT) { int count = 0; @@ -1953,15 +1985,17 @@ static void vgroup_smooth_subset(Object *ob, MEM_freeN(emap_mem); } - if (dvert_array) + if (dvert_array) { MEM_freeN(dvert_array); + } /* not so efficient to get 'dvert_array' again just so unselected verts are NULL'd */ if (use_mirror) { ED_vgroup_parray_alloc(ob->data, &dvert_array, &dvert_tot, true); ED_vgroup_parray_mirror_sync(ob, dvert_array, dvert_tot, vgroup_validmap, vgroup_tot); - if (dvert_array) + if (dvert_array) { MEM_freeN(dvert_array); + } } } @@ -1975,14 +2009,18 @@ static int inv_cmp_mdef_vert_weights(const void *a1, const void *a2) * This does the opposite. */ const struct MDeformWeight *dw1 = a1, *dw2 = a2; - if (dw1->weight < dw2->weight) + if (dw1->weight < dw2->weight) { return 1; - else if (dw1->weight > dw2->weight) + } + else if (dw1->weight > dw2->weight) { return -1; - else if (&dw1 < &dw2) + } + else if (&dw1 < &dw2) { return 1; /* compare address for stable sort algorithm */ - else + } + else { return -1; + } } /* Used for limiting the number of influencing bones per vertex when exporting @@ -2407,8 +2445,9 @@ cleanup: *r_totmirr = totmirr; *r_totfail = totfail; - if (flip_map) + if (flip_map) { MEM_freeN(flip_map); + } #undef VGROUP_MIRR_OP } @@ -2416,8 +2455,9 @@ cleanup: static void vgroup_delete_active(Object *ob) { bDeformGroup *dg = BLI_findlink(&ob->defbase, ob->actdef - 1); - if (!dg) + if (!dg) { return; + } BKE_object_defgroup_remove(ob, dg); } @@ -2427,8 +2467,9 @@ static void vgroup_assign_verts(Object *ob, const float weight) { const int def_nr = ob->actdef - 1; - if (!BLI_findlink(&ob->defbase, def_nr)) + if (!BLI_findlink(&ob->defbase, def_nr)) { return; + } if (ob->type == OB_MESH) { Mesh *me = ob->data; @@ -2440,8 +2481,9 @@ static void vgroup_assign_verts(Object *ob, const float weight) BMIter iter; BMVert *eve; - if (!CustomData_has_layer(&em->bm->vdata, CD_MDEFORMVERT)) + if (!CustomData_has_layer(&em->bm->vdata, CD_MDEFORMVERT)) { BM_data_layer_add(em->bm, &em->bm->vdata, CD_MDEFORMVERT); + } cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); @@ -2487,8 +2529,9 @@ static void vgroup_assign_verts(Object *ob, const float weight) BPoint *bp; int a, tot; - if (lt->dvert == NULL) + if (lt->dvert == NULL) { BKE_object_defgroup_data_create(<->id); + } dv = lt->dvert; @@ -2546,8 +2589,9 @@ static bool UNUSED_FUNCTION(vertex_group_poll_edit)(bContext *C) Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; - if (!(ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data))) + if (!(ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data))) { return 0; + } return BKE_object_is_in_editmode_vgroup(ob); } @@ -2560,8 +2604,9 @@ static bool vertex_group_vert_poll_ex(bContext *C, Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; - if (!(ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data))) + if (!(ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data))) { return false; + } if (ob_type_flag && (((1 << ob->type) & ob_type_flag)) == 0) { return false; @@ -2619,8 +2664,9 @@ static bool vertex_group_vert_select_unlocked_poll(bContext *C) Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; - if (!(ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data))) + if (!(ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data))) { return 0; + } if (!(BKE_object_is_in_editmode_vgroup(ob) || BKE_object_is_in_wpaint_select_vert(ob))) { return 0; @@ -2640,12 +2686,14 @@ static bool vertex_group_vert_select_mesh_poll(bContext *C) Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; - if (!(ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data))) + if (!(ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data))) { return 0; + } /* only difference to #vertex_group_vert_select_poll */ - if (ob->type != OB_MESH) + if (ob->type != OB_MESH) { return 0; + } return (BKE_object_is_in_editmode_vgroup(ob) || BKE_object_is_in_wpaint_select_vert(ob)); } @@ -2655,6 +2703,7 @@ static int vertex_group_add_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_object_context(C); BKE_object_defgroup_add(ob); + DEG_relations_tag_update(CTX_data_main(C)); DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob->data); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); @@ -2681,14 +2730,18 @@ static int vertex_group_remove_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_context(C); - if (RNA_boolean_get(op->ptr, "all")) + if (RNA_boolean_get(op->ptr, "all")) { BKE_object_defgroup_remove_all(ob); - else if (RNA_boolean_get(op->ptr, "all_unlocked")) + } + else if (RNA_boolean_get(op->ptr, "all_unlocked")) { BKE_object_defgroup_remove_all_ex(ob, true); - else + } + else { vgroup_delete_active(ob); + } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + DEG_relations_tag_update(CTX_data_main(C)); WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob->data); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); @@ -2834,8 +2887,9 @@ static int vertex_group_select_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = ED_object_context(C); - if (!ob || ID_IS_LINKED(ob)) + if (!ob || ID_IS_LINKED(ob)) { return OPERATOR_CANCELLED; + } vgroup_select_verts(ob, 1); DEG_id_tag_update(ob->data, ID_RECALC_COPY_ON_WRITE | ID_RECALC_SELECT); @@ -2891,6 +2945,7 @@ static int vertex_group_copy_exec(bContext *C, wmOperator *UNUSED(op)) vgroup_duplicate(ob); DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + DEG_relations_tag_update(CTX_data_main(C)); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob->data); @@ -3421,6 +3476,7 @@ static int vertex_group_mirror_exec(bContext *C, wmOperator *op) ED_mesh_report_mirror(op, totmirr, totfail); DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + DEG_relations_tag_update(CTX_data_main(C)); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); @@ -3509,6 +3565,7 @@ static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op) if (obact != ob) { if (ED_vgroup_array_copy(ob, obact)) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + DEG_relations_tag_update(CTX_data_main(C)); WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob); changed_tot++; } @@ -3571,8 +3628,9 @@ static const EnumPropertyItem *vgroup_itemf(bContext *C, bDeformGroup *def; int a, totitem = 0; - if (!ob) + if (!ob) { return DummyRNA_NULL_items; + } for (a = 0, def = ob->defbase.first; def; def = def->next, a++) { tmp.value = a; @@ -3683,16 +3741,18 @@ static int vgroup_do_remap(Object *ob, const char *name_array, wmOperator *op) /*create as necessary*/ if (dvert) { while (dvert_tot--) { - if (dvert->totweight) + if (dvert->totweight) { defvert_remap(dvert, sort_map, defbase_tot); + } dvert++; } } } /* update users */ - for (i = 0; i < defbase_tot; i++) + for (i = 0; i < defbase_tot; i++) { sort_map[i]++; + } sort_map_update[0] = 0; BKE_object_defgroup_remap_update_users(ob, sort_map_update); @@ -3776,8 +3836,9 @@ static int vertex_group_sort_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob); } - if (name_array) + if (name_array) { MEM_freeN(name_array); + } return ret; } @@ -3828,8 +3889,9 @@ static int vgroup_move_exec(bContext *C, wmOperator *op) } } - if (name_array) + if (name_array) { MEM_freeN(name_array); + } return ret; } diff --git a/source/blender/editors/physics/CMakeLists.txt b/source/blender/editors/physics/CMakeLists.txt index 3eb443320c3..021c17a94c2 100644 --- a/source/blender/editors/physics/CMakeLists.txt +++ b/source/blender/editors/physics/CMakeLists.txt @@ -25,8 +25,8 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/physics/dynamicpaint_ops.c b/source/blender/editors/physics/dynamicpaint_ops.c index e0ea53b06ec..cb8fe262730 100644 --- a/source/blender/editors/physics/dynamicpaint_ops.c +++ b/source/blender/editors/physics/dynamicpaint_ops.c @@ -72,19 +72,19 @@ static int surface_slot_add_exec(bContext *C, wmOperator *UNUSED(op)) /* Make sure we're dealing with a canvas */ pmd = (DynamicPaintModifierData *)modifiers_findByType(cObject, eModifierType_DynamicPaint); - if (!pmd || !pmd->canvas) + if (!pmd || !pmd->canvas) { return OPERATOR_CANCELLED; + } canvas = pmd->canvas; surface = dynamicPaint_createNewSurface(canvas, CTX_data_scene(C)); - if (!surface) + if (!surface) { return OPERATOR_CANCELLED; + } - /* set preview for this surface only and set active */ canvas->active_sur = 0; for (surface = surface->prev; surface; surface = surface->prev) { - surface->flags &= ~MOD_DPAINT_PREVIEW; canvas->active_sur++; } @@ -117,8 +117,9 @@ static int surface_slot_remove_exec(bContext *C, wmOperator *UNUSED(op)) /* Make sure we're dealing with a canvas */ pmd = (DynamicPaintModifierData *)modifiers_findByType(obj_ctx, eModifierType_DynamicPaint); - if (!pmd || !pmd->canvas) + if (!pmd || !pmd->canvas) { return OPERATOR_CANCELLED; + } canvas = pmd->canvas; surface = canvas->surfaces.first; @@ -133,7 +134,6 @@ static int surface_slot_remove_exec(bContext *C, wmOperator *UNUSED(op)) id++; } - dynamicPaint_resetPreview(canvas); DEG_id_tag_update(&obj_ctx->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obj_ctx); @@ -165,8 +165,9 @@ static int type_toggle_exec(bContext *C, wmOperator *op) cObject, eModifierType_DynamicPaint); int type = RNA_enum_get(op->ptr, "type"); - if (!pmd) + if (!pmd) { return OPERATOR_CANCELLED; + } /* if type is already enabled, toggle it off */ if (type == MOD_DYNAMICPAINT_TYPE_CANVAS && pmd->canvas) { @@ -177,8 +178,9 @@ static int type_toggle_exec(bContext *C, wmOperator *op) } /* else create a new type */ else { - if (!dynamicPaint_createType(pmd, type, scene)) + if (!dynamicPaint_createType(pmd, type, scene)) { return OPERATOR_CANCELLED; + } } /* update dependency */ @@ -223,8 +225,9 @@ static int output_toggle_exec(bContext *C, wmOperator *op) ob, eModifierType_DynamicPaint); int output = RNA_enum_get(op->ptr, "output"); /* currently only 1/0 */ - if (!pmd || !pmd->canvas) + if (!pmd || !pmd->canvas) { return OPERATOR_CANCELLED; + } surface = get_activeSurface(pmd->canvas); /* if type is already enabled, toggle it off */ @@ -232,27 +235,34 @@ static int output_toggle_exec(bContext *C, wmOperator *op) int exists = dynamicPaint_outputLayerExists(surface, ob, output); const char *name; - if (output == 0) + if (output == 0) { name = surface->output_name; - else + } + else { name = surface->output_name2; + } /* Vertex Color Layer */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { - if (!exists) + if (!exists) { ED_mesh_color_add(ob->data, name, true, true); - else + } + else { ED_mesh_color_remove_named(ob->data, name); + } } /* Vertex Weight Layer */ else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) { if (!exists) { BKE_object_defgroup_add_name(ob, name); + DEG_relations_tag_update(CTX_data_main(C)); } else { bDeformGroup *defgroup = defgroup_find_name(ob, name); - if (defgroup) + if (defgroup) { BKE_object_defgroup_remove(ob, defgroup); + DEG_relations_tag_update(CTX_data_main(C)); + } } } } diff --git a/source/blender/editors/physics/particle_boids.c b/source/blender/editors/physics/particle_boids.c index cedb7d6cbc1..55fc49165c9 100644 --- a/source/blender/editors/physics/particle_boids.c +++ b/source/blender/editors/physics/particle_boids.c @@ -57,13 +57,15 @@ static int rule_add_exec(bContext *C, wmOperator *op) BoidRule *rule; BoidState *state; - if (!part || part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) { return OPERATOR_CANCELLED; + } state = boid_get_current_state(part->boids); - for (rule = state->rules.first; rule; rule = rule->next) + for (rule = state->rules.first; rule; rule = rule->next) { rule->flag &= ~BOIDRULE_CURRENT; + } rule = boid_new_rule(type); rule->flag |= BOIDRULE_CURRENT; @@ -99,8 +101,9 @@ static int rule_del_exec(bContext *C, wmOperator *UNUSED(op)) BoidRule *rule; BoidState *state; - if (!part || part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) { return OPERATOR_CANCELLED; + } state = boid_get_current_state(part->boids); @@ -113,8 +116,9 @@ static int rule_del_exec(bContext *C, wmOperator *UNUSED(op)) } rule = state->rules.first; - if (rule) + if (rule) { rule->flag |= BOIDRULE_CURRENT; + } DEG_relations_tag_update(bmain); DEG_id_tag_update(&part->id, ID_RECALC_GEOMETRY | ID_RECALC_PSYS_RESET); @@ -144,8 +148,9 @@ static int rule_move_up_exec(bContext *C, wmOperator *UNUSED(op)) BoidRule *rule; BoidState *state; - if (!part || part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) { return OPERATOR_CANCELLED; + } state = boid_get_current_state(part->boids); for (rule = state->rules.first; rule; rule = rule->next) { @@ -180,8 +185,9 @@ static int rule_move_down_exec(bContext *C, wmOperator *UNUSED(op)) BoidRule *rule; BoidState *state; - if (!part || part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) { return OPERATOR_CANCELLED; + } state = boid_get_current_state(part->boids); for (rule = state->rules.first; rule; rule = rule->next) { @@ -216,11 +222,13 @@ static int state_add_exec(bContext *C, wmOperator *UNUSED(op)) ParticleSettings *part = ptr.data; BoidState *state; - if (!part || part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) { return OPERATOR_CANCELLED; + } - for (state = part->boids->states.first; state; state = state->next) + for (state = part->boids->states.first; state; state = state->next) { state->flag &= ~BOIDSTATE_CURRENT; + } state = boid_new_state(part->boids); state->flag |= BOIDSTATE_CURRENT; @@ -250,8 +258,9 @@ static int state_del_exec(bContext *C, wmOperator *UNUSED(op)) ParticleSettings *part = ptr.data; BoidState *state; - if (!part || part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) { return OPERATOR_CANCELLED; + } for (state = part->boids->states.first; state; state = state->next) { if (state->flag & BOIDSTATE_CURRENT) { @@ -266,8 +275,9 @@ static int state_del_exec(bContext *C, wmOperator *UNUSED(op)) state = boid_new_state(part->boids); BLI_addtail(&part->boids->states, state); } - else + else { state = part->boids->states.first; + } state->flag |= BOIDSTATE_CURRENT; @@ -299,8 +309,9 @@ static int state_move_up_exec(bContext *C, wmOperator *UNUSED(op)) BoidSettings *boids; BoidState *state; - if (!part || part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) { return OPERATOR_CANCELLED; + } boids = part->boids; @@ -334,8 +345,9 @@ static int state_move_down_exec(bContext *C, wmOperator *UNUSED(op)) BoidSettings *boids; BoidState *state; - if (!part || part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) { return OPERATOR_CANCELLED; + } boids = part->boids; diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 627ffd68bbb..dc634865a0a 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -129,21 +129,24 @@ void PE_free_ptcache_edit(PTCacheEdit *edit) { POINT_P; - if (edit == 0) + if (edit == 0) { return; + } if (edit->points) { LOOP_POINTS { - if (point->keys) + if (point->keys) { MEM_freeN(point->keys); + } } MEM_freeN(edit->points); } - if (edit->mirror_cache) + if (edit->mirror_cache) { MEM_freeN(edit->mirror_cache); + } if (edit->emitter_cosnos) { MEM_freeN(edit->emitter_cosnos); @@ -168,8 +171,9 @@ int PE_start_edit(PTCacheEdit *edit) { if (edit) { edit->edited = 1; - if (edit->psys) + if (edit->psys) { edit->psys->flag |= PSYS_EDITED; + } return 1; } @@ -242,8 +246,9 @@ static PTCacheEdit *pe_get_current(Depsgraph *depsgraph, Scene *scene, Object *o ListBase pidlist; PTCacheID *pid; - if (pset == NULL || ob == NULL) + if (pset == NULL || ob == NULL) { return NULL; + } pset->scene = scene; pset->object = ob; @@ -273,8 +278,9 @@ static PTCacheEdit *pe_get_current(Depsgraph *depsgraph, Scene *scene, Object *o if (psys->flag & PSYS_CURRENT) { if (psys->part && psys->part->type == PART_HAIR) { if (psys->flag & PSYS_HAIR_DYNAMICS && psys->pointcache->flag & PTCACHE_BAKED) { - if (create && !psys->pointcache->edit) + if (create && !psys->pointcache->edit) { PE_create_particle_edit(depsgraph, scene, ob, pid->cache, NULL); + } edit = pid->cache->edit; } else { @@ -287,8 +293,9 @@ static PTCacheEdit *pe_get_current(Depsgraph *depsgraph, Scene *scene, Object *o } } else { - if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit) + if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit) { PE_create_particle_edit(depsgraph, scene, ob, pid->cache, psys); + } edit = pid->cache->edit; } @@ -359,11 +366,12 @@ void PE_hide_keys_time(Scene *scene, PTCacheEdit *edit, float cfra) { LOOP_KEYS { - if (fabsf(cfra - *key->time) < pset->fade_frames) + if (fabsf(cfra - *key->time) < pset->fade_frames) { key->flag &= ~PEK_HIDE; + } else { key->flag |= PEK_HIDE; - //key->flag &= ~PEK_SELECT; + // key->flag &= ~PEK_SELECT; } } } @@ -381,8 +389,9 @@ void PE_hide_keys_time(Scene *scene, PTCacheEdit *edit, float cfra) static int pe_x_mirror(Object *ob) { - if (ob->type == OB_MESH) + if (ob->type == OB_MESH) { return (((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_X); + } return 0; } @@ -505,14 +514,17 @@ static bool key_test_depth(const PEData *data, const float co[3], const int scre float depth; /* nothing to do */ - if (XRAY_ENABLED(v3d)) + if (XRAY_ENABLED(v3d)) { return true; + } - /* used to calculate here but all callers have the screen_co already, so pass as arg */ + /* used to calculate here but all callers have the screen_co already, so pass as arg */ #if 0 - if (ED_view3d_project_int_global(data->vc.ar, co, screen_co, - V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) != V3D_PROJ_RET_OK) - { + if (ED_view3d_project_int_global(data->vc.ar, + co, + screen_co, + V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | + V3D_PROJ_TEST_CLIP_NEAR) != V3D_PROJ_RET_OK) { return 0; } #endif @@ -523,16 +535,19 @@ static bool key_test_depth(const PEData *data, const float co[3], const int scre /* we know its not clipped */ depth = vd->depths[screen_co[1] * vd->w + screen_co[0]]; } - else + else { return 0; + } float win[3]; ED_view3d_project(data->vc.ar, co, win); - if (win[2] - 0.00001f > depth) + if (win[2] - 0.00001f > depth) { return 0; - else + } + else { return 1; + } } static bool key_inside_circle(const PEData *data, float rad, const float co[3], float *distance) @@ -550,12 +565,14 @@ static bool key_inside_circle(const PEData *data, float rad, const float co[3], dy = data->mval[1] - screen_co[1]; dist = sqrtf(dx * dx + dy * dy); - if (dist > rad) + if (dist > rad) { return 0; + } if (key_test_depth(data, co, screen_co)) { - if (distance) + if (distance) { *distance = dist; + } return 1; } @@ -582,18 +599,21 @@ static bool key_inside_rect(PEData *data, const float co[3]) static bool key_inside_test(PEData *data, const float co[3]) { - if (data->mval) + if (data->mval) { return key_inside_circle(data, data->rad, co, NULL); - else + } + else { return key_inside_rect(data, co); + } } static bool point_is_selected(PTCacheEditPoint *point) { KEY_K; - if (point->flag & PEP_HIDE) + if (point->flag & PEP_HIDE) { return 0; + } LOOP_SELECTED_KEYS { @@ -639,8 +659,9 @@ static void for_mouse_hit_keys(PEData *data, ForKeyFunc func, const enum ePartic float dist = data->rad; /* in path select mode we have no keys */ - if (pset->selectmode == SCE_SELECT_PATH) + if (pset->selectmode == SCE_SELECT_PATH) { return; + } nearest_point = -1; nearest_key = -1; @@ -702,8 +723,9 @@ static void foreach_mouse_hit_point(PEData *data, ForHitPointFunc func, int sele KEY_K; /* all is selected in path mode */ - if (pset->selectmode == SCE_SELECT_PATH) + if (pset->selectmode == SCE_SELECT_PATH) { selected = 0; + } LOOP_VISIBLE_POINTS { @@ -876,8 +898,9 @@ static int count_selected_keys(Scene *scene, PTCacheEdit *edit) else if (pset->selectmode == SCE_SELECT_END) { if (point->totkey) { key = point->keys + point->totkey - 1; - if (key->flag & PEK_SELECT) + if (key->flag & PEK_SELECT) { sel++; + } } } } @@ -904,8 +927,9 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys) psmd_eval = edit->psmd_eval; totpart = psys->totpart; - if (!psmd_eval->mesh_final) + if (!psmd_eval->mesh_final) { return; + } tree = BLI_kdtree_3d_new(totpart); @@ -922,8 +946,9 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys) BLI_kdtree_3d_balance(tree); /* lookup particles and set in mirror cache */ - if (!edit->mirror_cache) + if (!edit->mirror_cache) { edit->mirror_cache = MEM_callocN(sizeof(int) * totpart, "PE mirror cache"); + } LOOP_PARTICLES { @@ -936,10 +961,12 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys) index = BLI_kdtree_3d_find_nearest(tree, co, &nearest); /* this needs a custom threshold still, duplicated for editmode mirror */ - if (index != -1 && index != p && (nearest.dist <= 0.0002f)) + if (index != -1 && index != p && (nearest.dist <= 0.0002f)) { edit->mirror_cache[p] = index; - else + } + else { edit->mirror_cache[p] = -1; + } } /* make sure mirrors are in two directions */ @@ -947,8 +974,9 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys) { if (edit->mirror_cache[p]) { index = edit->mirror_cache[p]; - if (edit->mirror_cache[index] != p) + if (edit->mirror_cache[index] != p) { edit->mirror_cache[p] = -1; + } } } @@ -970,29 +998,35 @@ static void PE_mirror_particle( /* find mirrored particle if needed */ if (!mpa) { - if (!edit->mirror_cache) + if (!edit->mirror_cache) { PE_update_mirror_cache(ob, psys); + } - if (!edit->mirror_cache) + if (!edit->mirror_cache) { return; /* something went wrong! */ + } mi = edit->mirror_cache[i]; - if (mi == -1) + if (mi == -1) { return; + } mpa = psys->particles + mi; } - else + else { mi = mpa - psys->particles; + } point = edit->points + i; mpoint = edit->points + mi; /* make sure they have the same amount of keys */ if (pa->totkey != mpa->totkey) { - if (mpa->hair) + if (mpa->hair) { MEM_freeN(mpa->hair); - if (mpoint->keys) + } + if (mpoint->keys) { MEM_freeN(mpoint->keys); + } mpa->hair = MEM_dupallocN(pa->hair); mpa->totkey = pa->totkey; @@ -1023,16 +1057,19 @@ static void PE_mirror_particle( mhkey->co[0] = -mhkey->co[0]; mul_m4_v3(immat, mhkey->co); - if (key->flag & PEK_TAG) + if (key->flag & PEK_TAG) { mkey->flag |= PEK_TAG; + } mkey->length = key->length; } - if (point->flag & PEP_TAG) + if (point->flag & PEP_TAG) { mpoint->flag |= PEP_TAG; - if (point->flag & PEP_EDIT_RECALC) + } + if (point->flag & PEP_EDIT_RECALC) { mpoint->flag |= PEP_EDIT_RECALC; + } } static void PE_apply_mirror(Object *ob, ParticleSystem *psys) @@ -1041,20 +1078,24 @@ static void PE_apply_mirror(Object *ob, ParticleSystem *psys) ParticleSystemModifierData *psmd_eval; POINT_P; - if (!psys) + if (!psys) { return; + } edit = psys->edit; psmd_eval = edit->psmd_eval; - if (!psmd_eval->mesh_final) + if (!psmd_eval->mesh_final) { return; + } - if (!edit->mirror_cache) + if (!edit->mirror_cache) { PE_update_mirror_cache(ob, psys); + } - if (!edit->mirror_cache) + if (!edit->mirror_cache) { return; /* something went wrong */ + } /* we delay settings the PARS_EDIT_RECALC for mirrored particles * to avoid doing mirror twice */ @@ -1063,16 +1104,19 @@ static void PE_apply_mirror(Object *ob, ParticleSystem *psys) if (point->flag & PEP_EDIT_RECALC) { PE_mirror_particle(ob, psmd_eval->mesh_final, psys, psys->particles + p, NULL); - if (edit->mirror_cache[p] != -1) + if (edit->mirror_cache[p] != -1) { edit->points[edit->mirror_cache[p]].flag &= ~PEP_EDIT_RECALC; + } } } LOOP_POINTS { - if (point->flag & PEP_EDIT_RECALC) - if (edit->mirror_cache[p] != -1) + if (point->flag & PEP_EDIT_RECALC) { + if (edit->mirror_cache[p] != -1) { edit->points[edit->mirror_cache[p]].flag |= PEP_EDIT_RECALC; + } + } } } @@ -1223,11 +1267,13 @@ static void PE_apply_lengths(Scene *scene, PTCacheEdit *edit) { ParticleEditSettings *pset = PE_settings(scene); - if (edit == 0 || (pset->flag & PE_KEEP_LENGTHS) == 0) + if (edit == 0 || (pset->flag & PE_KEEP_LENGTHS) == 0) { return; + } - if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR) + if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR) { return; + } ApplyLengthsIterData iter_data; iter_data.edit = edit; @@ -1319,8 +1365,9 @@ void recalc_lengths(PTCacheEdit *edit) POINT_P; KEY_K; - if (edit == 0) + if (edit == 0) { return; + } LOOP_EDITED_POINTS { @@ -1339,11 +1386,13 @@ void recalc_emitter_field(Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), Part float *vec, *nor; int i, totface /*, totvert*/; - if (!mesh) + if (!mesh) { return; + } - if (edit->emitter_cosnos) + if (edit->emitter_cosnos) { MEM_freeN(edit->emitter_cosnos); + } BLI_kdtree_3d_free(edit->emitter_field); @@ -1400,11 +1449,12 @@ static void PE_update_selection(Depsgraph *depsgraph, Scene *scene, Object *ob, KEY_K; /* flag all particles to be updated if not using flag */ - if (!useflag) + if (!useflag) { LOOP_POINTS { point->flag |= PEP_EDIT_RECALC; } + } /* flush edit key flag to hair key flag to preserve selection * on save */ @@ -1439,20 +1489,23 @@ void update_world_cos(Depsgraph *UNUSED(depsgraph), Object *ob, PTCacheEdit *edi KEY_K; float hairmat[4][4]; - if (psys == 0 || psys->edit == 0 || psmd_eval->mesh_final == NULL) + if (psys == 0 || psys->edit == 0 || psmd_eval->mesh_final == NULL) { return; + } LOOP_POINTS { - if (!(psys->flag & PSYS_GLOBAL_HAIR)) + if (!(psys->flag & PSYS_GLOBAL_HAIR)) { psys_mat_hair_to_global( ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, hairmat); + } LOOP_KEYS { copy_v3_v3(key->world_co, key->co); - if (!(psys->flag & PSYS_GLOBAL_HAIR)) + if (!(psys->flag & PSYS_GLOBAL_HAIR)) { mul_m4_v3(hairmat, key->world_co); + } } } } @@ -1464,8 +1517,9 @@ static void update_velocities(PTCacheEdit *edit) KEY_K; /* hair doesn't use velocities */ - if (edit->psys || !edit->points || !edit->points->keys->vel) + if (edit->psys || !edit->points || !edit->points->keys->vel) { return; + } frs_sec = edit->pid.flag & PTCACHE_VEL_PER_SEC ? 25.0f : 1.0f; @@ -1476,8 +1530,9 @@ static void update_velocities(PTCacheEdit *edit) if (k == 0) { dfra = *(key + 1)->time - *key->time; - if (dfra <= 0.0f) + if (dfra <= 0.0f) { continue; + } sub_v3_v3v3(key->vel, (key + 1)->co, key->co); @@ -1491,8 +1546,9 @@ static void update_velocities(PTCacheEdit *edit) else if (k == point->totkey - 1) { dfra = *key->time - *(key - 1)->time; - if (dfra <= 0.0f) + if (dfra <= 0.0f) { continue; + } sub_v3_v3v3(key->vel, key->co, (key - 1)->co); @@ -1506,8 +1562,9 @@ static void update_velocities(PTCacheEdit *edit) else { dfra = *(key + 1)->time - *(key - 1)->time; - if (dfra <= 0.0f) + if (dfra <= 0.0f) { continue; + } sub_v3_v3v3(key->vel, (key + 1)->co, (key - 1)->co); } @@ -1524,26 +1581,31 @@ void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int usefla PTCacheEdit *edit = PE_get_current(scene, ob); POINT_P; - if (!edit) + if (!edit) { return; + } /* flag all particles to be updated if not using flag */ - if (!useflag) + if (!useflag) { LOOP_POINTS { point->flag |= PEP_EDIT_RECALC; } + } /* do post process on particle edit keys */ pe_iterate_lengths(scene, edit); pe_deflect_emitter(scene, ob, edit); PE_apply_lengths(scene, edit); - if (pe_x_mirror(ob)) + if (pe_x_mirror(ob)) { PE_apply_mirror(ob, edit->psys); - if (edit->psys) + } + if (edit->psys) { update_world_cos(depsgraph, ob, edit); - if (pset->flag & PE_AUTO_VELOCITY) + } + if (pset->flag & PE_AUTO_VELOCITY) { update_velocities(edit); + } PE_hide_keys_time(scene, edit, CFRA); /* regenerate path caches */ @@ -1555,8 +1617,9 @@ void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int usefla point->flag &= ~PEP_EDIT_RECALC; } - if (edit->psys) + if (edit->psys) { edit->psys->flag &= ~PSYS_HAIR_UPDATED; + } } /************************************************/ @@ -1571,10 +1634,12 @@ static void select_key(PEData *data, int point_index, int key_index, bool UNUSED PTCacheEditPoint *point = edit->points + point_index; PTCacheEditKey *key = point->keys + key_index; - if (data->select) + if (data->select) { key->flag |= PEK_SELECT; - else + } + else { key->flag &= ~PEK_SELECT; + } point->flag |= PEP_EDIT_RECALC; data->is_changed = true; @@ -1605,10 +1670,12 @@ static void select_keys(PEData *data, LOOP_KEYS { - if (data->select) + if (data->select) { key->flag |= PEK_SELECT; - else + } + else { key->flag &= ~PEK_SELECT; + } } point->flag |= PEP_EDIT_RECALC; @@ -1710,8 +1777,9 @@ static int pe_select_all_exec(bContext *C, wmOperator *op) break; } - if (action == SEL_DESELECT) + if (action == SEL_DESELECT) { break; + } } } @@ -1804,8 +1872,9 @@ static void select_root(PEData *data, int point_index) PTCacheEditPoint *point = data->edit->points + point_index; PTCacheEditKey *key = point->keys; - if (point->flag & PEP_HIDE) + if (point->flag & PEP_HIDE) { return; + } if (data->select_action != SEL_TOGGLE) { data->is_changed = select_action_apply(point, key, data->select_action); @@ -1872,8 +1941,9 @@ static void select_tip(PEData *data, int point_index) key = &point->keys[point->totkey - 1]; - if (point->flag & PEP_HIDE) + if (point->flag & PEP_HIDE) { return; + } if (data->select_action != SEL_TOGGLE) { data->is_changed = select_action_apply(point, key, data->select_action); @@ -2188,8 +2258,9 @@ int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, const unit_m4(mat); - if (!PE_start_edit(edit)) + if (!PE_start_edit(edit)) { return OPERATOR_CANCELLED; + } /* only for depths */ PE_set_view3d_data(C, &data); @@ -2200,9 +2271,10 @@ int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, const LOOP_VISIBLE_POINTS { - if (edit->psys && !(psys->flag & PSYS_GLOBAL_HAIR)) + if (edit->psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { psys_mat_hair_to_global( ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, mat); + } if (pset->selectmode == SCE_SELECT_POINT) { LOOP_KEYS @@ -2373,16 +2445,19 @@ static void select_less_keys(PEData *data, int point_index) LOOP_SELECTED_KEYS { if (k == 0) { - if (((key + 1)->flag & PEK_SELECT) == 0) + if (((key + 1)->flag & PEK_SELECT) == 0) { key->flag |= PEK_TAG; + } } else if (k == point->totkey - 1) { - if (((key - 1)->flag & PEK_SELECT) == 0) + if (((key - 1)->flag & PEK_SELECT) == 0) { key->flag |= PEK_TAG; + } } else { - if ((((key - 1)->flag & (key + 1)->flag) & PEK_SELECT) == 0) + if ((((key - 1)->flag & (key + 1)->flag) & PEK_SELECT) == 0) { key->flag |= PEK_TAG; + } } } @@ -2434,20 +2509,24 @@ static void select_more_keys(PEData *data, int point_index) LOOP_KEYS { - if (key->flag & PEK_SELECT) + if (key->flag & PEK_SELECT) { continue; + } if (k == 0) { - if ((key + 1)->flag & PEK_SELECT) + if ((key + 1)->flag & PEK_SELECT) { key->flag |= PEK_TAG; + } } else if (k == point->totkey - 1) { - if ((key - 1)->flag & PEK_SELECT) + if ((key - 1)->flag & PEK_SELECT) { key->flag |= PEK_TAG; + } } else { - if (((key - 1)->flag | (key + 1)->flag) & PEK_SELECT) + if (((key - 1)->flag | (key + 1)->flag) & PEK_SELECT) { key->flag |= PEK_TAG; + } } } @@ -2532,22 +2611,25 @@ static void rekey_particle(PEData *data, int pa_index) } /* replace keys */ - if (pa->hair) + if (pa->hair) { MEM_freeN(pa->hair); + } pa->hair = new_keys; point->totkey = pa->totkey = data->totrekey; - if (point->keys) + if (point->keys) { MEM_freeN(point->keys); + } ekey = point->keys = MEM_callocN(pa->totkey * sizeof(PTCacheEditKey), "Hair re-key edit keys"); for (k = 0, key = pa->hair; k < pa->totkey; k++, key++, ekey++) { ekey->co = key->co; ekey->time = &key->time; ekey->flag |= PEK_SELECT; - if (!(psys->flag & PSYS_GLOBAL_HAIR)) + if (!(psys->flag & PSYS_GLOBAL_HAIR)) { ekey->flag |= PEK_USE_WCO; + } } pa->flag &= ~PARS_REKEY; @@ -2603,8 +2685,9 @@ static void rekey_particle_to_time( PTCacheEditKey *ekey; int k; - if (!edit || !edit->psys) + if (!edit || !edit->psys) { return; + } psys = edit->psys; @@ -2627,8 +2710,9 @@ static void rekey_particle_to_time( } /* replace hair keys */ - if (pa->hair) + if (pa->hair) { MEM_freeN(pa->hair); + } pa->hair = new_keys; /* update edit pointers */ @@ -2676,10 +2760,12 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror) if (ELEM(NULL, new_pars, new_points)) { /* allocation error! */ - if (new_pars) + if (new_pars) { MEM_freeN(new_pars); - if (new_points) + } + if (new_points) { MEM_freeN(new_points); + } return 0; } } @@ -2688,10 +2774,12 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror) point = edit->points; for (i = 0; i < psys->totpart; i++, pa++, point++) { if (point->flag & PEP_TAG) { - if (point->keys) + if (point->keys) { MEM_freeN(point->keys); - if (pa->hair) + } + if (pa->hair) { MEM_freeN(pa->hair); + } } else { memcpy(npa, pa, sizeof(ParticleData)); @@ -2701,12 +2789,14 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror) } } - if (psys->particles) + if (psys->particles) { MEM_freeN(psys->particles); + } psys->particles = new_pars; - if (edit->points) + if (edit->points) { MEM_freeN(edit->points); + } edit->points = new_points; if (edit->mirror_cache) { @@ -2726,7 +2816,7 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror) return removed; } -static void remove_tagged_keys(Object *ob, ParticleSystem *psys) +static void remove_tagged_keys(Depsgraph *depsgraph, Object *ob, ParticleSystem *psys) { PTCacheEdit *edit = psys->edit; ParticleData *pa; @@ -2734,12 +2824,13 @@ static void remove_tagged_keys(Object *ob, ParticleSystem *psys) POINT_P; KEY_K; PTCacheEditKey *nkey, *new_keys; - ParticleSystemModifierData *psmd_eval; short new_totkey; if (pe_x_mirror(ob)) { /* mirror key tags */ - psmd_eval = psys_get_modifier(ob, psys); + ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); + ParticleSystemModifierData *psmd_eval = (ParticleSystemModifierData *)modifier_get_evaluated( + depsgraph, ob, &psmd->modifier); LOOP_POINTS { @@ -2759,8 +2850,9 @@ static void remove_tagged_keys(Object *ob, ParticleSystem *psys) new_totkey--; } /* we can't have elements with less than two keys*/ - if (new_totkey < 2) + if (new_totkey < 2) { point->flag |= PEP_TAG; + } } remove_tagged_particles(ob, psys, pe_x_mirror(ob)); @@ -2805,11 +2897,13 @@ static void remove_tagged_keys(Object *ob, ParticleSystem *psys) hkey++; } - if (pa->hair) + if (pa->hair) { MEM_freeN(pa->hair); + } - if (point->keys) + if (point->keys) { MEM_freeN(point->keys); + } pa->hair = new_hkeys; point->keys = new_keys; @@ -2846,12 +2940,14 @@ static void subdivide_particle(PEData *data, int pa_index) sim.psys = edit->psys; for (k = 0, ekey = point->keys; k < pa->totkey - 1; k++, ekey++) { - if (ekey->flag & PEK_SELECT && (ekey + 1)->flag & PEK_SELECT) + if (ekey->flag & PEK_SELECT && (ekey + 1)->flag & PEK_SELECT) { totnewkey++; + } } - if (totnewkey == 0) + if (totnewkey == 0) { return; + } pa->flag |= PARS_REKEY; @@ -2883,8 +2979,9 @@ static void subdivide_particle(PEData *data, int pa_index) nekey->co = nkey->co; nekey->time = &nkey->time; nekey->flag |= PEK_SELECT; - if (!(psys->flag & PSYS_GLOBAL_HAIR)) + if (!(psys->flag & PSYS_GLOBAL_HAIR)) { nekey->flag |= PEK_USE_WCO; + } nekey++; nkey++; @@ -2897,12 +2994,14 @@ static void subdivide_particle(PEData *data, int pa_index) nekey->co = nkey->co; nekey->time = &nkey->time; - if (pa->hair) + if (pa->hair) { MEM_freeN(pa->hair); + } pa->hair = new_keys; - if (point->keys) + if (point->keys) { MEM_freeN(point->keys); + } point->keys = new_ekeys; point->totkey = pa->totkey = pa->totkey + totnewkey; @@ -2956,8 +3055,9 @@ static int remove_doubles_exec(bContext *C, wmOperator *op) float mat[4][4], co[3], threshold = RNA_float_get(op->ptr, "threshold"); int n, totn, removed, totremoved; - if (psys->flag & PSYS_GLOBAL_HAIR) + if (psys->flag & PSYS_GLOBAL_HAIR) { return OPERATOR_CANCELLED; + } edit = psys->edit; psmd_eval = edit->psmd_eval; @@ -3008,8 +3108,9 @@ static int remove_doubles_exec(bContext *C, wmOperator *op) totremoved += removed; } while (removed); - if (totremoved == 0) + if (totremoved == 0) { return OPERATOR_CANCELLED; + } BKE_reportf(op->reports, RPT_INFO, "Removed %d double particles", totremoved); @@ -3144,9 +3245,10 @@ static void toggle_particle_cursor(bContext *C, int enable) WM_paint_cursor_end(CTX_wm_manager(C), pset->paintcursor); pset->paintcursor = NULL; } - else if (enable) + else if (enable) { pset->paintcursor = WM_paint_cursor_activate( CTX_wm_manager(C), SPACE_VIEW3D, RGN_TYPE_WINDOW, PE_poll_view3d, brush_drawcursor, NULL); + } } /*************************** delete operator **************************/ @@ -3185,7 +3287,7 @@ static int delete_exec(bContext *C, wmOperator *op) if (type == DEL_KEY) { foreach_selected_key(&data, set_delete_particle_key); - remove_tagged_keys(data.ob, data.edit->psys); + remove_tagged_keys(data.depsgraph, data.ob, data.edit->psys); recalc_lengths(data.edit); } else if (type == DEL_PARTICLE) { @@ -3240,12 +3342,14 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged) int *mirrorfaces = NULL; int rotation, totpart, newtotpart; - if (psys->flag & PSYS_GLOBAL_HAIR) + if (psys->flag & PSYS_GLOBAL_HAIR) { return; + } psmd_eval = edit->psmd_eval; - if (!psmd_eval->mesh_final) + if (!psmd_eval->mesh_final) { return; + } const bool use_dm_final_indices = (psys->part->use_modifier_stack && !psmd_eval->mesh_final->runtime.deformed_only); @@ -3253,13 +3357,14 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged) /* NOTE: this is not nice to use tessfaces but hard to avoid since pa->num uses tessfaces */ BKE_mesh_tessface_ensure(me); - /* Note: In case psys uses Mesh tessface indices, we mirror final Mesh itself, not orig mesh. Avoids an (impossible) - * mesh -> orig -> mesh tessface indices conversion... */ + /* NOTE: In case psys uses Mesh tessface indices, we mirror final Mesh itself, not orig mesh. + * Avoids an (impossible) mesh -> orig -> mesh tessface indices conversion. */ mirrorfaces = mesh_get_x_mirror_faces( ob, NULL, use_dm_final_indices ? psmd_eval->mesh_final : NULL); - if (!edit->mirror_cache) + if (!edit->mirror_cache) { PE_update_mirror_cache(ob, psys); + } totpart = psys->totpart; newtotpart = psys->totpart; @@ -3274,13 +3379,15 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged) PE_mirror_particle(ob, psmd_eval->mesh_final, psys, pa, NULL); continue; } - else + else { point->flag |= PEP_TAG; + } } } - if ((point->flag & PEP_TAG) && mirrorfaces[pa->num * 2] != -1) + if ((point->flag & PEP_TAG) && mirrorfaces[pa->num * 2] != -1) { newtotpart++; + } } if (newtotpart != psys->totpart) { @@ -3317,19 +3424,23 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged) pa = psys->particles + p; const int pa_num = pa->num; - if (point->flag & PEP_HIDE) + if (point->flag & PEP_HIDE) { continue; + } - if (!(point->flag & PEP_TAG) || mirrorfaces[pa_num * 2] == -1) + if (!(point->flag & PEP_TAG) || mirrorfaces[pa_num * 2] == -1) { continue; + } /* duplicate */ *newpa = *pa; *newpoint = *point; - if (pa->hair) + if (pa->hair) { newpa->hair = MEM_dupallocN(pa->hair); - if (point->keys) + } + if (point->keys) { newpoint->keys = MEM_dupallocN(point->keys); + } /* rotate weights according to vertex index rotation */ rotation = mirrorfaces[pa_num * 2 + 1]; @@ -3347,7 +3458,8 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged) } /* assign face index */ - /* NOTE: mesh_get_x_mirror_faces generates -1 for non-found mirror, same as DMCACHE_NOTFOUND... */ + /* NOTE: mesh_get_x_mirror_faces generates -1 for non-found mirror, + * same as DMCACHE_NOTFOUND. */ newpa->num = mirrorfaces[pa_num * 2]; if (use_dm_final_indices) { @@ -3424,8 +3536,9 @@ static void brush_comb(PEData *data, ParticleEditSettings *pset = PE_settings(data->scene); float cvec[3], fac; - if (pset->flag & PE_LOCK_FIRST && key_index == 0) + if (pset->flag & PE_LOCK_FIRST && key_index == 0) { return; + } fac = (float)pow((double)(1.0f - mouse_distance / data->rad), (double)data->combfac); @@ -3456,12 +3569,14 @@ static void brush_cut(PEData *data, int pa_index) } /* don't cut hidden */ - if (edit->points[pa_index].flag & PEP_HIDE) + if (edit->points[pa_index].flag & PEP_HIDE) { return; + } if (ED_view3d_project_int_global(ar, key->co, screen_co, V3D_PROJ_TEST_CLIP_NEAR) != - V3D_PROJ_RET_OK) + V3D_PROJ_RET_OK) { return; + } rad2 = data->rad * data->rad; @@ -3612,8 +3727,9 @@ static void brush_puff(PEData *data, int point_index, float mouse_distance) mul_v3_m4v3(kco, data->ob->imat, co); point_index = BLI_kdtree_3d_find_nearest(edit->emitter_field, kco, NULL); - if (point_index == -1) + if (point_index == -1) { return; + } copy_v3_v3(co_root, co); copy_v3_v3(no_root, &edit->emitter_cosnos[point_index * 6 + 3]); @@ -3628,8 +3744,9 @@ static void brush_puff(PEData *data, int point_index, float mouse_distance) fac = (float)pow((double)(1.0f - mouse_distance / data->rad), (double)data->pufffac); fac *= 0.025f; - if (data->invert) + if (data->invert) { fac = -fac; + } } else { /* compute position as if hair was standing up straight. @@ -3725,8 +3842,9 @@ static void brush_puff(PEData *data, int point_index, float mouse_distance) } } - if (changed) + if (changed) { point->flag |= PEP_EDIT_RECALC; + } } static void BKE_brush_weight_get(PEData *data, @@ -3873,15 +3991,17 @@ static int particle_intersect_mesh(Depsgraph *depsgraph, copy_v3_v3(v1, vert_cos + 3 * mface->v1); copy_v3_v3(v2, vert_cos + 3 * mface->v2); copy_v3_v3(v3, vert_cos + 3 * mface->v3); - if (mface->v4) + if (mface->v4) { copy_v3_v3(v4, vert_cos + 3 * mface->v4); + } } else { copy_v3_v3(v1, mvert[mface->v1].co); copy_v3_v3(v2, mvert[mface->v2].co); copy_v3_v3(v3, mvert[mface->v3].co); - if (mface->v4) + if (mface->v4) { copy_v3_v3(v4, mvert[mface->v4].co); + } } if (face_minmax == 0) { @@ -3889,16 +4009,19 @@ static int particle_intersect_mesh(Depsgraph *depsgraph, DO_MINMAX(v1, min, max); DO_MINMAX(v2, min, max); DO_MINMAX(v3, min, max); - if (mface->v4) + if (mface->v4) { DO_MINMAX(v4, min, max); - if (isect_aabb_aabb_v3(min, max, p_min, p_max) == 0) + } + if (isect_aabb_aabb_v3(min, max, p_min, p_max) == 0) { continue; + } } else { copy_v3_v3(min, face_minmax + 6 * i); copy_v3_v3(max, face_minmax + 6 * i + 3); - if (isect_aabb_aabb_v3(min, max, p_min, p_max) == 0) + if (isect_aabb_aabb_v3(min, max, p_min, p_max) == 0) { continue; + } } if (radius > 0.0f) { @@ -3929,8 +4052,9 @@ static int particle_intersect_mesh(Depsgraph *depsgraph, min_w[1] = cur_uv[0]; min_w[2] = cur_uv[1]; min_w[3] = 0.0f; - if (mface->v4) + if (mface->v4) { intersect_dm_quad_weights(v1, v2, v3, v4, min_w); + } *min_face = i; intersect = 1; } @@ -4038,7 +4162,8 @@ static void brush_add_count_iter(void *__restrict iter_data_v, add_pars[iter].num_dmcache = DMCACHE_ISCHILD; } else if (iter_data->mesh == psmd_eval->mesh_original) { - /* Final DM is not same topology as orig mesh, we have to map num_dmcache to real final dm. */ + /* Final DM is not same topology as orig mesh, + * we have to map num_dmcache to real final dm. */ add_pars[iter].num = add_pars[iter].num_dmcache; add_pars[iter].num_dmcache = psys_particle_dm_face_lookup(psmd_eval->mesh_final, psmd_eval->mesh_original, @@ -4086,8 +4211,9 @@ static int brush_add(const bContext *C, PEData *data, short number) invert_m4_m4(imat, ob->obmat); - if (psys->flag & PSYS_GLOBAL_HAIR) + if (psys->flag & PSYS_GLOBAL_HAIR) { return 0; + } add_pars = MEM_callocN(number * sizeof(ParticleData), "ParticleData add"); @@ -4169,12 +4295,14 @@ static int brush_add(const bContext *C, PEData *data, short number) memcpy(new_points, edit->points, totpart * sizeof(PTCacheEditPoint)); /* change old arrays to new ones */ - if (psys->particles) + if (psys->particles) { MEM_freeN(psys->particles); + } psys->particles = new_pars; - if (edit->points) + if (edit->points) { MEM_freeN(edit->points); + } edit->points = new_points; if (edit->mirror_cache) { @@ -4221,16 +4349,18 @@ static int brush_add(const bContext *C, PEData *data, short number) key->co = hkey->co; key->time = &hkey->time; - if (!(psys->flag & PSYS_GLOBAL_HAIR)) + if (!(psys->flag & PSYS_GLOBAL_HAIR)) { key->flag |= PEK_USE_WCO; + } } pa->size = 1.0f; initialize_particle(&sim, pa); reset_particle(&sim, pa, 0.0, 1.0); point->flag |= PEP_EDIT_RECALC; - if (pe_x_mirror(ob)) + if (pe_x_mirror(ob)) { point->flag |= PEP_TAG; /* signal for duplicate */ + } framestep = pa->lifetime / (float)(pset->totaddkey - 1); @@ -4266,12 +4396,14 @@ static int brush_add(const bContext *C, PEData *data, short number) } if (totw > 0.0f) { - for (w = 0; w < maxw; w++) + for (w = 0; w < maxw; w++) { weight[w] /= totw; + } } else { - for (w = 0; w < maxw; w++) + for (w = 0; w < maxw; w++) { weight[w] = 1.0f / maxw; + } } ppa = psys->particles + ptn[0].index; @@ -4301,8 +4433,9 @@ static int brush_add(const bContext *C, PEData *data, short number) } } - if (k == 0) + if (k == 0) { sub_v3_v3v3(co1, pa->state.co, key3[0].co); + } add_v3_v3v3(thkey->co, key3[0].co, co1); @@ -4323,8 +4456,9 @@ static int brush_add(const bContext *C, PEData *data, short number) } } - if (tree) + if (tree) { BLI_kdtree_3d_free(tree); + } } MEM_freeN(add_pars); @@ -4404,8 +4538,9 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) float dx, dy, dmax; int lock_root = pset->flag & PE_LOCK_FIRST; - if (!PE_start_edit(edit)) + if (!PE_start_edit(edit)) { return; + } RNA_float_get_array(itemptr, "mouse", mousef); mouse[0] = mousef[0]; @@ -4424,8 +4559,9 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) mval[1] = mouse[1]; /* disable locking temporatily for disconnected hair */ - if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR) + if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR) { pset->flag &= ~PE_LOCK_FIRST; + } if (((pset->brushtype == PE_BRUSH_ADD) ? (sqrtf(dx * dx + dy * dy) > pset->brush[PE_BRUSH_ADD].step) : @@ -4454,10 +4590,12 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) data.rad = pe_brush_size_get(scene, brush); data.combfac = (brush->strength - 0.5f) * 2.0f; - if (data.combfac < 0.0f) + if (data.combfac < 0.0f) { data.combfac = 1.0f - 9.0f * data.combfac; - else + } + else { data.combfac = 1.0f - data.combfac; + } invert_m4_m4(ob->imat, ob->obmat); @@ -4473,17 +4611,21 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) data.rad = pe_brush_size_get(scene, brush); data.cutfac = brush->strength; - if (selected) + if (selected) { foreach_selected_point(&data, brush_cut); - else + } + else { foreach_point(&data, brush_cut); + } removed = remove_tagged_particles(ob, edit->psys, pe_x_mirror(ob)); - if (pset->flag & PE_KEEP_LENGTHS) + if (pset->flag & PE_KEEP_LENGTHS) { recalc_lengths(edit); + } } - else + else { removed = 0; + } break; } @@ -4493,15 +4635,18 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) data.rad = pe_brush_size_get(scene, brush); data.growfac = brush->strength / 50.0f; - if (brush->invert ^ flip) + if (brush->invert ^ flip) { data.growfac = 1.0f - data.growfac; - else + } + else { data.growfac = 1.0f + data.growfac; + } foreach_mouse_hit_point(&data, brush_length, selected); - if (pset->flag & PE_KEEP_LENGTHS) + if (pset->flag & PE_KEEP_LENGTHS) { recalc_lengths(edit); + } break; } case PE_BRUSH_PUFF: { @@ -4512,10 +4657,12 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) data.select = selected; data.pufffac = (brush->strength - 0.5f) * 2.0f; - if (data.pufffac < 0.0f) + if (data.pufffac < 0.0f) { data.pufffac = 1.0f - 9.0f * data.pufffac; - else + } + else { data.pufffac = 1.0f - data.pufffac; + } data.invert = (brush->invert ^ flip); invert_m4_m4(ob->imat, ob->obmat); @@ -4530,11 +4677,13 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) added = brush_add(C, &data, brush->count); - if (pset->flag & PE_KEEP_LENGTHS) + if (pset->flag & PE_KEEP_LENGTHS) { recalc_lengths(edit); + } } - else + else { added = 0; + } break; } case PE_BRUSH_SMOOTH: { @@ -4571,12 +4720,14 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) break; } } - if ((pset->flag & PE_KEEP_LENGTHS) == 0) + if ((pset->flag & PE_KEEP_LENGTHS) == 0) { recalc_lengths(edit); + } if (ELEM(pset->brushtype, PE_BRUSH_ADD, PE_BRUSH_CUT) && (added || removed)) { - if (pset->brushtype == PE_BRUSH_ADD && pe_x_mirror(ob)) + if (pset->brushtype == PE_BRUSH_ADD && pe_x_mirror(ob)) { PE_mirror_x(scene, ob, 1); + } update_world_cos(depsgraph, ob, edit); psys_free_path_cache(NULL, edit); @@ -4615,8 +4766,9 @@ static void brush_edit_exit(wmOperator *op) static int brush_edit_exec(bContext *C, wmOperator *op) { - if (!brush_edit_init(C, op)) + if (!brush_edit_init(C, op)) { return OPERATOR_CANCELLED; + } RNA_BEGIN (op->ptr, itemptr, "stroke") { brush_edit_apply(C, op, &itemptr); @@ -4647,8 +4799,9 @@ static void brush_edit_apply_event(bContext *C, wmOperator *op, const wmEvent *e static int brush_edit_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - if (!brush_edit_init(C, op)) + if (!brush_edit_init(C, op)) { return OPERATOR_CANCELLED; + } brush_edit_apply_event(C, op, event); @@ -4734,8 +4887,9 @@ static void point_inside_bvh_cb(void *userdata, data->bvhdata.raycast_callback(&data->bvhdata, index, ray, hit); - if (hit->index != -1) + if (hit->index != -1) { ++data->num_hits; + } } /* true if the point is inside the shape mesh */ @@ -4767,8 +4921,9 @@ static void shape_cut(PEData *data, int pa_index) int k, totkeys = 1 << pset->draw_step; /* don't cut hidden */ - if (edit->points[pa_index].flag & PEP_HIDE) + if (edit->points[pa_index].flag & PEP_HIDE) { return; + } cut = false; @@ -4829,12 +4984,14 @@ static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op)) int selected = count_selected_keys(scene, edit); int lock_root = pset->flag & PE_LOCK_FIRST; - if (!PE_start_edit(edit)) + if (!PE_start_edit(edit)) { return OPERATOR_CANCELLED; + } /* disable locking temporatily for disconnected hair */ - if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR) + if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR) { pset->flag &= ~PE_LOCK_FIRST; + } if (edit->psys && edit->pathcache) { PEData data; @@ -4846,10 +5003,12 @@ static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; } - if (selected) + if (selected) { foreach_selected_point(&data, shape_cut); - else + } + else { foreach_point(&data, shape_cut); + } removed = remove_tagged_particles(ob, edit->psys, pe_x_mirror(ob)); recalc_lengths(edit); @@ -4909,19 +5068,23 @@ int PE_minmax(Scene *scene, ViewLayer *view_layer, float min[3], float max[3]) float co[3], mat[4][4]; int ok = 0; - if (!edit) + if (!edit) { return ok; + } - if ((psys = edit->psys)) + if ((psys = edit->psys)) { psmd_eval = edit->psmd_eval; - else + } + else { unit_m4(mat); + } LOOP_VISIBLE_POINTS { - if (psys) + if (psys) { psys_mat_hair_to_global( ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, mat); + } LOOP_SELECTED_KEYS { @@ -4961,14 +5124,17 @@ void PE_create_particle_edit( } /* no psmd->dm happens in case particle system modifier is not enabled */ - if (!(psys && psmd && psmd_eval->mesh_final) && !cache) + if (!(psys && psmd && psmd_eval->mesh_final) && !cache) { return; + } - if (cache && cache->flag & PTCACHE_DISK_CACHE) + if (cache && cache->flag & PTCACHE_DISK_CACHE) { return; + } - if (psys == NULL && (cache && BLI_listbase_is_empty(&cache->mem_cache))) + if (psys == NULL && (cache && BLI_listbase_is_empty(&cache->mem_cache))) { return; + } edit = (psys) ? psys->edit : cache->edit; @@ -5029,21 +5195,24 @@ void PE_create_particle_edit( cache->free_edit = PE_free_ptcache_edit; edit->psys = NULL; - for (pm = cache->mem_cache.first; pm; pm = pm->next) + for (pm = cache->mem_cache.first; pm; pm = pm->next) { totframe++; + } for (pm = cache->mem_cache.first; pm; pm = pm->next) { LOOP_POINTS { - if (BKE_ptcache_mem_pointers_seek(p, pm) == 0) + if (BKE_ptcache_mem_pointers_seek(p, pm) == 0) { continue; + } if (!point->totkey) { key = point->keys = MEM_callocN(totframe * sizeof(PTCacheEditKey), "ParticleEditKeys"); point->flag |= PEP_EDIT_RECALC; } - else + else { key = point->keys + point->totkey; + } key->co = pm->cur[BPHYS_DATA_LOCATION]; key->vel = pm->cur[BPHYS_DATA_VELOCITY]; @@ -5067,8 +5236,9 @@ void PE_create_particle_edit( memset(edit->nosel_col, 0x00, sizeof(edit->nosel_col)); #endif recalc_lengths(edit); - if (psys && !cache) + if (psys && !cache) { recalc_emitter_field(depsgraph, ob, psys); + } PE_update_object(depsgraph, scene, ob, 1); } @@ -5078,12 +5248,15 @@ static bool particle_edit_toggle_poll(bContext *C) { Object *ob = CTX_data_active_object(C); - if (ob == NULL || ob->type != OB_MESH) + if (ob == NULL || ob->type != OB_MESH) { return 0; - if (!ob->data || ID_IS_LINKED(ob->data)) + } + if (!ob->data || ID_IS_LINKED(ob->data)) { return 0; - if (CTX_data_edit_object(C)) + } + if (CTX_data_edit_object(C)) { return 0; + } return (ob->particlesystem.first || modifiers_findByType(ob, eModifierType_Cloth) || modifiers_findByType(ob, eModifierType_Softbody)); diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index 92eed9be2f5..b03ec56c7e4 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -69,10 +69,12 @@ #include "physics_intern.h" -static float I[4][4] = {{1.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 1.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 1.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 1.0f}}; +static float I[4][4] = { + {1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 1.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 1.0f}, +}; /********************** particle system slot operators *********************/ @@ -82,8 +84,9 @@ static int particle_system_add_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_object_context(C); Scene *scene = CTX_data_scene(C); - if (!scene || !ob) + if (!scene || !ob) { return OPERATOR_CANCELLED; + } object_add_particle_system(bmain, scene, ob, NULL); @@ -116,8 +119,9 @@ static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op)) ViewLayer *view_layer = CTX_data_view_layer(C); int mode_orig; - if (!scene || !ob) + if (!scene || !ob) { return OPERATOR_CANCELLED; + } mode_orig = ob->mode; object_remove_particle_system(bmain, scene, ob); @@ -175,15 +179,18 @@ static int new_particle_settings_exec(bContext *C, wmOperator *UNUSED(op)) psys = ptr.data; /* add or copy particle setting */ - if (psys->part) + if (psys->part) { part = BKE_particlesettings_copy(bmain, psys->part); - else + } + else { part = BKE_particlesettings_add(bmain, "ParticleSettings"); + } ob = ptr.id.data; - if (psys->part) + if (psys->part) { id_us_min(&psys->part->id); + } psys->part = part; @@ -223,12 +230,14 @@ static int new_particle_target_exec(bContext *C, wmOperator *UNUSED(op)) ParticleTarget *pt; - if (!psys) + if (!psys) { return OPERATOR_CANCELLED; + } pt = psys->targets.first; - for (; pt; pt = pt->next) + for (; pt; pt = pt->next) { pt->flag &= ~PTARGET_CURRENT; + } pt = MEM_callocN(sizeof(ParticleTarget), "keyed particle target"); @@ -268,8 +277,9 @@ static int remove_particle_target_exec(bContext *C, wmOperator *UNUSED(op)) ParticleTarget *pt; - if (!psys) + if (!psys) { return OPERATOR_CANCELLED; + } pt = psys->targets.first; for (; pt; pt = pt->next) { @@ -281,8 +291,9 @@ static int remove_particle_target_exec(bContext *C, wmOperator *UNUSED(op)) } pt = psys->targets.last; - if (pt) + if (pt) { pt->flag |= PTARGET_CURRENT; + } DEG_relations_tag_update(bmain); DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); @@ -315,8 +326,9 @@ static int target_move_up_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ptr.id.data; ParticleTarget *pt; - if (!psys) + if (!psys) { return OPERATOR_CANCELLED; + } pt = psys->targets.first; for (; pt; pt = pt->next) { @@ -354,8 +366,9 @@ static int target_move_down_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ptr.id.data; ParticleTarget *pt; - if (!psys) + if (!psys) { return OPERATOR_CANCELLED; + } pt = psys->targets.first; for (; pt; pt = pt->next) { if (pt->flag & PTARGET_CURRENT && pt->next) { @@ -390,8 +403,9 @@ static int dupliob_refresh_exec(bContext *C, wmOperator *UNUSED(op)) PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); ParticleSystem *psys = ptr.data; - if (!psys) + if (!psys) { return OPERATOR_CANCELLED; + } psys_check_group_weights(psys->part); DEG_id_tag_update(&psys->part->id, ID_RECALC_GEOMETRY | ID_RECALC_PSYS_REDO); @@ -421,8 +435,9 @@ static int dupliob_move_up_exec(bContext *C, wmOperator *UNUSED(op)) ParticleSettings *part; ParticleDupliWeight *dw; - if (!psys) + if (!psys) { return OPERATOR_CANCELLED; + } part = psys->part; for (dw = part->instance_weights.first; dw; dw = dw->next) { @@ -460,8 +475,9 @@ static int copy_particle_dupliob_exec(bContext *C, wmOperator *UNUSED(op)) ParticleSettings *part; ParticleDupliWeight *dw; - if (!psys) + if (!psys) { return OPERATOR_CANCELLED; + } part = psys->part; for (dw = part->instance_weights.first; dw; dw = dw->next) { if (dw->flag & PART_DUPLIW_CURRENT) { @@ -500,8 +516,9 @@ static int remove_particle_dupliob_exec(bContext *C, wmOperator *UNUSED(op)) ParticleSettings *part; ParticleDupliWeight *dw; - if (!psys) + if (!psys) { return OPERATOR_CANCELLED; + } part = psys->part; for (dw = part->instance_weights.first; dw; dw = dw->next) { @@ -513,8 +530,9 @@ static int remove_particle_dupliob_exec(bContext *C, wmOperator *UNUSED(op)) } dw = part->instance_weights.last; - if (dw) + if (dw) { dw->flag |= PART_DUPLIW_CURRENT; + } DEG_id_tag_update(&part->id, ID_RECALC_GEOMETRY | ID_RECALC_PSYS_REDO); WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, NULL); @@ -545,8 +563,9 @@ static int dupliob_move_down_exec(bContext *C, wmOperator *UNUSED(op)) ParticleSettings *part; ParticleDupliWeight *dw; - if (!psys) + if (!psys) { return OPERATOR_CANCELLED; + } part = psys->part; for (dw = part->instance_weights.first; dw; dw = dw->next) { @@ -591,11 +610,13 @@ static void disconnect_hair(Depsgraph *depsgraph, Scene *scene, Object *ob, Part int i, k; float hairmat[4][4]; - if (!ob || !psys || psys->flag & PSYS_GLOBAL_HAIR) + if (!ob || !psys || psys->flag & PSYS_GLOBAL_HAIR) { return; + } - if (!psys->part || psys->part->type != PART_HAIR) + if (!psys->part || psys->part->type != PART_HAIR) { return; + } edit = psys->edit; point = edit ? edit->points : NULL; @@ -637,8 +658,9 @@ static int disconnect_hair_exec(bContext *C, wmOperator *op) ParticleSystem *psys = NULL; const bool all = RNA_boolean_get(op->ptr, "all"); - if (!ob) + if (!ob) { return OPERATOR_CANCELLED; + } if (all) { for (psys = ob->particlesystem.first; psys; psys = psys->next) { @@ -703,12 +725,15 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, float from_ob_imat[4][4], to_ob_imat[4][4]; float from_imat[4][4], to_imat[4][4]; - if (!target_psmd->mesh_final) + if (!target_psmd->mesh_final) { return false; - if (!psys->part || psys->part->type != PART_HAIR) + } + if (!psys->part || psys->part->type != PART_HAIR) { return false; - if (!target_psys->part || target_psys->part->type != PART_HAIR) + } + if (!target_psys->part || target_psys->part->type != PART_HAIR) { return false; + } edit_point = target_edit ? target_edit->points : NULL; @@ -738,8 +763,9 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, mvert = mesh->mvert; /* convert to global coordinates */ - for (i = 0; i < numverts; i++) + for (i = 0; i < numverts; i++) { mul_m4_v3(to_mat, mvert[i].co); + } if (mesh->totface != 0) { mface = mesh->mface; @@ -759,10 +785,12 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, float from_co[3]; BVHTreeNearest nearest; - if (from_global) + if (from_global) { mul_v3_m4v3(from_co, from_ob_imat, pa->hair[0].co); - else + } + else { mul_v3_m4v3(from_co, from_ob_imat, pa->hair[0].world_co); + } mul_m4_v3(from_mat, from_co); nearest.index = -1; @@ -771,8 +799,9 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, BLI_bvhtree_find_nearest(bvhtree.tree, from_co, &nearest, bvhtree.nearest_callback, &bvhtree); if (nearest.index == -1) { - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("No nearest point found for hair root!"); + } continue; } @@ -788,8 +817,9 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, copy_v3_v3(v[3], mvert[mf->v4].co); interp_weights_poly_v3(tpa->fuv, v, 4, nearest.co); } - else + else { interp_weights_poly_v3(tpa->fuv, v, 3, nearest.co); + } tpa->foffset = 0.0f; tpa->num = nearest.index; @@ -813,8 +843,9 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, float hairmat[4][4], imat[4][4]; float offset[3]; - if (to_global) + if (to_global) { copy_m4_m4(imat, target_ob->obmat); + } else { /* note: using target_dm here, which is in target_ob object space and has full modifiers */ psys_mat_hair_to_object(target_ob, target_mesh, target_psys->part->from, tpa, hairmat); @@ -830,10 +861,12 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, k++, key++, tkey++, ekey++) { float co_orig[3]; - if (from_global) + if (from_global) { mul_v3_m4v3(co_orig, from_ob_imat, key->co); - else + } + else { mul_v3_m4v3(co_orig, from_ob_imat, key->world_co); + } mul_m4_v3(from_mat, co_orig); add_v3_v3v3(tkey->co, co_orig, offset); @@ -849,10 +882,12 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, for (k = 0, key = pa->hair, tkey = tpa->hair; k < tpa->totkey; k++, key++, tkey++) { float co_orig[3]; - if (from_global) + if (from_global) { mul_v3_m4v3(co_orig, from_ob_imat, key->co); - else + } + else { mul_v3_m4v3(co_orig, from_ob_imat, key->world_co); + } mul_m4_v3(from_mat, co_orig); add_v3_v3v3(tkey->co, co_orig, offset); @@ -877,8 +912,9 @@ static bool connect_hair(Depsgraph *depsgraph, Scene *scene, Object *ob, Particl { bool ok; - if (!psys) + if (!psys) { return false; + } ok = remap_hair_emitter(depsgraph, scene, @@ -905,8 +941,9 @@ static int connect_hair_exec(bContext *C, wmOperator *op) const bool all = RNA_boolean_get(op->ptr, "all"); bool any_connected = false; - if (!ob) + if (!ob) { return OPERATOR_CANCELLED; + } if (all) { for (psys = ob->particlesystem.first; psys; psys = psys->next) { @@ -964,8 +1001,9 @@ static void copy_particle_edit(Depsgraph *depsgraph, KEY_K; POINT_P; - if (!edit_from) + if (!edit_from) { return; + } edit = MEM_dupallocN(edit_from); edit->psys = psys; @@ -1013,10 +1051,12 @@ static void remove_particle_systems_from_object(Object *ob_to) { ModifierData *md, *md_next; - if (ob_to->type != OB_MESH) + if (ob_to->type != OB_MESH) { return; - if (!ob_to->data || ID_IS_LINKED(ob_to->data)) + } + if (!ob_to->data || ID_IS_LINKED(ob_to->data)) { return; + } for (md = ob_to->modifiers.first; md; md = md_next) { md_next = md->next; @@ -1054,19 +1094,23 @@ static bool copy_particle_systems_to_object(const bContext *C, CustomData_MeshMasks cdmask = {0}; int i, totpsys; - if (ob_to->type != OB_MESH) + if (ob_to->type != OB_MESH) { return false; - if (!ob_to->data || ID_IS_LINKED(ob_to->data)) + } + if (!ob_to->data || ID_IS_LINKED(ob_to->data)) { return false; + } /* For remapping we need a valid DM. - * Because the modifiers are appended at the end it's safe to use - * the final DM of the object without particles. - * However, when evaluating the DM all the particle modifiers must be valid, - * i.e. have the psys assigned already. - * To break this hen/egg problem we create all psys separately first (to collect required customdata masks), - * then create the DM, then add them to the object and make the psys modifiers ... - */ + * Because the modifiers are appended at the end it's safe to use + * the final DM of the object without particles. + * However, when evaluating the DM all the particle modifiers must be valid, + * i.e. have the psys assigned already. + * + * To break this hen/egg problem we create all psys separately first + * (to collect required customdata masks), + * then create the DM, then add them to the object and make the psys modifiers. + */ #define PSYS_FROM_FIRST (single_psys_from ? single_psys_from : ob_from->particlesystem.first) #define PSYS_FROM_NEXT(cur) (single_psys_from ? NULL : (cur)->next) totpsys = single_psys_from ? 1 : BLI_listbase_count(&ob_from->particlesystem); @@ -1077,8 +1121,9 @@ static bool copy_particle_systems_to_object(const bContext *C, psys = BKE_object_copy_particlesystem(psys_from, 0); tmp_psys[i] = psys; - if (psys_start == NULL) + if (psys_start == NULL) { psys_start = psys; + } psys_emitter_customdata_mask(psys, &cdmask); } @@ -1177,12 +1222,14 @@ static bool copy_particle_systems_to_object(const bContext *C, static bool copy_particle_systems_poll(bContext *C) { Object *ob; - if (!ED_operator_object_active_editable(C)) + if (!ED_operator_object_active_editable(C)) { return false; + } ob = ED_object_active_context(C); - if (BLI_listbase_is_empty(&ob->particlesystem)) + if (BLI_listbase_is_empty(&ob->particlesystem)) { return false; + } return true; } @@ -1208,13 +1255,16 @@ static int copy_particle_systems_exec(bContext *C, wmOperator *op) remove_particle_systems_from_object(ob_to); changed = true; } - if (copy_particle_systems_to_object(C, scene, ob_from, psys_from, ob_to, space, false)) + if (copy_particle_systems_to_object(C, scene, ob_from, psys_from, ob_to, space, false)) { changed = true; - else + } + else { fail++; + } - if (changed) + if (changed) { changed_tot++; + } } } CTX_DATA_END; diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index 2769d1a9dc3..fd092eb4b78 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -80,8 +80,9 @@ static float get_fluid_rate(FluidsimSettings *settings) rate = settings->animRate; - if (rate < 0.0f) + if (rate < 0.0f) { rate = 0.0f; + } return rate; } @@ -185,16 +186,18 @@ static void fluidsimPrintChannel(FILE *file, float *channel, int paramsize, char } fprintf(file, " CHANNEL %s =\n", str); - for (i=0; i < channelSize; i++) { + for (i = 0; i < channelSize; i++) { fprintf(file, " "); - for (j=0;j <= entries;j++) { // also print time value - fprintf(file, " %f ", channel[i*(entries + 1) + j]); - if (j == entries-1) { fprintf(file, " "); } + for (j = 0; j <= entries; j++) { // also print time value + fprintf(file, " %f ", channel[i * (entries + 1) + j]); + if (j == entries - 1) { + fprintf(file, " "); + } } fprintf(file, "\n"); } - fprintf(file, " ;\n"); + fprintf(file, " ;\n"); } # endif @@ -255,8 +258,9 @@ static void set_vertex_channel(Depsgraph *depsgraph, int framesize = (3 * fobj->numVerts) + 1; int j; - if (channel == NULL) + if (channel == NULL) { return; + } initElbeemMesh(depsgraph, scene, ob, &numVerts, &verts, &numTris, &tris, 1, modifierIndex); @@ -279,8 +283,9 @@ static void set_vertex_channel(Depsgraph *depsgraph, static void free_domain_channels(FluidAnimChannels *channels) { - if (!channels->timeAtFrame) + if (!channels->timeAtFrame) { return; + } MEM_freeN(channels->timeAtFrame); channels->timeAtFrame = NULL; MEM_freeN(channels->DomainGravity); @@ -429,7 +434,8 @@ static void fluid_init_all_channels(bContext *C, /* now scene data should be current according to animation system, so we fill the channels */ /* Domain time */ - // TODO: have option for not running sim, time mangling, in which case second case comes in handy + /* TODO: have option for not running sim, time mangling, + * in which case second case comes in handy. */ if (channels->DomainTime) { time = get_fluid_rate(domainSettings) * (float)channels->aniFrameTime; timeAtFrame = channels->timeAtFrame[i] + time; @@ -455,8 +461,9 @@ static void fluid_init_all_channels(bContext *C, float active = (float)((fluidmd->fss->flag & OB_FLUIDSIM_ACTIVE) ? 1 : 0); float rot_d[3] = {0.f, 0.f, 0.f}, old_rot[3] = {0.f, 0.f, 0.f}; - if (ELEM(fluidmd->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE)) + if (ELEM(fluidmd->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE)) { continue; + } /* init euler rotation values and convert to elbeem format */ /* get the rotation from ob->obmat rather than ob->rot to account for parent animations */ @@ -524,8 +531,9 @@ static void export_fluid_objects(const bContext *C, ListBase *fobjects, Scene *s elbeemMesh fsmesh; - if (ELEM(fluidmd->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE)) + if (ELEM(fluidmd->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE)) { continue; + } elbeemResetMesh(&fsmesh); @@ -552,12 +560,15 @@ static void export_fluid_objects(const bContext *C, ListBase *fobjects, Scene *s fsmesh.localInivelCoords = ((fluidmd->fss->typeFlags & OB_FSINFLOW_LOCALCOORD) ? 1 : 0); } - if (fluidmd->fss->typeFlags & OB_FSBND_NOSLIP) + if (fluidmd->fss->typeFlags & OB_FSBND_NOSLIP) { fsmesh.obstacleType = FLUIDSIM_OBSTACLE_NOSLIP; - else if (fluidmd->fss->typeFlags & OB_FSBND_PARTSLIP) + } + else if (fluidmd->fss->typeFlags & OB_FSBND_PARTSLIP) { fsmesh.obstacleType = FLUIDSIM_OBSTACLE_PARTSLIP; - else if (fluidmd->fss->typeFlags & OB_FSBND_FREESLIP) + } + else if (fluidmd->fss->typeFlags & OB_FSBND_FREESLIP) { fsmesh.obstacleType = FLUIDSIM_OBSTACLE_FREESLIP; + } fsmesh.obstaclePartslip = fluidmd->fss->partSlipValue; fsmesh.volumeInitType = fluidmd->fss->volumeInitType; @@ -591,16 +602,19 @@ static void export_fluid_objects(const bContext *C, ListBase *fobjects, Scene *s fsmesh.channelTranslation = fsmesh.channelRotation = fsmesh.channelScale = NULL; /* Override user settings, only noslip is supported here! */ - if (fsmesh.type != OB_FLUIDSIM_CONTROL) + if (fsmesh.type != OB_FLUIDSIM_CONTROL) { fsmesh.obstacleType = FLUIDSIM_OBSTACLE_NOSLIP; + } } elbeemAddMesh(&fsmesh); - if (verts) + if (verts) { MEM_freeN(verts); - if (tris) + } + if (tris) { MEM_freeN(tris); + } } } @@ -617,8 +631,9 @@ static int fluid_validate_scene(ReportList *reports, ViewLayer *view_layer, Obje ob, eModifierType_Fluidsim); /* only find objects with fluid modifiers */ - if (!fluidmdtmp || ob->type != OB_MESH) + if (!fluidmdtmp || ob->type != OB_MESH) { continue; + } if (fluidmdtmp->fss->type == OB_FLUIDSIM_DOMAIN) { /* if no initial domain object given, find another potential domain */ @@ -633,16 +648,19 @@ static int fluid_validate_scene(ReportList *reports, ViewLayer *view_layer, Obje } /* count number of objects needed for animation channels */ - if (!ELEM(fluidmdtmp->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE)) + if (!ELEM(fluidmdtmp->fss->type, OB_FLUIDSIM_DOMAIN, OB_FLUIDSIM_PARTICLE)) { channelObjCount++; + } /* count number of fluid input objects */ - if (ELEM(fluidmdtmp->fss->type, OB_FLUIDSIM_FLUID, OB_FLUIDSIM_INFLOW)) + if (ELEM(fluidmdtmp->fss->type, OB_FLUIDSIM_FLUID, OB_FLUIDSIM_INFLOW)) { fluidInputCount++; + } } - if (newdomain) + if (newdomain) { fsDomain = newdomain; + } if (!fsDomain) { BKE_report(reports, RPT_ERROR, "No domain object found"); @@ -699,7 +717,8 @@ static bool fluid_init_filepaths(Main *bmain, const bool dir_exists = BLI_dir_create_recursive(targetDir); const bool is_writable = BLI_file_is_writable(targetFile); - /* We change path to some presumably valid default value, but do not allow bake process to continue, + /* We change path to some presumably valid default value, + * but do not allow bake process to continue, * this gives user chance to set manually another path. */ if (!dir_exists || !is_writable) { modifier_path_init(domainSettings->surfdataPath, @@ -765,8 +784,9 @@ static int fluidbake_breakjob(void *customdata) { FluidBakeJob *fb = (FluidBakeJob *)customdata; - if (fb->stop && *(fb->stop)) + if (fb->stop && *(fb->stop)) { return 1; + } /* this is not nice yet, need to make the jobs list template better * for identifying/acting upon various different jobs */ @@ -815,7 +835,13 @@ static int runSimulationCallback(void *data, int status, int frame) if (status == FLUIDSIM_CBSTATUS_NEWFRAME) { fluidbake_updatejob(fb, frame / (float)settings->noOfFrames); - //printf("elbeem blender cb s%d, f%d, domainid:%d noOfFrames: %d\n", status, frame, settings->domainId, settings->noOfFrames ); // DEBUG +# if 0 + printf("elbeem blender cb s%d, f%d, domainid:%d noOfFrames: %d\n", + status, + frame, + settings->domainId, + settings->noOfFrames); // DEBUG +# endif } if (fluidbake_breakjob(fb)) { @@ -938,7 +964,8 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, shor elbeemDebugOut(debugStrBuffer); } - /* make sure it corresponds to startFrame setting (old: noFrames = scene->r.efra - scene->r.sfra +1) */ + /* Make sure it corresponds to startFrame setting + * (old: noFrames = scene->r.efra - scene->r.sfra +1). */ ; noFrames = scene->r.efra - 0; if (noFrames <= 0) { @@ -1015,9 +1042,9 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, shor return false; } - channels->length = - scene->r - .efra; // DG TODO: why using endframe and not "noFrames" here? .. because "noFrames" is buggy too? (not using sfra) + /* DG TODO: why using endframe and not "noFrames" here? + * because "noFrames" is buggy too? (not using sfra) */ + channels->length = scene->r.efra; channels->aniFrameTime = (double)((double)domainSettings->animEnd - (double)domainSettings->animStart) / (double)noFrames; @@ -1089,19 +1116,24 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, shor fsset->runsimCallback = &runSimulationCallback; fsset->runsimUserData = fb; - if (domainSettings->typeFlags & OB_FSBND_NOSLIP) + if (domainSettings->typeFlags & OB_FSBND_NOSLIP) { fsset->domainobsType = FLUIDSIM_OBSTACLE_NOSLIP; - else if (domainSettings->typeFlags & OB_FSBND_PARTSLIP) + } + else if (domainSettings->typeFlags & OB_FSBND_PARTSLIP) { fsset->domainobsType = FLUIDSIM_OBSTACLE_PARTSLIP; - else if (domainSettings->typeFlags & OB_FSBND_FREESLIP) + } + else if (domainSettings->typeFlags & OB_FSBND_FREESLIP) { fsset->domainobsType = FLUIDSIM_OBSTACLE_FREESLIP; + } fsset->domainobsPartslip = domainSettings->partSlipValue; /* use domainobsType also for surface generation flag (bit: >=64) */ - if (domainSettings->typeFlags & OB_FSSG_NOOBS) + if (domainSettings->typeFlags & OB_FSSG_NOOBS) { fsset->mFsSurfGenSetting = FLUIDSIM_FSSG_NOOBS; - else + } + else { fsset->mFsSurfGenSetting = 0; // "normal" mode + } fsset->generateVertexVectors = (domainSettings->domainNovecgen == 0); @@ -1180,19 +1212,22 @@ static int fluidsimBake(bContext *UNUSED(C), static int fluid_bake_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { /* only one bake job at a time */ - if (WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_OBJECT_SIM_FLUID)) + if (WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_OBJECT_SIM_FLUID)) { return OPERATOR_CANCELLED; + } - if (!fluidsimBake(C, op->reports, CTX_data_active_object(C), true)) + if (!fluidsimBake(C, op->reports, CTX_data_active_object(C), true)) { return OPERATOR_CANCELLED; + } return OPERATOR_FINISHED; } static int fluid_bake_exec(bContext *C, wmOperator *op) { - if (!fluidsimBake(C, op->reports, CTX_data_active_object(C), false)) + if (!fluidsimBake(C, op->reports, CTX_data_active_object(C), false)) { return OPERATOR_CANCELLED; + } return OPERATOR_FINISHED; } diff --git a/source/blender/editors/physics/rigidbody_constraint.c b/source/blender/editors/physics/rigidbody_constraint.c index 2d2c90f9391..2c454448b9b 100644 --- a/source/blender/editors/physics/rigidbody_constraint.c +++ b/source/blender/editors/physics/rigidbody_constraint.c @@ -60,8 +60,9 @@ static bool ED_operator_rigidbody_con_active_poll(bContext *C) Object *ob = CTX_data_active_object(C); return (ob && ob->rigidbody_constraint); } - else + else { return 0; + } } bool ED_rigidbody_constraint_add( diff --git a/source/blender/editors/physics/rigidbody_object.c b/source/blender/editors/physics/rigidbody_object.c index 2914127f8d8..ed6d31dfd9b 100644 --- a/source/blender/editors/physics/rigidbody_object.c +++ b/source/blender/editors/physics/rigidbody_object.c @@ -66,8 +66,9 @@ static bool ED_operator_rigidbody_active_poll(bContext *C) Object *ob = ED_object_active_context(C); return (ob && ob->rigidbody_object); } - else + else { return 0; + } } static bool ED_operator_rigidbody_add_poll(bContext *C) @@ -76,8 +77,9 @@ static bool ED_operator_rigidbody_add_poll(bContext *C) Object *ob = ED_object_active_context(C); return (ob && ob->type == OB_MESH); } - else + else { return 0; + } } /* ----------------- */ @@ -506,8 +508,9 @@ static int rigidbody_objects_calc_mass_exec(bContext *C, wmOperator *op) /* get density (kg/m^3) to apply */ if (material >= 0) { /* get density from table, and store in props for later repeating */ - if (material >= NUM_RB_MATERIAL_PRESETS) + if (material >= NUM_RB_MATERIAL_PRESETS) { material = 0; + } density = RB_MATERIAL_DENSITY_TABLE[material].density; RNA_float_set(op->ptr, "density", density); diff --git a/source/blender/editors/physics/rigidbody_world.c b/source/blender/editors/physics/rigidbody_world.c index 179a5a513f4..558a293ccbf 100644 --- a/source/blender/editors/physics/rigidbody_world.c +++ b/source/blender/editors/physics/rigidbody_world.c @@ -172,11 +172,13 @@ static int rigidbody_world_export_exec(bContext *C, wmOperator *op) static int rigidbody_world_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (!RNA_struct_property_is_set(op->ptr, "relative_path")) + if (!RNA_struct_property_is_set(op->ptr, "relative_path")) { RNA_boolean_set(op->ptr, "relative_path", (U.flag & USER_RELPATHS) != 0); + } - if (RNA_struct_property_is_set(op->ptr, "filepath")) + if (RNA_struct_property_is_set(op->ptr, "filepath")) { return rigidbody_world_export_exec(C, op); + } // TODO: use the actual rigidbody world's name + .bullet instead of this temp crap RNA_string_set(op->ptr, "filepath", "rigidbodyworld_export.bullet"); diff --git a/source/blender/editors/render/CMakeLists.txt b/source/blender/editors/render/CMakeLists.txt index 5d414c3af0f..6c62dbcb3a2 100644 --- a/source/blender/editors/render/CMakeLists.txt +++ b/source/blender/editors/render/CMakeLists.txt @@ -21,17 +21,17 @@ set(INC ../../blenlib ../../blenloader ../../blentranslation + ../../bmesh ../../depsgraph ../../draw ../../gpu ../../imbuf - ../../bmesh ../../makesdna ../../makesrna ../../render/extern/include ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 6df1ba5e0aa..09bcc0a3058 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -72,6 +72,8 @@ #include "ED_undo.h" #include "ED_view3d.h" +#include "BIF_glutil.h" + #include "RE_pipeline.h" #include "RE_engine.h" @@ -147,19 +149,22 @@ static void image_buffer_rect_update(RenderJob *rj, if (renrect) { /* if (ymax == recty), rendering of layer is ready, * we should not draw, other things happen... */ - if (rr->renlay == NULL || renrect->ymax >= rr->recty) + if (rr->renlay == NULL || renrect->ymax >= rr->recty) { return; + } /* xmin here is first subrect x coord, xmax defines subrect width */ xmin = renrect->xmin + rr->crop; xmax = renrect->xmax - xmin + rr->crop; - if (xmax < 2) + if (xmax < 2) { return; + } ymin = renrect->ymin + rr->crop; ymax = renrect->ymax - ymin + rr->crop; - if (ymax < 2) + if (ymax < 2) { return; + } renrect->ymin = renrect->ymax; } else { @@ -170,19 +175,24 @@ static void image_buffer_rect_update(RenderJob *rj, /* xmin ymin is in tile coords. transform to ibuf */ rxmin = rr->tilerect.xmin + xmin; - if (rxmin >= ibuf->x) + if (rxmin >= ibuf->x) { return; + } rymin = rr->tilerect.ymin + ymin; - if (rymin >= ibuf->y) + if (rymin >= ibuf->y) { return; + } - if (rxmin + xmax > ibuf->x) + if (rxmin + xmax > ibuf->x) { xmax = ibuf->x - rxmin; - if (rymin + ymax > ibuf->y) + } + if (rymin + ymax > ibuf->y) { ymax = ibuf->y - rymin; + } - if (xmax < 1 || ymax < 1) + if (xmax < 1 || ymax < 1) { return; + } /* The thing here is, the logic below (which was default behavior * of how rectf is acquiring since forever) gives float buffer for @@ -203,8 +213,9 @@ static void image_buffer_rect_update(RenderJob *rj, rv = RE_RenderViewGetById(rr, view_id); /* find current float rect for display, first case is after composite... still weak */ - if (rv->rectf) + if (rv->rectf) { rectf = rv->rectf; + } else { if (rv->rect32) { /* special case, currently only happens with sequencer rendering, @@ -215,13 +226,15 @@ static void image_buffer_rect_update(RenderJob *rj, return; } else { - if (rr->renlay == NULL) + if (rr->renlay == NULL) { return; + } rectf = RE_RenderLayerGetPass(rr->renlay, RE_PASSNAME_COMBINED, viewname); } } - if (rectf == NULL) + if (rectf == NULL) { return; + } rectf += 4 * (rr->rectx * ymin + xmin); linear_stride = rr->rectx; @@ -294,8 +307,9 @@ static void screen_render_single_layer_set( RNA_string_get(op->ptr, "layer", rl_name); rl = (ViewLayer *)BLI_findstring(&(*scene)->view_layers, rl_name, offsetof(ViewLayer, name)); - if (rl) + if (rl) { *single_layer = rl; + } } else if (((*scene)->r.scemode & R_SINGLE_LAYER) && active_layer) { *single_layer = active_layer; @@ -344,12 +358,12 @@ static int screen_render_exec(bContext *C, wmOperator *op) * otherwise, invalidated cache entries can make their way into * the output rendering. We can't put that into RE_BlenderFrame, * since sequence rendering can call that recursively... (peter) */ - BKE_sequencer_cache_cleanup(); + BKE_sequencer_cache_cleanup(scene); RE_SetReports(re, op->reports); BLI_threaded_malloc_begin(); - if (is_animation) + if (is_animation) { RE_BlenderAnim(re, mainp, scene, @@ -358,9 +372,11 @@ static int screen_render_exec(bContext *C, wmOperator *op) scene->r.sfra, scene->r.efra, scene->r.frame_step); - else + } + else { RE_BlenderFrame( re, mainp, scene, single_layer, camera_override, scene->r.cfra, is_write_still); + } BLI_threaded_malloc_end(); RE_SetReports(re, NULL); @@ -402,10 +418,12 @@ static void make_renderinfo_string(const RenderStats *rs, megs_peak_memory = (peak_memory) / (1024.0 * 1024.0); /* local view */ - if (rs->localview) + if (rs->localview) { spos += sprintf(spos, "%s | ", IFACE_("3D Local View")); - else if (v3d_override) + } + else if (v3d_override) { spos += sprintf(spos, "%s | ", IFACE_("3D View")); + } /* frame number */ spos += sprintf(spos, IFACE_("Frame:%d "), (scene->r.cfra)); @@ -414,16 +432,19 @@ static void make_renderinfo_string(const RenderStats *rs, BLI_timecode_string_from_time_simple(info_time_str, sizeof(info_time_str), rs->lastframetime); if (rs->infostr && rs->infostr[0]) { - if (rs->lastframetime != 0.0) + if (rs->lastframetime != 0.0) { spos += sprintf(spos, IFACE_("| Last:%s "), info_time_str); - else + } + else { spos += sprintf(spos, "| "); + } BLI_timecode_string_from_time_simple( info_time_str, sizeof(info_time_str), PIL_check_seconds_timer() - rs->starttime); } - else + else { spos += sprintf(spos, "| "); + } spos += sprintf(spos, IFACE_("Time:%s "), info_time_str); @@ -434,38 +455,49 @@ static void make_renderinfo_string(const RenderStats *rs, } } else { - if (rs->totvert || rs->totface || rs->tothalo || rs->totstrand || rs->totlamp) + if (rs->totvert || rs->totface || rs->tothalo || rs->totstrand || rs->totlamp) { spos += sprintf(spos, "| "); + } - if (rs->totvert) + if (rs->totvert) { spos += sprintf(spos, IFACE_("Ve:%d "), rs->totvert); - if (rs->totface) + } + if (rs->totface) { spos += sprintf(spos, IFACE_("Fa:%d "), rs->totface); - if (rs->tothalo) + } + if (rs->tothalo) { spos += sprintf(spos, IFACE_("Ha:%d "), rs->tothalo); - if (rs->totstrand) + } + if (rs->totstrand) { spos += sprintf(spos, IFACE_("St:%d "), rs->totstrand); - if (rs->totlamp) + } + if (rs->totlamp) { spos += sprintf(spos, IFACE_("Li:%d "), rs->totlamp); + } - if (rs->mem_peak == 0.0f) + if (rs->mem_peak == 0.0f) { spos += sprintf(spos, IFACE_("| Mem:%.2fM (%.2fM, Peak %.2fM) "), megs_used_memory, mmap_used_memory, megs_peak_memory); - else + } + else { spos += sprintf(spos, IFACE_("| Mem:%.2fM, Peak: %.2fM "), rs->mem_used, rs->mem_peak); + } - if (rs->curfield) + if (rs->curfield) { spos += sprintf(spos, IFACE_("Field %d "), rs->curfield); - if (rs->curblur) + } + if (rs->curblur) { spos += sprintf(spos, IFACE_("Blur %d "), rs->curblur); + } } /* full sample */ - if (rs->curfsa) + if (rs->curfsa) { spos += sprintf(spos, IFACE_("| Full Sample %d "), rs->curfsa); + } /* extra info */ if (rs->infostr && rs->infostr[0]) { @@ -476,9 +508,11 @@ static void make_renderinfo_string(const RenderStats *rs, } /* very weak... but 512 characters is quite safe */ - if (spos >= str + IMA_MAX_RENDER_TEXT) - if (G.debug & G_DEBUG) + if (spos >= str + IMA_MAX_RENDER_TEXT) { + if (G.debug & G_DEBUG) { printf("WARNING! renderwin text beyond limit\n"); + } + } } static void image_renderinfo_cb(void *rjv, RenderStats *rs) @@ -490,8 +524,9 @@ static void image_renderinfo_cb(void *rjv, RenderStats *rs) if (rr) { /* malloc OK here, stats_draw is not in tile threads */ - if (rr->text == NULL) + if (rr->text == NULL) { rr->text = MEM_callocN(IMA_MAX_RENDER_TEXT, "rendertext"); + } make_renderinfo_string(rs, rj->scene, rj->v3d_override, rr->error, rr->text); } @@ -592,8 +627,9 @@ static void image_rect_update(void *rjv, RenderResult *rr, volatile rcti *renrec return; } - if (rr == NULL) + if (rr == NULL) { return; + } /* update part of render */ render_image_update_pass_and_layer(rj, rr, &rj->iuser); @@ -607,7 +643,7 @@ static void image_rect_update(void *rjv, RenderResult *rr, volatile rcti *renrec * operate with. */ if (rr->do_exr_tile || !rj->supports_glsl_draw || ibuf->channels == 1 || - U.image_draw_method != IMAGE_DRAW_METHOD_GLSL) { + ED_draw_imbuf_method(ibuf) != IMAGE_DRAW_METHOD_GLSL) { image_buffer_rect_update(rj, rr, ibuf, &rj->iuser, renrect, viewname); } @@ -634,7 +670,7 @@ static void render_startjob(void *rjv, short *stop, short *do_update, float *pro RE_SetReports(rj->re, rj->reports); - if (rj->anim) + if (rj->anim) { RE_BlenderAnim(rj->re, rj->main, rj->scene, @@ -643,7 +679,8 @@ static void render_startjob(void *rjv, short *stop, short *do_update, float *pro rj->scene->r.sfra, rj->scene->r.efra, rj->scene->r.frame_step); - else + } + else { RE_BlenderFrame(rj->re, rj->main, rj->scene, @@ -651,6 +688,7 @@ static void render_startjob(void *rjv, short *stop, short *do_update, float *pro rj->camera_override, rj->scene->r.cfra, rj->write_still); + } RE_SetReports(rj->re, NULL); } @@ -701,8 +739,9 @@ static void render_endjob(void *rjv) * to avoid referencing freed renderjobs bug T24508. */ RE_InitRenderCB(rj->re); - if (rj->main != G_MAIN) + if (rj->main != G_MAIN) { BKE_main_free(rj->main); + } /* else the frame will not update for the original value */ if (rj->anim && !(rj->scene->r.scemode & R_NO_FRAME_UPDATE)) { @@ -753,8 +792,9 @@ static void render_endjob(void *rjv) Image *ima = rj->image; ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &rj->iuser, &lock); - if (ibuf) + if (ibuf) { ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID; + } BKE_image_release_ibuf(ima, ibuf, lock); } @@ -775,10 +815,12 @@ static int render_breakjob(void *rjv) { RenderJob *rj = rjv; - if (G.is_break) + if (G.is_break) { return 1; - if (rj->stop && *(rj->stop)) + } + if (rj->stop && *(rj->stop)) { return 1; + } return 0; } @@ -786,8 +828,9 @@ static int render_breakjob(void *rjv) * note: this wont check for the escape key being pressed, but doing so isnt threadsafe */ static int render_break(void *UNUSED(rjv)) { - if (G.is_break) + if (G.is_break) { return 1; + } return 0; } @@ -903,8 +946,9 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even screen_render_single_layer_set(op, bmain, active_layer, &scene, &single_layer); /* only one render job at a time */ - if (WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_RENDER)) + if (WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_RENDER)) { return OPERATOR_CANCELLED; + } if (!RE_is_rendering_allowed(scene, single_layer, camera_override, op->reports)) { return OPERATOR_CANCELLED; @@ -920,8 +964,9 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even WM_jobs_kill_all_except(CTX_wm_manager(C), CTX_wm_screen(C)); /* cancel animation playback */ - if (ED_screen_animation_playing(CTX_wm_manager(C))) + if (ED_screen_animation_playing(CTX_wm_manager(C))) { ED_screen_animation_play(C, 0, 0); + } /* handle UI stuff */ WM_cursor_wait(1); @@ -933,7 +978,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even * otherwise, invalidated cache entries can make their way into * the output rendering. We can't put that into RE_BlenderFrame, * since sequence rendering can call that recursively... (peter) */ - BKE_sequencer_cache_cleanup(); + BKE_sequencer_cache_cleanup(scene); // store spare // get view3d layer, local layer, make this nice api call to render @@ -944,8 +989,9 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even jobflag = WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS; - if (RNA_struct_property_is_set(op->ptr, "layer")) + if (RNA_struct_property_is_set(op->ptr, "layer")) { jobflag |= WM_JOB_SUSPEND; + } /* job custom data */ rj = MEM_callocN(sizeof(RenderJob), "render job"); @@ -975,8 +1021,9 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even } if (v3d) { - if (camera_override && camera_override != scene->camera) + if (camera_override && camera_override != scene->camera) { rj->v3d_override = true; + } } /* Lock the user interface depending on render settings. */ @@ -998,10 +1045,12 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even } /* setup job */ - if (RE_seq_render_active(scene, &scene->r)) + if (RE_seq_render_active(scene, &scene->r)) { name = "Sequence Render"; - else + } + else { name = "Render"; + } wm_job = WM_jobs_get( CTX_wm_manager(C), CTX_wm_window(C), scene, name, jobflag, WM_JOB_TYPE_RENDER); @@ -1066,7 +1115,10 @@ void RENDER_OT_render(wmOperatorType *ot) ot->cancel = screen_render_cancel; ot->exec = screen_render_exec; - /*ot->poll = ED_operator_screenactive;*/ /* this isn't needed, causes failer in background mode */ + /* this isn't needed, causes failer in background mode */ +#if 0 + ot->poll = ED_operator_screenactive; +#endif prop = RNA_def_boolean(ot->srna, "animation", @@ -1107,8 +1159,9 @@ Scene *ED_render_job_get_scene(const bContext *C) wmWindowManager *wm = CTX_wm_manager(C); RenderJob *rj = (RenderJob *)WM_jobs_customdata_from_type(wm, WM_JOB_TYPE_RENDER); - if (rj) + if (rj) { return rj->scene; + } return NULL; } diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index 6862881de59..28cfce00e6e 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -154,8 +154,9 @@ static bool screen_opengl_is_multiview(OGLRender *oglrender) RegionView3D *rv3d = oglrender->rv3d; RenderData *rd = &oglrender->scene->r; - if ((rd == NULL) || ((v3d != NULL) && (rv3d == NULL))) + if ((rd == NULL) || ((v3d != NULL) && (rv3d == NULL))) { return false; + } return (rd->scemode & R_MULTIVIEW) && ((v3d == NULL) || (rv3d->persp == RV3D_CAMOB && v3d->camera)); @@ -189,14 +190,17 @@ static void screen_opengl_views_setup(OGLRender *oglrender) RenderView *rv_del = rv->next; BLI_remlink(&rr->views, rv_del); - if (rv_del->rectf) + if (rv_del->rectf) { MEM_freeN(rv_del->rectf); + } - if (rv_del->rectz) + if (rv_del->rectz) { MEM_freeN(rv_del->rectz); + } - if (rv_del->rect32) + if (rv_del->rect32) { MEM_freeN(rv_del->rect32); + } MEM_freeN(rv_del); } @@ -219,14 +223,17 @@ static void screen_opengl_views_setup(OGLRender *oglrender) BLI_remlink(&rr->views, rv_del); - if (rv_del->rectf) + if (rv_del->rectf) { MEM_freeN(rv_del->rectf); + } - if (rv_del->rectz) + if (rv_del->rectz) { MEM_freeN(rv_del->rectz); + } - if (rv_del->rect32) + if (rv_del->rect32) { MEM_freeN(rv_del->rect32); + } MEM_freeN(rv_del); } @@ -234,8 +241,9 @@ static void screen_opengl_views_setup(OGLRender *oglrender) /* create all the views that are needed */ for (srv = rd->views.first; srv; srv = srv->next) { - if (BKE_scene_multiview_is_render_view_active(rd, srv) == false) + if (BKE_scene_multiview_is_render_view_active(rd, srv) == false) { continue; + } rv = BLI_findstring(&rr->views, srv->name, offsetof(SceneRenderView, name)); @@ -247,8 +255,9 @@ static void screen_opengl_views_setup(OGLRender *oglrender) } } - if (!(is_multiview && BKE_scene_multiview_is_stereo3d(rd))) + if (!(is_multiview && BKE_scene_multiview_is_stereo3d(rd))) { oglrender->iuser.flag &= ~IMA_SHOW_STEREO; + } /* will only work for non multiview correctly */ if (v3d) { @@ -372,9 +381,10 @@ static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, R } } else { - draw_flags |= V3D_OFSDRAW_USE_GPENCIL; + draw_flags |= V3D_OFSDRAW_SHOW_ANNOTATION; ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(depsgraph, scene, + NULL, OB_SOLID, scene->camera, oglrender->sizex, @@ -431,10 +441,12 @@ static void screen_opengl_render_write(OGLRender *oglrender) RE_ReleaseResultImage(oglrender->re); - if (ok) + if (ok) { printf("OpenGL Render written to '%s'\n", name); - else + } + else { printf("OpenGL Render failed to write '%s'\n", name); + } } static void UNUSED_FUNCTION(addAlphaOverFloat)(float dest[4], const float source[4]) @@ -551,8 +563,9 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op) } /* only one render job at a time */ - if (WM_jobs_test(wm, scene, WM_JOB_TYPE_RENDER)) + if (WM_jobs_test(wm, scene, WM_JOB_TYPE_RENDER)) { return false; + } if (is_sequencer) { is_view_context = false; @@ -951,8 +964,9 @@ static bool screen_opengl_render_anim_step(bContext *C, wmOperator *op) RenderResult *rr; /* go to next frame */ - if (CFRA < oglrender->nfra) + if (CFRA < oglrender->nfra) { CFRA++; + } while (CFRA < oglrender->nfra) { BKE_scene_graph_update_for_newframe(depsgraph, bmain); CFRA++; @@ -1035,8 +1049,9 @@ static int screen_opengl_render_modal(bContext *C, wmOperator *op, const wmEvent return OPERATOR_FINISHED; case TIMER: /* render frame? */ - if (oglrender->timer == event->customdata) + if (oglrender->timer == event->customdata) { break; + } ATTR_FALLTHROUGH; default: /* nothing to do */ @@ -1068,12 +1083,14 @@ static int screen_opengl_render_invoke(bContext *C, wmOperator *op, const wmEven OGLRender *oglrender; const bool anim = RNA_boolean_get(op->ptr, "animation"); - if (!screen_opengl_render_init(C, op)) + if (!screen_opengl_render_init(C, op)) { return OPERATOR_CANCELLED; + } if (anim) { - if (!screen_opengl_render_anim_initialize(C, op)) + if (!screen_opengl_render_anim_initialize(C, op)) { return OPERATOR_CANCELLED; + } } oglrender = op->customdata; @@ -1093,8 +1110,9 @@ static int screen_opengl_render_exec(bContext *C, wmOperator *op) { const bool is_animation = RNA_boolean_get(op->ptr, "animation"); - if (!screen_opengl_render_init(C, op)) + if (!screen_opengl_render_init(C, op)) { return OPERATOR_CANCELLED; + } if (!is_animation) { /* same as invoke */ /* render image */ @@ -1106,8 +1124,9 @@ static int screen_opengl_render_exec(bContext *C, wmOperator *op) else { bool ret = true; - if (!screen_opengl_render_anim_initialize(C, op)) + if (!screen_opengl_render_anim_initialize(C, op)) { return OPERATOR_CANCELLED; + } while (ret) { ret = screen_opengl_render_anim_step(C, op); diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index c62d6530c6b..bf6d658f927 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -131,14 +131,16 @@ ImBuf *get_brush_icon(Brush *brush) } } - if (brush->icon_imbuf) + if (brush->icon_imbuf) { BKE_icon_changed(BKE_icon_id_ensure(&brush->id)); + } } } } - if (!(brush->icon_imbuf)) + if (!(brush->icon_imbuf)) { brush->id.icon_id = 0; + } return brush->icon_imbuf; } @@ -234,17 +236,20 @@ static bool check_engine_supports_preview(Scene *scene) void ED_preview_free_dbase(void) { - if (G_pr_main) + if (G_pr_main) { BKE_main_free(G_pr_main); + } - if (G_pr_main_grease_pencil) + if (G_pr_main_grease_pencil) { BKE_main_free(G_pr_main_grease_pencil); + } } static Scene *preview_get_scene(Main *pr_main) { - if (pr_main == NULL) + if (pr_main == NULL) { return NULL; + } return pr_main->scenes.first; } @@ -326,28 +331,22 @@ static World *preview_get_localized_world(ShaderPreview *sp, World *world) return sp->worldcopy; } -static ID *duplicate_ids(ID *id, Depsgraph *depsgraph) +static ID *duplicate_ids(ID *id) { if (id == NULL) { /* Non-ID preview render. */ return NULL; } - ID *id_eval = id; - - if (depsgraph) { - id_eval = DEG_get_evaluated_id(depsgraph, id); - } - switch (GS(id->name)) { case ID_MA: - return (ID *)BKE_material_localize((Material *)id_eval); + return (ID *)BKE_material_localize((Material *)id); case ID_TE: - return (ID *)BKE_texture_localize((Tex *)id_eval); + return (ID *)BKE_texture_localize((Tex *)id); case ID_LA: - return (ID *)BKE_light_localize((Light *)id_eval); + return (ID *)BKE_light_localize((Light *)id); case ID_WO: - return (ID *)BKE_world_localize((World *)id_eval); + return (ID *)BKE_world_localize((World *)id); case ID_IM: case ID_BR: case ID_SCR: @@ -397,10 +396,12 @@ static Scene *preview_prepare_scene( sce->r.tiley = sce->r.ysch / 4; } - if ((id && sp->pr_method == PR_ICON_RENDER) && id_type != ID_WO) + if ((id && sp->pr_method == PR_ICON_RENDER) && id_type != ID_WO) { sce->r.alphamode = R_ALPHAPREMUL; - else + } + else { sce->r.alphamode = R_ADDSKY; + } sce->r.cfra = scene->r.cfra; @@ -461,8 +462,9 @@ static Scene *preview_prepare_scene( Material ***matar = give_matarar(base->object); int actcol = max_ii(base->object->actcol - 1, 0); - if (matar && actcol < base->object->totcol) + if (matar && actcol < base->object->totcol) { (*matar)[actcol] = mat; + } } else if (base->object->type == OB_LAMP) { base->flag |= BASE_VISIBLE; @@ -510,8 +512,9 @@ static Scene *preview_prepare_scene( for (Base *base = view_layer->object_bases.first; base; base = base->next) { if (base->object->id.name[2] == 'p') { - if (base->object->type == OB_LAMP) + if (base->object->type == OB_LAMP) { base->object->data = la; + } } } @@ -562,10 +565,12 @@ static bool ed_preview_draw_rect(ScrArea *sa, int split, int first, rcti *rect, int newy = BLI_rcti_size_y(rect); bool ok = false; - if (!split || first) + if (!split || first) { sprintf(name, "Preview %p", (void *)sa); - else + } + else { sprintf(name, "SecondPreview %p", (void *)sa); + } if (split) { if (first) { @@ -581,8 +586,9 @@ static bool ed_preview_draw_rect(ScrArea *sa, int split, int first, rcti *rect, /* test if something rendered ok */ re = RE_GetRender(name); - if (re == NULL) + if (re == NULL) { return false; + } RE_AcquireResultImageViews(re, &rres); @@ -609,8 +615,9 @@ static bool ed_preview_draw_rect(ScrArea *sa, int split, int first, rcti *rect, float fy = rect->ymin; /* material preview only needs monoscopy (view 0) */ - if (re) + if (re) { RE_AcquiredResultGet32(re, &rres, (unsigned int *)rect_byte, 0); + } IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); immDrawPixelsTex(&state, @@ -662,11 +669,13 @@ void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, r ok = ed_preview_draw_rect(sa, 1, 1, rect, &newrect); ok &= ed_preview_draw_rect(sa, 1, 0, rect, &newrect); } - else + else { ok = ed_preview_draw_rect(sa, 0, 0, rect, &newrect); + } - if (ok) + if (ok) { *rect = newrect; + } /* start a new preview render job if signaled through sbuts->preview, * if no render result was found and no preview render job is running, @@ -712,26 +721,30 @@ static void shader_preview_updatejob(void *spv) if (GS(sp->id->name) == ID_MA) { Material *mat = (Material *)sp->id; - if (sp->matcopy && mat->nodetree && sp->matcopy->nodetree) + if (sp->matcopy && mat->nodetree && sp->matcopy->nodetree) { ntreeLocalSync(sp->matcopy->nodetree, mat->nodetree); + } } else if (GS(sp->id->name) == ID_TE) { Tex *tex = (Tex *)sp->id; - if (sp->texcopy && tex->nodetree && sp->texcopy->nodetree) + if (sp->texcopy && tex->nodetree && sp->texcopy->nodetree) { ntreeLocalSync(sp->texcopy->nodetree, tex->nodetree); + } } else if (GS(sp->id->name) == ID_WO) { World *wrld = (World *)sp->id; - if (sp->worldcopy && wrld->nodetree && sp->worldcopy->nodetree) + if (sp->worldcopy && wrld->nodetree && sp->worldcopy->nodetree) { ntreeLocalSync(sp->worldcopy->nodetree, wrld->nodetree); + } } else if (GS(sp->id->name) == ID_LA) { Light *la = (Light *)sp->id; - if (sp->lampcopy && la->nodetree && sp->lampcopy->nodetree) + if (sp->lampcopy && la->nodetree && sp->lampcopy->nodetree) { ntreeLocalSync(sp->lampcopy->nodetree, la->nodetree); + } } } } @@ -801,18 +814,15 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs char name[32]; int sizex; Main *pr_main = sp->pr_main; - ID *id_eval = id; - - if (sp->depsgraph) { - id_eval = DEG_get_evaluated_id(sp->depsgraph, id); - } /* in case of split preview, use border render */ if (split) { - if (first) + if (first) { sizex = sp->sizex / 2; - else + } + else { sizex = sp->sizex - sp->sizex / 2; + } } else { sizex = sp->sizex; @@ -827,19 +837,23 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs } /* get the stuff from the builtin preview dbase */ - sce = preview_prepare_scene(sp->bmain, sp->scene, id_eval, idtype, sp); - if (sce == NULL) + sce = preview_prepare_scene(sp->bmain, sp->scene, id, idtype, sp); + if (sce == NULL) { return; + } - if (!split || first) + if (!split || first) { sprintf(name, "Preview %p", sp->owner); - else + } + else { sprintf(name, "SecondPreview %p", sp->owner); + } re = RE_GetRender(name); /* full refreshed render from first tile */ - if (re == NULL) + if (re == NULL) { re = RE_NewRender(name); + } /* sce->r gets copied in RE_InitState! */ sce->r.scemode &= ~(R_MATNODE_PREVIEW | R_TEXNODE_PREVIEW); @@ -850,10 +864,12 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs sce->r.mode |= R_OSA; } else if (sp->pr_method == PR_NODE_RENDER) { - if (idtype == ID_MA) + if (idtype == ID_MA) { sce->r.scemode |= R_MATNODE_PREVIEW; - else if (idtype == ID_TE) + } + else if (idtype == ID_TE) { sce->r.scemode |= R_TEXNODE_PREVIEW; + } sce->r.mode &= ~R_OSA; } else { /* PR_BUTS_RENDER */ @@ -869,8 +885,9 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs /* lens adjust */ oldlens = ((Camera *)sce->camera->data)->lens; - if (sizex > sp->sizey) + if (sizex > sp->sizey) { ((Camera *)sce->camera->data)->lens *= (float)sp->sizey / (float)sizex; + } /* entire cycle for render engine */ if (idtype == ID_TE) { @@ -887,8 +904,9 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs if (sp->pr_method == PR_ICON_RENDER) { // char *rct= (char *)(sp->pr_rect + 32*16 + 16); - if (sp->pr_rect) + if (sp->pr_rect) { RE_ResultGet32(re, sp->pr_rect); + } } /* unassign the pointers, reset vars */ @@ -914,8 +932,9 @@ static void shader_preview_startjob(void *customdata, short *stop, short *do_upd shader_preview_render(sp, sp->id, 1, 1); shader_preview_render(sp, sp->parent, 1, 0); } - else + else { shader_preview_render(sp, sp->id, 0, 0); + } *do_update = true; } @@ -986,14 +1005,16 @@ static void icon_copy_rect(ImBuf *ibuf, unsigned int w, unsigned int h, unsigned short ex, ey, dx, dy; /* paranoia test */ - if (ibuf == NULL || (ibuf->rect == NULL && ibuf->rect_float == NULL)) + if (ibuf == NULL || (ibuf->rect == NULL && ibuf->rect_float == NULL)) { return; + } /* waste of cpu cyles... but the imbuf API has no other way to scale fast (ton) */ ima = IMB_dupImBuf(ibuf); - if (!ima) + if (!ima) { return; + } if (ima->x > ima->y) { scaledx = (float)w; @@ -1013,8 +1034,9 @@ static void icon_copy_rect(ImBuf *ibuf, unsigned int w, unsigned int h, unsigned IMB_scalefastImBuf(ima, ex, ey); /* if needed, convert to 32 bits */ - if (ima->rect == NULL) + if (ima->rect == NULL) { IMB_rect_from_float(ima); + } srect = ima->rect; drect = rect; @@ -1033,8 +1055,9 @@ static void set_alpha(char *cp, int sizex, int sizey, char alpha) { int a, size = sizex * sizey; - for (a = 0; a < size; a++, cp += 4) + for (a = 0; a < size; a++, cp += 4) { cp[3] = alpha; + } } static void icon_preview_startjob(void *customdata, short *stop, short *do_update) @@ -1070,8 +1093,9 @@ static void icon_preview_startjob(void *customdata, short *stop, short *do_updat ImageUser iuser = {NULL}; /* ima->ok is zero when Image cannot load */ - if (ima == NULL || ima->ok == 0) + if (ima == NULL || ima->ok == 0) { return; + } /* setup dummy image user */ iuser.ok = iuser.framenr = 1; @@ -1099,8 +1123,9 @@ static void icon_preview_startjob(void *customdata, short *stop, short *do_updat memset(sp->pr_rect, 0x88, sp->sizex * sp->sizey * sizeof(unsigned int)); - if (!(br->icon_imbuf) || !(br->icon_imbuf->rect)) + if (!(br->icon_imbuf) || !(br->icon_imbuf->rect)) { return; + } icon_copy_rect(br->icon_imbuf, sp->sizex, sp->sizey, sp->pr_rect); @@ -1135,10 +1160,12 @@ static void common_preview_startjob(void *customdata, { ShaderPreview *sp = customdata; - if (ELEM(sp->pr_method, PR_ICON_RENDER, PR_ICON_DEFERRED)) + if (ELEM(sp->pr_method, PR_ICON_RENDER, PR_ICON_DEFERRED)) { icon_preview_startjob(customdata, stop, do_update); - else + } + else { shader_preview_startjob(customdata, stop, do_update); + } } /* exported functions */ @@ -1228,8 +1255,9 @@ static void icon_preview_endjob(void *customdata) if (ip->id) { - if (GS(ip->id->name) == ID_BR) + if (GS(ip->id->name) == ID_BR) { WM_main_add_notifier(NC_BRUSH | NA_EDITED, ip->id); + } #if 0 if (GS(ip->id->name) == ID_MA) { Material *ma = (Material *)ip->id; @@ -1241,7 +1269,7 @@ static void icon_preview_endjob(void *customdata) if (prv_img->gputexture[i]) { GPU_texture_free(prv_img->gputexture[i]); prv_img->gputexture[i] = NULL; - WM_main_add_notifier(NC_MATERIAL|ND_SHADING_DRAW, ip->id); + WM_main_add_notifier(NC_MATERIAL | ND_SHADING_DRAW, ip->id); } } } @@ -1288,7 +1316,7 @@ void ED_preview_icon_render( ip.scene = scene; ip.owner = BKE_previewimg_id_ensure(id); ip.id = id; - ip.id_copy = duplicate_ids(id, NULL); + ip.id_copy = duplicate_ids(id); icon_preview_add_size(&ip, rect, sizex, sizey); @@ -1319,8 +1347,9 @@ void ED_preview_icon_job( /* render all resolutions from suspended job too */ old_ip = WM_jobs_customdata_get(wm_job); - if (old_ip) + if (old_ip) { BLI_movelisttolist(&ip->sizes, &old_ip->sizes); + } /* customdata for preview thread */ ip->bmain = CTX_data_main(C); @@ -1328,11 +1357,12 @@ void ED_preview_icon_job( ip->depsgraph = CTX_data_depsgraph(C); ip->owner = owner; ip->id = id; - ip->id_copy = duplicate_ids(id, ip->depsgraph); + ip->id_copy = duplicate_ids(id); icon_preview_add_size(ip, rect, sizex, sizey); - /* Special threading hack: warn main code that this preview is being rendered and cannot be freed... */ + /* Special threading hack: + * warn main code that this preview is being rendered and cannot be freed... */ { PreviewImage *prv_img = owner; if (prv_img->tag & PRV_TAG_DEFFERED) { @@ -1363,7 +1393,8 @@ void ED_preview_shader_job(const bContext *C, Scene *scene = CTX_data_scene(C); short id_type = GS(id->name); - /* Use workspace render only for buttons Window, since the other previews are related to the datablock. */ + /* Use workspace render only for buttons Window, + * since the other previews are related to the datablock. */ if (!check_engine_supports_preview(scene)) { return; @@ -1392,7 +1423,7 @@ void ED_preview_shader_job(const bContext *C, sp->sizey = sizey; sp->pr_method = method; sp->id = id; - sp->id_copy = duplicate_ids(id, sp->depsgraph); + sp->id_copy = duplicate_ids(id); sp->own_id_copy = true; sp->parent = parent; sp->slot = slot; @@ -1431,6 +1462,7 @@ void ED_preview_shader_job(const bContext *C, void ED_preview_kill_jobs(wmWindowManager *wm, Main *UNUSED(bmain)) { - if (wm) + if (wm) { WM_jobs_kill(wm, NULL, common_preview_startjob); + } } diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index 70157abf2ef..3186f011c6a 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -131,8 +131,9 @@ static int material_slot_add_exec(bContext *C, wmOperator *UNUSED(op)) Main *bmain = CTX_data_main(C); Object *ob = ED_object_context(C); - if (!ob) + if (!ob) { return OPERATOR_CANCELLED; + } BKE_object_material_slot_add(bmain, ob); @@ -168,8 +169,9 @@ static int material_slot_remove_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_context(C); - if (!ob) + if (!ob) { return OPERATOR_CANCELLED; + } /* Removing material slots in edit mode screws things up, see bug #21822.*/ if (ob == CTX_data_edit_object(C)) { @@ -366,10 +368,12 @@ static int material_slot_de_select(bContext *C, bool select) while (a--) { if (bp->hide == 0) { changed = true; - if (select) + if (select) { bp->f1 |= SELECT; - else + } + else { bp->f1 &= ~SELECT; + } } bp++; } @@ -435,13 +439,15 @@ static int material_slot_copy_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_object_context(C); Material ***matar; - if (!ob || !(matar = give_matarar(ob))) + if (!ob || !(matar = give_matarar(ob))) { return OPERATOR_CANCELLED; + } CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) { if (ob != ob_iter && give_matarar(ob_iter)) { - if (ob->data != ob_iter->data) + if (ob->data != ob_iter->data) { assign_matarar(bmain, ob_iter, matar, ob->totcol); + } if (ob_iter->totcol == ob->totcol) { ob_iter->actcol = ob->actcol; @@ -1026,8 +1032,9 @@ static int render_view_remove_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene = CTX_data_scene(C); SceneRenderView *rv = BLI_findlink(&scene->r.views, scene->r.actview); - if (!BKE_scene_remove_render_view(scene, rv)) + if (!BKE_scene_remove_render_view(scene, rv)) { return OPERATOR_CANCELLED; + } WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene); @@ -1544,14 +1551,18 @@ void SCENE_OT_freestyle_geometry_modifier_add(wmOperatorType *ot) static int freestyle_get_modifier_type(PointerRNA *ptr) { - if (RNA_struct_is_a(ptr->type, &RNA_LineStyleColorModifier)) + if (RNA_struct_is_a(ptr->type, &RNA_LineStyleColorModifier)) { return LS_MODIFIER_TYPE_COLOR; - else if (RNA_struct_is_a(ptr->type, &RNA_LineStyleAlphaModifier)) + } + else if (RNA_struct_is_a(ptr->type, &RNA_LineStyleAlphaModifier)) { return LS_MODIFIER_TYPE_ALPHA; - else if (RNA_struct_is_a(ptr->type, &RNA_LineStyleThicknessModifier)) + } + else if (RNA_struct_is_a(ptr->type, &RNA_LineStyleThicknessModifier)) { return LS_MODIFIER_TYPE_THICKNESS; - else if (RNA_struct_is_a(ptr->type, &RNA_LineStyleGeometryModifier)) + } + else if (RNA_struct_is_a(ptr->type, &RNA_LineStyleGeometryModifier)) { return LS_MODIFIER_TYPE_GEOMETRY; + } return -1; } @@ -1831,8 +1842,9 @@ static int copy_material_exec(bContext *C, wmOperator *UNUSED(op)) { Material *ma = CTX_data_pointer_get_type(C, "material", &RNA_Material).data; - if (ma == NULL) + if (ma == NULL) { return OPERATOR_CANCELLED; + } copy_matcopybuf(CTX_data_main(C), ma); @@ -1858,8 +1870,9 @@ static int paste_material_exec(bContext *C, wmOperator *UNUSED(op)) { Material *ma = CTX_data_pointer_get_type(C, "material", &RNA_Material).data; - if (ma == NULL) + if (ma == NULL) { return OPERATOR_CANCELLED; + } paste_matcopybuf(CTX_data_main(C), ma); @@ -1919,8 +1932,9 @@ static void paste_mtex_copybuf(ID *id) { MTex **mtex = NULL; - if (mtexcopied == 0 || mtexcopybuf.tex == NULL) + if (mtexcopied == 0 || mtexcopybuf.tex == NULL) { return; + } switch (GS(id->name)) { case ID_PA: @@ -1999,19 +2013,25 @@ static int paste_mtex_exec(bContext *C, wmOperator *UNUSED(op)) FreestyleLineStyle *linestyle = CTX_data_pointer_get_type(C, "line_style", &RNA_FreestyleLineStyle).data; - if (ma) + if (ma) { id = &ma->id; - else if (la) + } + else if (la) { id = &la->id; - else if (wo) + } + else if (wo) { id = &wo->id; - else if (psys) + } + else if (psys) { id = &psys->part->id; - else if (linestyle) + } + else if (linestyle) { id = &linestyle->id; + } - if (id == NULL) + if (id == NULL) { return OPERATOR_CANCELLED; + } } paste_mtex_copybuf(id); diff --git a/source/blender/editors/render/render_update.c b/source/blender/editors/render/render_update.c index dfc7610946a..3f3f98bc6e5 100644 --- a/source/blender/editors/render/render_update.c +++ b/source/blender/editors/render/render_update.c @@ -81,16 +81,19 @@ void ED_render_scene_update(const DEGEditorUpdateContext *update_ctx, int update /* don't do this render engine update if we're updating the scene from * other threads doing e.g. rendering or baking jobs */ - if (!BLI_thread_is_main()) + if (!BLI_thread_is_main()) { return; + } /* don't call this recursively for frame updates */ - if (recursive_check) + if (recursive_check) { return; + } /* Do not call if no WM available, see T42688. */ - if (BLI_listbase_is_empty(&bmain->wm)) + if (BLI_listbase_is_empty(&bmain->wm)) { return; + } recursive_check = true; @@ -160,12 +163,14 @@ void ED_render_engine_area_exit(Main *bmain, ScrArea *sa) ARegion *ar; wmWindowManager *wm = bmain->wm.first; - if (sa->spacetype != SPACE_VIEW3D) + if (sa->spacetype != SPACE_VIEW3D) { return; + } for (ar = sa->regionbase.first; ar; ar = ar->next) { - if (ar->regiontype != RGN_TYPE_WINDOW || !(ar->regiondata)) + if (ar->regiontype != RGN_TYPE_WINDOW || !(ar->regiondata)) { continue; + } ED_view3d_stop_render_preview(wm, ar); } } @@ -237,8 +242,9 @@ static void texture_changed(Main *bmain, Tex *tex) /* find compositing nodes */ if (scene->use_nodes && scene->nodetree) { for (node = scene->nodetree->nodes.first; node; node = node->next) { - if (node->id == &tex->id) + if (node->id == &tex->id) { ED_node_tag_update_id(&scene->id); + } } } } @@ -258,9 +264,11 @@ static void image_changed(Main *bmain, Image *ima) BKE_icon_changed(BKE_icon_id_ensure(&ima->id)); /* textures */ - for (tex = bmain->textures.first; tex; tex = tex->id.next) - if (tex->ima == ima) + for (tex = bmain->textures.first; tex; tex = tex->id.next) { + if (tex->ima == ima) { texture_changed(bmain, tex); + } + } } static void scene_changed(Main *bmain, Scene *scene) diff --git a/source/blender/editors/render/render_view.c b/source/blender/editors/render/render_view.c index 258e98977c7..cd5edcdc3f4 100644 --- a/source/blender/editors/render/render_view.c +++ b/source/blender/editors/render/render_view.c @@ -92,12 +92,14 @@ static ScrArea *find_area_showing_r_result(bContext *C, Scene *scene, wmWindow * for (sa = screen->areabase.first; sa; sa = sa->next) { if (sa->spacetype == SPACE_IMAGE) { sima = sa->spacedata.first; - if (sima->image && sima->image->type == IMA_TYPE_R_RESULT) + if (sima->image && sima->image->type == IMA_TYPE_R_RESULT) { break; + } } } - if (sa) + if (sa) { break; + } } } @@ -114,8 +116,9 @@ static ScrArea *find_area_image_empty(bContext *C) for (sa = sc->areabase.first; sa; sa = sa->next) { if (sa->spacetype == SPACE_IMAGE) { sima = sa->spacedata.first; - if (!sima->image) + if (!sima->image) { break; + } } } @@ -134,18 +137,21 @@ ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports) SpaceImage *sima; bool area_was_image = false; - if (scene->r.displaymode == R_OUTPUT_NONE) + if (scene->r.displaymode == R_OUTPUT_NONE) { return NULL; + } if (scene->r.displaymode == R_OUTPUT_WINDOW) { int sizex = 30 * UI_DPI_FAC + (scene->r.xsch * scene->r.size) / 100; int sizey = 60 * UI_DPI_FAC + (scene->r.ysch * scene->r.size) / 100; /* arbitrary... miniature image window views don't make much sense */ - if (sizex < 320) + if (sizex < 320) { sizex = 320; - if (sizey < 256) + } + if (sizey < 256) { sizey = 256; + } /* changes context! */ if (WM_window_open_temp(C, mx, my, sizex, sizey, WM_WINDOW_RENDER) == NULL) { @@ -164,8 +170,9 @@ ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports) sa = NULL; } else { - if (sa && sa->spacetype == SPACE_IMAGE) + if (sa && sa->spacetype == SPACE_IMAGE) { area_was_image = true; + } /* this function returns with changed context */ sa = ED_screen_full_newspace(C, sa, SPACE_IMAGE); @@ -174,12 +181,14 @@ ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports) if (!sa) { sa = find_area_showing_r_result(C, scene, &win); - if (sa == NULL) + if (sa == NULL) { sa = find_area_image_empty(C); + } /* if area found in other window, we make that one show in front */ - if (win && win != CTX_wm_window(C)) + if (win && win != CTX_wm_window(C)) { wm_window_raise(win); + } if (sa == NULL) { /* find largest open non-image area */ @@ -221,8 +230,9 @@ ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports) /* Tell the image editor to revert to previous space in space list on close * _only_ if it wasn't already an image editor when the render was invoked */ - if (area_was_image == 0) + if (area_was_image == 0) { sima->flag |= SI_PREVSPACE; + } else { /* Leave it alone so the image editor will just go back from * full screen to the original tiled setup */ diff --git a/source/blender/editors/scene/scene_edit.c b/source/blender/editors/scene/scene_edit.c index 381b595171a..8834d243d4a 100644 --- a/source/blender/editors/scene/scene_edit.c +++ b/source/blender/editors/scene/scene_edit.c @@ -94,12 +94,15 @@ bool ED_scene_delete(bContext *C, Main *bmain, wmWindow *win, Scene *scene) wmWindowManager *wm = bmain->wm.first; WM_jobs_kill_type(wm, scene, WM_JOB_TYPE_ANY); - if (scene->id.prev) + if (scene->id.prev) { scene_new = scene->id.prev; - else if (scene->id.next) + } + else if (scene->id.next) { scene_new = scene->id.next; - else + } + else { return false; + } WM_window_set_active_scene(bmain, C, win, scene_new); @@ -245,8 +248,9 @@ static int scene_delete_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; } - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("scene delete %p\n", scene); + } WM_event_add_notifier(C, NC_SCENE | NA_REMOVED, scene); diff --git a/source/blender/editors/screen/CMakeLists.txt b/source/blender/editors/screen/CMakeLists.txt index daa72ac194c..dc355148ad3 100644 --- a/source/blender/editors/screen/CMakeLists.txt +++ b/source/blender/editors/screen/CMakeLists.txt @@ -29,8 +29,8 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS @@ -39,6 +39,7 @@ set(INC_SYS set(SRC area.c + area_query.c area_utils.c glutil.c screen_context.c diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 4ca26d108a2..38684afec39 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -151,16 +151,18 @@ void ED_region_do_listen( /* generic notes first */ switch (note->category) { case NC_WM: - if (note->data == ND_FILEREAD) + if (note->data == ND_FILEREAD) { ED_region_tag_redraw(ar); + } break; case NC_WINDOW: ED_region_tag_redraw(ar); break; } - if (ar->type && ar->type->listener) + if (ar->type && ar->type->listener) { ar->type->listener(win, sa, ar, note, scene); + } } /* only exported for WM */ @@ -335,8 +337,9 @@ static void region_draw_azones(ScrArea *sa, ARegion *ar) { AZone *az; - if (!sa) + if (!sa) { return; + } GPU_line_width(1.0f); GPU_blend(true); @@ -421,17 +424,18 @@ static void region_draw_status_text(ScrArea *sa, ARegion *ar) BLF_draw(fontid, ar->headerstr, BLF_DRAW_STR_DUMMY_MAX); } -/* Follow wmMsgNotifyFn spec */ -void ED_region_do_msg_notify_tag_redraw(bContext *UNUSED(C), - wmMsgSubscribeKey *UNUSED(msg_key), - wmMsgSubscribeValue *msg_val) +void ED_region_do_msg_notify_tag_redraw( + /* Follow wmMsgNotifyFn spec */ + bContext *UNUSED(C), + wmMsgSubscribeKey *UNUSED(msg_key), + wmMsgSubscribeValue *msg_val) { ARegion *ar = msg_val->owner; ED_region_tag_redraw(ar); /* This avoids _many_ situations where header/properties control display settings. * the common case is space properties in the header */ - if (ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_UI)) { + if (ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER, RGN_TYPE_UI)) { while (ar && ar->prev) { ar = ar->prev; } @@ -442,15 +446,52 @@ void ED_region_do_msg_notify_tag_redraw(bContext *UNUSED(C), } } } -/* Follow wmMsgNotifyFn spec */ -void ED_area_do_msg_notify_tag_refresh(bContext *UNUSED(C), - wmMsgSubscribeKey *UNUSED(msg_key), - wmMsgSubscribeValue *msg_val) + +void ED_area_do_msg_notify_tag_refresh( + /* Follow wmMsgNotifyFn spec */ + bContext *UNUSED(C), + wmMsgSubscribeKey *UNUSED(msg_key), + wmMsgSubscribeValue *msg_val) { ScrArea *sa = msg_val->user_data; ED_area_tag_refresh(sa); } +static void region_do_msg_notify_tag_redraw( + /* Follow wmMsgNotifyFn spec */ + bContext *UNUSED(C), + wmMsgSubscribeKey *UNUSED(msg_key), + wmMsgSubscribeValue *msg_val) +{ + ARegion *ar = msg_val->owner; + ED_region_tag_redraw(ar); + + /* FIXME(campbell): shouldn't be needed. */ + WM_main_add_notifier(NC_SPACE | ND_SPACE_VIEW3D, NULL); +} + +void ED_area_do_mgs_subscribe_for_tool_header( + /* Follow ARegionType.message_subscribe */ + const struct bContext *UNUSED(C), + struct WorkSpace *workspace, + struct Scene *UNUSED(scene), + struct bScreen *UNUSED(screen), + struct ScrArea *UNUSED(sa), + struct ARegion *ar, + struct wmMsgBus *mbus) +{ + wmMsgSubscribeValue msg_sub_value_region_tag_redraw = { + .owner = ar, + .user_data = ar, + /* TODO(campbell): investigate why + * ED_region_do_msg_notify_tag_redraw doesn't work here. */ + // .notify = ED_region_do_msg_notify_tag_redraw, + .notify = region_do_msg_notify_tag_redraw, + }; + WM_msg_subscribe_rna_prop( + mbus, &workspace->id, workspace, WorkSpace, tools, &msg_sub_value_region_tag_redraw); +} + /** * Although there's no general support for minimizing areas, the status-bar can * be snapped to be only a few pixels high. A few pixels rather than 0 so it @@ -491,8 +532,9 @@ void ED_region_do_draw(bContext *C, ARegion *ar) ARegionType *at = ar->type; /* see BKE_spacedata_draw_locks() */ - if (at->do_lock) + if (at->do_lock) { return; + } ar->do_draw |= RGN_DRAWING; @@ -516,7 +558,8 @@ void ED_region_do_draw(bContext *C, ARegion *ar) at->draw(C, ar); } - /* XXX test: add convention to end regions always in pixel space, for drawing of borders/gestures etc */ + /* XXX test: add convention to end regions always in pixel space, + * for drawing of borders/gestures etc */ ED_region_pixelspace(ar); ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_PIXEL); @@ -530,8 +573,11 @@ void ED_region_do_draw(bContext *C, ARegion *ar) uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); immUniformColor4f(drand48(), drand48(), drand48(), 0.1f); - immRectf(pos, ar->drawrct.xmin - ar->winrct.xmin, ar->drawrct.ymin - ar->winrct.ymin, - ar->drawrct.xmax - ar->winrct.xmin, ar->drawrct.ymax - ar->winrct.ymin); + immRectf(pos, + ar->drawrct.xmin - ar->winrct.xmin, + ar->drawrct.ymin - ar->winrct.ymin, + ar->drawrct.xmax - ar->winrct.xmin, + ar->drawrct.ymax - ar->winrct.ymin); immUnbindProgram(); GPU_blend(false); #endif @@ -615,8 +661,9 @@ void ED_region_tag_redraw(ARegion *ar) void ED_region_tag_redraw_overlay(ARegion *ar) { - if (ar) + if (ar) { ar->do_draw_overlay = RGN_DRAW; + } } void ED_region_tag_redraw_no_rebuild(ARegion *ar) @@ -659,18 +706,22 @@ void ED_area_tag_redraw(ScrArea *sa) { ARegion *ar; - if (sa) - for (ar = sa->regionbase.first; ar; ar = ar->next) + if (sa) { + for (ar = sa->regionbase.first; ar; ar = ar->next) { ED_region_tag_redraw(ar); + } + } } void ED_area_tag_redraw_no_rebuild(ScrArea *sa) { ARegion *ar; - if (sa) - for (ar = sa->regionbase.first; ar; ar = ar->next) + if (sa) { + for (ar = sa->regionbase.first; ar; ar = ar->next) { ED_region_tag_redraw_no_rebuild(ar); + } + } } void ED_area_tag_redraw_regiontype(ScrArea *sa, int regiontype) @@ -688,8 +739,9 @@ void ED_area_tag_redraw_regiontype(ScrArea *sa, int regiontype) void ED_area_tag_refresh(ScrArea *sa) { - if (sa) + if (sa) { sa->do_refresh = true; + } } /* *************************************************************** */ @@ -700,14 +752,16 @@ void ED_area_status_text(ScrArea *sa, const char *str) ARegion *ar; /* happens when running transform operators in background mode */ - if (sa == NULL) + if (sa == NULL) { return; + } for (ar = sa->regionbase.first; ar; ar = ar->next) { if (ar->regiontype == RGN_TYPE_HEADER) { if (str) { - if (ar->headerstr == NULL) + if (ar->headerstr == NULL) { ar->headerstr = MEM_mallocN(UI_MAX_DRAW_STR, "headerprint"); + } BLI_strncpy(ar->headerstr, str, UI_MAX_DRAW_STR); BLI_str_rstrip(ar->headerstr); } @@ -726,12 +780,14 @@ void ED_workspace_status_text(bContext *C, const char *str) WorkSpace *workspace = CTX_wm_workspace(C); /* Can be NULL when running operators in background mode. */ - if (workspace == NULL) + if (workspace == NULL) { return; + } if (str) { - if (workspace->status_text == NULL) + if (workspace->status_text == NULL) { workspace->status_text = MEM_mallocN(UI_MAX_DRAW_STR, "headerprint"); + } BLI_strncpy(workspace->status_text, str, UI_MAX_DRAW_STR); } else if (workspace->status_text) { @@ -773,26 +829,28 @@ static void area_azone_initialize(wmWindow *win, const bScreen *screen, ScrArea return; } - float coords[4][4] = {/* Bottom-left. */ - {sa->totrct.xmin - U.pixelsize, - sa->totrct.ymin - U.pixelsize, - sa->totrct.xmin + AZONESPOTW, - sa->totrct.ymin + AZONESPOTH}, - /* Bottom-right. */ - {sa->totrct.xmax - AZONESPOTW, - sa->totrct.ymin - U.pixelsize, - sa->totrct.xmax + U.pixelsize, - sa->totrct.ymin + AZONESPOTH}, - /* Top-left. */ - {sa->totrct.xmin - U.pixelsize, - sa->totrct.ymax - AZONESPOTH, - sa->totrct.xmin + AZONESPOTW, - sa->totrct.ymax + U.pixelsize}, - /* Top-right. */ - {sa->totrct.xmax - AZONESPOTW, - sa->totrct.ymax - AZONESPOTH, - sa->totrct.xmax + U.pixelsize, - sa->totrct.ymax + U.pixelsize}}; + float coords[4][4] = { + /* Bottom-left. */ + {sa->totrct.xmin - U.pixelsize, + sa->totrct.ymin - U.pixelsize, + sa->totrct.xmin + AZONESPOTW, + sa->totrct.ymin + AZONESPOTH}, + /* Bottom-right. */ + {sa->totrct.xmax - AZONESPOTW, + sa->totrct.ymin - U.pixelsize, + sa->totrct.xmax + U.pixelsize, + sa->totrct.ymin + AZONESPOTH}, + /* Top-left. */ + {sa->totrct.xmin - U.pixelsize, + sa->totrct.ymax - AZONESPOTH, + sa->totrct.xmin + AZONESPOTW, + sa->totrct.ymax + U.pixelsize}, + /* Top-right. */ + {sa->totrct.xmax - AZONESPOTW, + sa->totrct.ymax - AZONESPOTH, + sa->totrct.xmax + U.pixelsize, + sa->totrct.ymax + U.pixelsize}, + }; for (int i = 0; i < 4; i++) { /* can't click on bottom corners on OS X, already used for resizing */ @@ -822,8 +880,9 @@ static void fullscreen_azone_initialize(ScrArea *sa, ARegion *ar) { AZone *az; - if (ED_area_is_global(sa) || (ar->regiontype != RGN_TYPE_WINDOW)) + if (ED_area_is_global(sa) || (ar->regiontype != RGN_TYPE_WINDOW)) { return; + } az = (AZone *)MEM_callocN(sizeof(AZone), "fullscreen action zone"); BLI_addtail(&(sa->actionzones), az); @@ -868,7 +927,6 @@ static void region_azone_edge(AZone *az, ARegion *ar) az->y2 = ar->winrct.ymax; break; } - BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); } @@ -884,8 +942,9 @@ static void region_azone_tab_plus(ScrArea *sa, AZone *az, ARegion *ar) const float tab_size_y = 0.4f * U.widget_unit; for (azt = sa->actionzones.first; azt; azt = azt->next) { - if (azt->edge == az->edge) + if (azt->edge == az->edge) { tot++; + } } switch (az->edge) { @@ -926,7 +985,7 @@ static bool region_azone_edge_poll(const ARegion *ar, const bool is_fullscreen) if (is_hidden && is_fullscreen) { return false; } - if (!is_hidden && ar->regiontype == RGN_TYPE_HEADER) { + if (!is_hidden && ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER)) { return false; } @@ -1006,15 +1065,25 @@ static void region_azones_add(const bScreen *screen, ScrArea *sa, ARegion *ar, c { const bool is_fullscreen = screen->state == SCREENFULL; + /* Only display tab or icons when the header region is hidden + * (not the tool header - they overlap). */ + if (ar->regiontype == RGN_TYPE_TOOL_HEADER) { + return; + } + /* edge code (t b l r) is along which area edge azone will be drawn */ - if (alignment == RGN_ALIGN_TOP) + if (alignment == RGN_ALIGN_TOP) { region_azone_edge_initialize(sa, ar, AE_BOTTOM_TO_TOPLEFT, is_fullscreen); - else if (alignment == RGN_ALIGN_BOTTOM) + } + else if (alignment == RGN_ALIGN_BOTTOM) { region_azone_edge_initialize(sa, ar, AE_TOP_TO_BOTTOMRIGHT, is_fullscreen); - else if (alignment == RGN_ALIGN_RIGHT) + } + else if (alignment == RGN_ALIGN_RIGHT) { region_azone_edge_initialize(sa, ar, AE_LEFT_TO_TOPRIGHT, is_fullscreen); - else if (alignment == RGN_ALIGN_LEFT) + } + else if (alignment == RGN_ALIGN_LEFT) { region_azone_edge_initialize(sa, ar, AE_RIGHT_TO_TOPLEFT, is_fullscreen); + } if (is_fullscreen) { fullscreen_azone_initialize(sa, ar); @@ -1141,8 +1210,9 @@ static void region_rect_recursive( { rcti *remainder_prev = remainder; - if (ar == NULL) + if (ar == NULL) { return; + } int prev_winx = ar->winx; int prev_winy = ar->winy; @@ -1151,9 +1221,11 @@ static void region_rect_recursive( BLI_rcti_init(&ar->winrct, 0, 0, 0, 0); /* for test; allow split of previously defined region */ - if (ar->alignment & RGN_SPLIT_PREV) - if (ar->prev) + if (ar->alignment & RGN_SPLIT_PREV) { + if (ar->prev) { remainder = &ar->prev->winrct; + } + } int alignment = ar->alignment & ~RGN_SPLIT_PREV; @@ -1178,6 +1250,9 @@ static void region_rect_recursive( else if (ar->regiontype == RGN_TYPE_HEADER) { prefsizey = ED_area_headersize(); } + else if (ar->regiontype == RGN_TYPE_TOOL_HEADER) { + prefsizey = ED_area_headersize(); + } else if (ar->regiontype == RGN_TYPE_FOOTER) { prefsizey = ED_area_footersize(); } @@ -1251,8 +1326,9 @@ static void region_rect_recursive( else { int fac = rct_fits(winrct, 'v', prefsizey); - if (fac < 0) + if (fac < 0) { prefsizey += fac; + } ar->winrct = *winrct; @@ -1275,8 +1351,9 @@ static void region_rect_recursive( else { int fac = rct_fits(winrct, 'h', prefsizex); - if (fac < 0) + if (fac < 0) { prefsizex += fac; + } ar->winrct = *winrct; @@ -1330,8 +1407,9 @@ static void region_rect_recursive( if (count != 4) { /* let's stop adding regions */ BLI_rcti_init(remainder, 0, 0, 0, 0); - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("region quadsplit failed\n"); + } } else { quad = 1; @@ -1366,10 +1444,12 @@ static void region_rect_recursive( /* if region opened normally, we store this for hide/reveal usage */ /* prevent rounding errors for UI_DPI_FAC mult and divide */ - if (ar->winx > 1) + if (ar->winx > 1) { ar->sizex = (ar->winx + 0.5f) / UI_DPI_FAC; - if (ar->winy > 1) + } + if (ar->winy > 1) { ar->sizey = (ar->winy + 0.5f) / UI_DPI_FAC; + } /* exception for multiple overlapping regions on same spot */ if (ar->overlap && (alignment != RGN_ALIGN_FLOAT)) { @@ -1444,7 +1524,8 @@ static void area_calc_totrct(ScrArea *sa, const rcti *window_rect) sa->totrct.ymax -= px; } /* Although the following asserts are correct they lead to a very unstable Blender. - * And the asserts would fail even in 2.7x (they were added in 2.8x as part of the top-bar commit). + * And the asserts would fail even in 2.7x + * (they were added in 2.8x as part of the top-bar commit). * For more details see T54864. */ #if 0 BLI_assert(sa->totrct.xmin >= 0); @@ -1463,12 +1544,20 @@ static void region_subwindow(ARegion *ar) { bool hidden = (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) != 0; - if ((ar->alignment & RGN_SPLIT_PREV) && ar->prev) + if ((ar->alignment & RGN_SPLIT_PREV) && ar->prev) { hidden = hidden || (ar->prev->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)); + } ar->visible = !hidden; } +static bool event_in_markers_region(const ARegion *ar, const wmEvent *event) +{ + rcti rect = ar->winrct; + rect.ymax = rect.ymin + UI_MARKER_MARGIN_Y; + return BLI_rcti_isect_pt(&rect, event->x, event->y); +} + /** * \param ar: Region, may be NULL when adding handlers for \a sa. */ @@ -1510,13 +1599,7 @@ static void ed_default_handlers( if (flag & ED_KEYMAP_MARKERS) { /* time-markers */ wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "Markers", 0, 0); - - /* use a boundbox restricted map */ - /* same local check for all areas */ - static rcti rect = {0, 10000, 0, -1}; - rect.ymax = UI_MARKER_MARGIN_Y; - BLI_assert(ar->type->regionid == RGN_TYPE_WINDOW); - WM_event_add_keymap_handler_bb(handlers, keymap, &rect, &ar->winrct); + WM_event_add_keymap_handler_poll(handlers, keymap, event_in_markers_region); } if (flag & ED_KEYMAP_ANIMATION) { /* frame changing and timeline operators (for time spaces) */ @@ -1637,8 +1720,9 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa) sa->type = BKE_spacetype_from_id(sa->spacetype); } - for (ar = sa->regionbase.first; ar; ar = ar->next) + for (ar = sa->regionbase.first; ar; ar = ar->next) { ar->type = BKE_regiontype_from_id_or_first(sa->type, ar->regiontype); + } /* area sizes */ area_calc_totrct(sa, &window_rect); @@ -1652,8 +1736,9 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa) /* default area handlers */ ed_default_handlers(wm, sa, NULL, &sa->handlers, sa->type->keymapflag); /* checks spacedata, adds own handlers */ - if (sa->type->init) + if (sa->type->init) { sa->type->init(wm, sa); + } /* clear all azones, add the area triangle widgets */ area_azone_initialize(win, screen, sa); @@ -1732,12 +1817,11 @@ void ED_region_cursor_set(wmWindow *win, ScrArea *sa, ARegion *ar) } /* for use after changing visibility of regions */ -void ED_region_visibility_change_update(bContext *C, ARegion *ar) +void ED_region_visibility_change_update(bContext *C, ScrArea *sa, ARegion *ar) { - ScrArea *sa = CTX_wm_area(C); - - if (ar->flag & RGN_FLAG_HIDDEN) + if (ar->flag & RGN_FLAG_HIDDEN) { WM_event_remove_handlers(C, &ar->handlers); + } ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa); ED_area_tag_redraw(sa); @@ -1752,10 +1836,10 @@ void region_toggle_hidden(bContext *C, ARegion *ar, const bool do_fade) if (do_fade && ar->overlap) { /* starts a timer, and in end calls the stuff below itself (region_sblend_invoke()) */ - region_blend_start(C, sa, ar); + ED_region_visibility_change_update_animated(C, sa, ar); } else { - ED_region_visibility_change_update(C, ar); + ED_region_visibility_change_update(C, sa, ar); } } @@ -1791,8 +1875,9 @@ void ED_area_data_copy(ScrArea *sa_dst, ScrArea *sa_src, const bool do_free) /* regions */ if (do_free) { st = BKE_spacetype_from_id(spacetype); - for (ar = sa_dst->regionbase.first; ar; ar = ar->next) + for (ar = sa_dst->regionbase.first; ar; ar = ar->next) { BKE_area_region_free(st, ar); + } BLI_freelistN(&sa_dst->regionbase); } st = BKE_spacetype_from_id(sa_src->spacetype); @@ -1889,9 +1974,11 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi * (e.g. with properties editor) until space-data is properly created */ /* check previously stored space */ - for (sl = sa->spacedata.first; sl; sl = sl->next) - if (sl->spacetype == type) + for (sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == type) { break; + } + } /* old spacedata... happened during work on 2.50, remove */ if (sl && BLI_listbase_is_empty(&sl->regionbase)) { @@ -1922,8 +2009,9 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi BLI_addhead(&sa->spacedata, sl); /* swap regions */ - if (slold) + if (slold) { slold->regionbase = sa->regionbase; + } sa->regionbase = sl->regionbase; BLI_listbase_clear(&sl->regionbase); } @@ -1934,7 +2022,7 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi /* Spaces with footer. */ if (st->spaceid == SPACE_TEXT) { for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) { - if (ar->regiontype == RGN_TYPE_HEADER) { + if (ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER)) { ar->alignment = header_alignment; } if (ar->regiontype == RGN_TYPE_FOOTER) { @@ -1947,7 +2035,7 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi } else { for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) { - if (ar->regiontype == RGN_TYPE_HEADER) { + if (ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER)) { ar->alignment = header_alignment; break; } @@ -2032,6 +2120,7 @@ static ThemeColorID region_background_color_id(const bContext *C, const ARegion switch (region->regiontype) { case RGN_TYPE_HEADER: + case RGN_TYPE_TOOL_HEADER: if (ED_screen_area_active(C) || ED_area_is_global(area)) { return TH_HEADER; } @@ -2217,8 +2306,9 @@ void ED_region_panels_layout_ex( BLI_SMALLSTACK_DECLARE(pt_stack, PanelType *); - if (contextnr != -1) + if (contextnr != -1) { is_context_new = UI_view2d_tab_set(v2d, contextnr); + } /* before setting the view */ if (vertical) { @@ -2339,7 +2429,8 @@ void ED_region_panels_layout_ex( } } else if (vertical) { - /* we always keep the scroll offset - so the total view gets increased with the scrolled away part */ + /* We always keep the scroll offset - + * so the total view gets increased with the scrolled away part. */ if (v2d->cur.ymax < -FLT_EPSILON) { /* Clamp to lower view boundary */ if (v2d->tot.ymin < -v2d->winy) { @@ -2425,9 +2516,8 @@ void ED_region_panels_draw(const bContext *C, ARegion *ar) mask_buf.xmax -= UI_PANEL_CATEGORY_MARGIN_WIDTH; mask = &mask_buf; } - View2DScrollers *scrollers = UI_view2d_scrollers_calc( - C, v2d, mask, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY); - UI_view2d_scrollers_draw(C, v2d, scrollers); + View2DScrollers *scrollers = UI_view2d_scrollers_calc(v2d, mask); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); } @@ -2474,7 +2564,8 @@ void ED_region_header_layout(const bContext *C, ARegion *ar) int yco = buttony + (ar->winy - buttony) / 2; int maxco = xco; - /* XXX workaround for 1 px alignment issue. Not sure what causes it... Would prefer a proper fix - Julian */ + /* XXX workaround for 1 px alignment issue. Not sure what causes it... + * Would prefer a proper fix - Julian */ if (!ELEM(CTX_wm_area(C)->spacetype, SPACE_TOPBAR, SPACE_STATUSBAR)) { yco -= 1; } @@ -2506,15 +2597,17 @@ void ED_region_header_layout(const bContext *C, ARegion *ar) /* for view2d */ xco = uiLayoutGetWidth(layout); - if (xco > maxco) + if (xco > maxco) { maxco = xco; + } } UI_block_layout_resolve(block, &xco, &yco); /* for view2d */ - if (xco > maxco) + if (xco > maxco) { maxco = xco; + } int new_sizex = (maxco + UI_HEADER_OFFSET) / UI_DPI_FAC; @@ -2855,8 +2948,9 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const do_newline = true; } - if (do_newline) + if (do_newline) { ofs_y += vertical_offset; + } } /* Strip */ else if (i == 1 || i == 2) { len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); @@ -2988,8 +3082,9 @@ void ED_region_image_metadata_draw( rctf rect; uiStyle *style = UI_style_get_dpi(); - if (!ibuf->metadata) + if (!ibuf->metadata) { return; + } /* find window pixel coordinates of origin */ GPU_matrix_push(); @@ -3091,8 +3186,9 @@ void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy) /* gridsize adapted to zoom level */ gridsize = 0.5f * (zoomx + zoomy); - if (gridsize <= 0.0f) + if (gridsize <= 0.0f) { return; + } if (gridsize < 1.0f) { while (gridsize < 1.0f) { @@ -3168,8 +3264,9 @@ void ED_region_visible_rect(ARegion *ar, rcti *rect) ARegion *arn = ar; /* allow function to be called without area */ - while (arn->prev) + while (arn->prev) { arn = arn->prev; + } *rect = ar->winrct; diff --git a/source/blender/editors/screen/area_query.c b/source/blender/editors/screen/area_query.c new file mode 100644 index 00000000000..420d70e63fb --- /dev/null +++ b/source/blender/editors/screen/area_query.c @@ -0,0 +1,172 @@ +/* + * 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 edscr + * + * Query functions for area/region. + */ + +#include "DNA_userdef_types.h" + +#include "BLI_blenlib.h" +#include "BLI_utildefines.h" +#include "BLI_math_base.h" + +#include "RNA_types.h" + +#include "WM_api.h" + +#include "ED_screen.h" + +#include "UI_interface.h" +#include "UI_view2d.h" + +bool ED_region_overlap_isect_x(const ARegion *ar, const int event_x) +{ + BLI_assert(ar->overlap); + /* No contents, skip it. */ + if (ar->v2d.mask.xmin == ar->v2d.mask.xmax) { + return false; + } + return BLI_rctf_isect_x(&ar->v2d.tot, + UI_view2d_region_to_view_x(&ar->v2d, event_x - ar->winrct.xmin)); +} + +bool ED_region_overlap_isect_y(const ARegion *ar, const int event_y) +{ + BLI_assert(ar->overlap); + /* No contents, skip it. */ + if (ar->v2d.mask.ymin == ar->v2d.mask.ymax) { + return false; + } + return BLI_rctf_isect_y(&ar->v2d.tot, + UI_view2d_region_to_view_y(&ar->v2d, event_y - ar->winrct.ymin)); +} + +bool ED_region_overlap_isect_xy(const ARegion *ar, const int event_xy[2]) +{ + return (ED_region_overlap_isect_x(ar, event_xy[0]) && + ED_region_overlap_isect_y(ar, event_xy[1])); +} + +bool ED_region_panel_category_gutter_calc_rect(const ARegion *ar, rcti *r_ar_gutter) +{ + *r_ar_gutter = ar->winrct; + if (UI_panel_category_is_visible(ar)) { + const int category_tabs_width = round_fl_to_int(UI_view2d_scale_get_x(&ar->v2d) * + UI_PANEL_CATEGORY_MARGIN_WIDTH); + if (ar->alignment == RGN_ALIGN_LEFT) { + r_ar_gutter->xmax = r_ar_gutter->xmin + category_tabs_width; + } + else if (ar->alignment == RGN_ALIGN_RIGHT) { + r_ar_gutter->xmin = r_ar_gutter->xmax - category_tabs_width; + } + else { + BLI_assert(!"Unsupported alignment"); + } + return true; + } + return false; +} + +bool ED_region_panel_category_gutter_isect_xy(const ARegion *ar, const int event_xy[2]) +{ + rcti ar_gutter; + if (ED_region_panel_category_gutter_calc_rect(ar, &ar_gutter)) { + return BLI_rcti_isect_pt_v(&ar_gutter, event_xy); + } + return false; +} + +bool ED_region_overlap_isect_x_with_margin(const ARegion *ar, const int event_x, const int margin) +{ + BLI_assert(ar->overlap); + /* No contents, skip it. */ + if (ar->v2d.mask.xmin == ar->v2d.mask.xmax) { + return false; + } + int region_x = event_x - ar->winrct.xmin; + return ((ar->v2d.tot.xmin <= UI_view2d_region_to_view_x(&ar->v2d, region_x + margin)) && + (ar->v2d.tot.xmax >= UI_view2d_region_to_view_x(&ar->v2d, region_x - margin))); +} + +bool ED_region_overlap_isect_y_with_margin(const ARegion *ar, const int event_y, const int margin) +{ + BLI_assert(ar->overlap); + /* No contents, skip it. */ + if (ar->v2d.mask.ymin == ar->v2d.mask.ymax) { + return false; + } + int region_y = event_y - ar->winrct.ymin; + return ((ar->v2d.tot.ymin <= UI_view2d_region_to_view_y(&ar->v2d, region_y + margin)) && + (ar->v2d.tot.ymax >= UI_view2d_region_to_view_y(&ar->v2d, region_y - margin))); +} + +bool ED_region_overlap_isect_xy_with_margin(const ARegion *ar, + const int event_xy[2], + const int margin) +{ + return (ED_region_overlap_isect_x_with_margin(ar, event_xy[0], margin) && + ED_region_overlap_isect_y_with_margin(ar, event_xy[1], margin)); +} + +bool ED_region_contains_xy(const ARegion *ar, const int event_xy[2]) +{ + /* Only use the margin when inside the region. */ + if (BLI_rcti_isect_pt_v(&ar->winrct, event_xy)) { + if (ar->overlap) { + const int overlap_margin = UI_REGION_OVERLAP_MARGIN; + /* Note the View2D.tot isn't reliable for headers with spacers otherwise + * we'd check #ED_region_overlap_isect_xy_with_margin for both bases. */ + if (ar->v2d.keeptot == V2D_KEEPTOT_STRICT) { + /* Header. */ + rcti rect; + BLI_rcti_init_pt_radius(&rect, event_xy, overlap_margin); + if (UI_region_but_find_rect_over(ar, &rect) == NULL) { + return false; + } + } + else { + /* Side-bar & any other kind of overlapping region. */ + + /* Check alignment to avoid region tabs being clipped out + * by only clipping a single axis for aligned regions. */ + if (ELEM(ar->alignment, RGN_ALIGN_TOP, RGN_ALIGN_BOTTOM)) { + if (!ED_region_overlap_isect_x_with_margin(ar, event_xy[0], overlap_margin)) { + return false; + } + } + else if (ELEM(ar->alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) { + if (ED_region_panel_category_gutter_isect_xy(ar, event_xy)) { + /* pass */ + } + else if (!ED_region_overlap_isect_y_with_margin(ar, event_xy[1], overlap_margin)) { + return false; + } + } + else { + /* No panel categories for horizontal regions currently. */ + if (!ED_region_overlap_isect_xy_with_margin(ar, event_xy, overlap_margin)) { + return false; + } + } + } + } + return true; + } + return false; +} diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 7fec62157c1..fc771e0db77 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -58,37 +58,6 @@ void set_inverted_drawing(int enable) GL_TOGGLE(GL_DITHER, !enable); } -float glaGetOneFloat(int param) -{ - GLfloat v; - glGetFloatv(param, &v); - return v; -} - -int glaGetOneInt(int param) -{ - GLint v; - glGetIntegerv(param, &v); - return v; -} - -void glaRasterPosSafe2f(float x, float y, float known_good_x, float known_good_y) -{ - GLubyte dummy = 0; - - /* As long as known good coordinates are correct - * this is guaranteed to generate an ok raster - * position (ignoring potential (real) overflow - * issues). - */ - glRasterPos2f(known_good_x, known_good_y); - - /* Now shift the raster position to where we wanted - * it in the first place using the glBitmap trick. - */ - glBitmap(0, 0, 0, 0, x - known_good_x, y - known_good_y, &dummy); -} - static int get_cached_work_texture(int *r_w, int *r_h) { static GLint texid = -1; @@ -203,12 +172,15 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, nsubparts_x = (img_w + (offset_x - 1)) / (offset_x); nsubparts_y = (img_h + (offset_y - 1)) / (offset_y); - if (format == GL_RGBA) + if (format == GL_RGBA) { components = 4; - else if (format == GL_RGB) + } + else if (format == GL_RGB) { components = 3; - else if (format == GL_RED) + } + else if (format == GL_RED) { components = 1; + } else { BLI_assert(!"Incompatible format passed to glaDrawPixelsTexScaled"); return; @@ -246,8 +218,9 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, float rast_x = x + subpart_x * offset_x * xzoom; float rast_y = y + subpart_y * offset_y * yzoom; /* check if we already got these because we always get 2 more when doing seamless */ - if (subpart_w <= seamless || subpart_h <= seamless) + if (subpart_w <= seamless || subpart_h <= seamless) { continue; + } if (use_clipping) { if (rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX < clip_min_x || @@ -273,7 +246,7 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, subpart_x * offset_x * components]); /* add an extra border of pixels so linear looks ok at edges of full image */ - if (subpart_w < tex_w) + if (subpart_w < tex_w) { glTexSubImage2D(GL_TEXTURE_2D, 0, subpart_w, @@ -284,7 +257,8 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, GL_FLOAT, &f_rect[((size_t)subpart_y) * offset_y * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]); - if (subpart_h < tex_h) + } + if (subpart_h < tex_h) { glTexSubImage2D( GL_TEXTURE_2D, 0, @@ -296,7 +270,8 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, GL_FLOAT, &f_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + subpart_x * offset_x * components]); - if (subpart_w < tex_w && subpart_h < tex_h) + } + if (subpart_w < tex_w && subpart_h < tex_h) { glTexSubImage2D( GL_TEXTURE_2D, 0, @@ -308,6 +283,7 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, GL_FLOAT, &f_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]); + } } else { glTexSubImage2D(GL_TEXTURE_2D, @@ -321,7 +297,7 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, &uc_rect[((size_t)subpart_y) * offset_y * img_w * components + subpart_x * offset_x * components]); - if (subpart_w < tex_w) + if (subpart_w < tex_w) { glTexSubImage2D(GL_TEXTURE_2D, 0, subpart_w, @@ -332,7 +308,8 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, GL_UNSIGNED_BYTE, &uc_rect[((size_t)subpart_y) * offset_y * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]); - if (subpart_h < tex_h) + } + if (subpart_h < tex_h) { glTexSubImage2D( GL_TEXTURE_2D, 0, @@ -344,7 +321,8 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, GL_UNSIGNED_BYTE, &uc_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + subpart_x * offset_x * components]); - if (subpart_w < tex_w && subpart_h < tex_h) + } + if (subpart_w < tex_w && subpart_h < tex_h) { glTexSubImage2D( GL_TEXTURE_2D, 0, @@ -356,6 +334,7 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, GL_UNSIGNED_BYTE, &uc_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]); + } } immBegin(GPU_PRIM_TRI_FAN, 4); @@ -382,7 +361,8 @@ void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state, /* NOTE: Weirdly enough this is only required on macOS. Without this there is some sort of * bleeding of data is happening from tiles which are drawn later on. - * This doesn't seem to be too slow, but still would be nice to have fast and nice solution. */ + * This doesn't seem to be too slow, + * but still would be nice to have fast and nice solution. */ #ifdef __APPLE__ GPU_flush(); #endif @@ -525,7 +505,8 @@ float bglPolygonOffsetCalc(const float winmat[16], float viewdist, float dist) /* This adjustment effectively results in reducing the Z value by 0.25%. * * winmat[14] actually evaluates to `-2 * far * near / (far - near)`, - * is very close to -0.2 with default clip range, and is used as the coefficient multiplied by `w / z`, + * is very close to -0.2 with default clip range, + * and is used as the coefficient multiplied by `w / z`, * thus controlling the z dependent part of the depth value. */ return winmat[14] * -0.0025f * dist; @@ -564,31 +545,32 @@ void bglPolygonOffset(float viewdist, float dist) /* **** Color management helper functions for GLSL display/transform ***** */ /* Draw given image buffer on a screen using GLSL for display transform */ -void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, - float x, - float y, - int zoomfilter, - ColorManagedViewSettings *view_settings, - ColorManagedDisplaySettings *display_settings, - float clip_min_x, - float clip_min_y, - float clip_max_x, - float clip_max_y, - float zoom_x, - float zoom_y) +void ED_draw_imbuf_clipping(ImBuf *ibuf, + float x, + float y, + int zoomfilter, + ColorManagedViewSettings *view_settings, + ColorManagedDisplaySettings *display_settings, + float clip_min_x, + float clip_min_y, + float clip_max_x, + float clip_max_y, + float zoom_x, + float zoom_y) { bool force_fallback = false; bool need_fallback = true; /* Early out */ - if (ibuf->rect == NULL && ibuf->rect_float == NULL) + if (ibuf->rect == NULL && ibuf->rect_float == NULL) { return; + } /* Single channel images could not be transformed using GLSL yet */ force_fallback |= ibuf->channels == 1; /* If user decided not to use GLSL, fallback to glaDrawPixelsAuto */ - force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL); + force_fallback |= (ED_draw_imbuf_method(ibuf) != IMAGE_DRAW_METHOD_GLSL); /* Try to draw buffer using GLSL display transform */ if (force_fallback == false) { @@ -618,12 +600,15 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, if (ibuf->rect_float) { int format = 0; - if (ibuf->channels == 3) + if (ibuf->channels == 3) { format = GL_RGB; - else if (ibuf->channels == 4) + } + else if (ibuf->channels == 4) { format = GL_RGBA; - else + } + else { BLI_assert(!"Incompatible number of channels for GLSL display"); + } if (format != 0) { immDrawPixelsTex_clipping(&state, @@ -702,65 +687,80 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, } } -void glaDrawImBuf_glsl(ImBuf *ibuf, - float x, - float y, - int zoomfilter, - ColorManagedViewSettings *view_settings, - ColorManagedDisplaySettings *display_settings, - float zoom_x, - float zoom_y) +void ED_draw_imbuf(ImBuf *ibuf, + float x, + float y, + int zoomfilter, + ColorManagedViewSettings *view_settings, + ColorManagedDisplaySettings *display_settings, + float zoom_x, + float zoom_y) { - glaDrawImBuf_glsl_clipping(ibuf, - x, - y, - zoomfilter, - view_settings, - display_settings, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - zoom_x, - zoom_y); + ED_draw_imbuf_clipping(ibuf, + x, + y, + zoomfilter, + view_settings, + display_settings, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + zoom_x, + zoom_y); } -void glaDrawImBuf_glsl_ctx_clipping(const bContext *C, - ImBuf *ibuf, - float x, - float y, - int zoomfilter, - float clip_min_x, - float clip_min_y, - float clip_max_x, - float clip_max_y, - float zoom_x, - float zoom_y) +void ED_draw_imbuf_ctx_clipping(const bContext *C, + ImBuf *ibuf, + float x, + float y, + int zoomfilter, + float clip_min_x, + float clip_min_y, + float clip_max_x, + float clip_max_y, + float zoom_x, + float zoom_y) { ColorManagedViewSettings *view_settings; ColorManagedDisplaySettings *display_settings; IMB_colormanagement_display_settings_from_ctx(C, &view_settings, &display_settings); - glaDrawImBuf_glsl_clipping(ibuf, - x, - y, - zoomfilter, - view_settings, - display_settings, - clip_min_x, - clip_min_y, - clip_max_x, - clip_max_y, - zoom_x, - zoom_y); + ED_draw_imbuf_clipping(ibuf, + x, + y, + zoomfilter, + view_settings, + display_settings, + clip_min_x, + clip_min_y, + clip_max_x, + clip_max_y, + zoom_x, + zoom_y); } -void glaDrawImBuf_glsl_ctx( +void ED_draw_imbuf_ctx( const bContext *C, ImBuf *ibuf, float x, float y, int zoomfilter, float zoom_x, float zoom_y) { - glaDrawImBuf_glsl_ctx_clipping( - C, ibuf, x, y, zoomfilter, 0.0f, 0.0f, 0.0f, 0.0f, zoom_x, zoom_y); + ED_draw_imbuf_ctx_clipping(C, ibuf, x, y, zoomfilter, 0.0f, 0.0f, 0.0f, 0.0f, zoom_x, zoom_y); +} + +int ED_draw_imbuf_method(ImBuf *ibuf) +{ + if (U.image_draw_method == IMAGE_DRAW_METHOD_AUTO) { + /* Use faster GLSL when CPU to GPU transfer is unlikely to be a bottleneck, + * otherwise do color management on CPU side. */ + const size_t threshold = 2048 * 2048 * 4 * sizeof(float); + const size_t data_size = (ibuf->rect_float) ? sizeof(float) : sizeof(uchar); + const size_t size = ibuf->x * ibuf->y * ibuf->channels * data_size; + + return (size > threshold) ? IMAGE_DRAW_METHOD_2DTEXTURE : IMAGE_DRAW_METHOD_GLSL; + } + else { + return U.image_draw_method; + } } /* don't move to GPU_immediate_util.h because this uses user-prefs diff --git a/source/blender/editors/screen/screen_context.c b/source/blender/editors/screen/screen_context.c index 719403531ff..c60469e092f 100644 --- a/source/blender/editors/screen/screen_context.c +++ b/source/blender/editors/screen/screen_context.c @@ -65,53 +65,54 @@ #include "screen_intern.h" -const char *screen_context_dir[] = {"scene", - "view_layer", - "visible_objects", - "visible_bases", - "selectable_objects", - "selectable_bases", - "selected_objects", - "selected_bases", - "editable_objects", - "editable_bases", - "selected_editable_objects", - "selected_editable_bases", - "objects_in_mode", - "objects_in_mode_unique_data", - "visible_bones", - "editable_bones", - "selected_bones", - "selected_editable_bones", - "visible_pose_bones", - "selected_pose_bones", - "selected_pose_bones_from_active_object", - "active_bone", - "active_pose_bone", - "active_base", - "active_object", - "object", - "edit_object", - "sculpt_object", - "vertex_paint_object", - "weight_paint_object", - "image_paint_object", - "particle_edit_object", - "uv_sculpt_object", - "pose_object", - "sequences", - "selected_sequences", - "selected_editable_sequences", /* sequencer */ - "gpencil_data", - "gpencil_data_owner", /* grease pencil data */ - "visible_gpencil_layers", - "editable_gpencil_layers", - "editable_gpencil_strokes", - "active_gpencil_layer", - "active_gpencil_frame", - "active_operator", - "selected_editable_fcurves", - NULL}; +const char *screen_context_dir[] = { + "scene", + "view_layer", + "visible_objects", + "visible_bases", + "selectable_objects", + "selectable_bases", + "selected_objects", + "selected_bases", + "editable_objects", + "editable_bases", + "selected_editable_objects", + "selected_editable_bases", + "objects_in_mode", + "objects_in_mode_unique_data", + "visible_bones", + "editable_bones", + "selected_bones", + "selected_editable_bones", + "visible_pose_bones", + "selected_pose_bones", + "selected_pose_bones_from_active_object", + "active_bone", + "active_pose_bone", + "active_base", + "active_object", + "object", + "edit_object", + "sculpt_object", + "vertex_paint_object", + "weight_paint_object", + "image_paint_object", + "particle_edit_object", + "pose_object", + "sequences", + "selected_sequences", + "selected_editable_sequences", /* sequencer */ + "gpencil_data", + "gpencil_data_owner", /* grease pencil data */ + "visible_gpencil_layers", + "editable_gpencil_layers", + "editable_gpencil_strokes", + "active_gpencil_layer", + "active_gpencil_frame", + "active_operator", + "selected_editable_fcurves", + NULL, +}; int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result) { @@ -274,8 +275,9 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult * We need to make sure that these mirrored copies are not selected, otherwise some * bones will be operated on twice. */ - if (arm->flag & ARM_MIRROR_EDIT) + if (arm->flag & ARM_MIRROR_EDIT) { flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone); + } /* if we're filtering for editable too, use the check for that instead, * as it has selection check too */ @@ -284,16 +286,18 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult if (EBONE_EDITABLE(ebone)) { CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); - if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) + if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) { CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); + } } } else { /* only include bones if visible */ CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); - if ((flipbone) && EBONE_VISIBLE(arm, flipbone) == 0) + if ((flipbone) && EBONE_VISIBLE(arm, flipbone) == 0) { CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); + } } } } @@ -328,8 +332,9 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult * We need to make sure that these mirrored copies are not selected, otherwise some * bones will be operated on twice. */ - if (arm->flag & ARM_MIRROR_EDIT) + if (arm->flag & ARM_MIRROR_EDIT) { flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone); + } /* if we're filtering for editable too, use the check for that instead, * as it has selection check too */ @@ -338,16 +343,18 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult if (EBONE_EDITABLE(ebone)) { CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); - if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) + if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) { CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); + } } } else { /* only include bones if selected */ CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); - if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) + if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) { CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); + } } } } @@ -449,74 +456,67 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult } } else if (CTX_data_equals(member, "active_base")) { - if (view_layer->basact) + if (view_layer->basact) { CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, view_layer->basact); + } return 1; } else if (CTX_data_equals(member, "active_object")) { - if (obact) + if (obact) { CTX_data_id_pointer_set(result, &obact->id); + } return 1; } else if (CTX_data_equals(member, "object")) { - if (obact) + if (obact) { CTX_data_id_pointer_set(result, &obact->id); + } return 1; } else if (CTX_data_equals(member, "edit_object")) { /* convenience for now, 1 object per scene in editmode */ - if (obedit) + if (obedit) { CTX_data_id_pointer_set(result, &obedit->id); + } return 1; } else if (CTX_data_equals(member, "sculpt_object")) { - if (obact && (obact->mode & OB_MODE_SCULPT)) + if (obact && (obact->mode & OB_MODE_SCULPT)) { CTX_data_id_pointer_set(result, &obact->id); + } return 1; } else if (CTX_data_equals(member, "vertex_paint_object")) { - if (obact && (obact->mode & OB_MODE_VERTEX_PAINT)) + if (obact && (obact->mode & OB_MODE_VERTEX_PAINT)) { CTX_data_id_pointer_set(result, &obact->id); + } return 1; } else if (CTX_data_equals(member, "weight_paint_object")) { - if (obact && (obact->mode & OB_MODE_WEIGHT_PAINT)) + if (obact && (obact->mode & OB_MODE_WEIGHT_PAINT)) { CTX_data_id_pointer_set(result, &obact->id); + } return 1; } else if (CTX_data_equals(member, "image_paint_object")) { - if (obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) + if (obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) { CTX_data_id_pointer_set(result, &obact->id); + } return 1; } else if (CTX_data_equals(member, "particle_edit_object")) { - if (obact && (obact->mode & OB_MODE_PARTICLE_EDIT)) + if (obact && (obact->mode & OB_MODE_PARTICLE_EDIT)) { CTX_data_id_pointer_set(result, &obact->id); - - return 1; - } - else if (CTX_data_equals(member, "uv_sculpt_object")) { - /* TODO(campbell): most likely we change rules for uv_sculpt. */ - if (obact && (obact->mode & OB_MODE_EDIT)) { - const ToolSettings *ts = scene->toolsettings; - if (ts->use_uv_sculpt) { - if (ED_uvedit_test(obedit)) { - WorkSpace *workspace = CTX_wm_workspace(C); - if ((workspace->tools_space_type == SPACE_IMAGE) && - (workspace->tools_mode == SI_MODE_UV)) { - CTX_data_id_pointer_set(result, &obact->id); - } - } - } } + return 1; } else if (CTX_data_equals(member, "pose_object")) { @@ -564,9 +564,10 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult } } else if (CTX_data_equals(member, "gpencil_data")) { - /* FIXME: for some reason, CTX_data_active_object(C) returns NULL when called from these situations - * (as outlined above - see Campbell's #ifdefs). That causes the get_active function to fail when - * called from context. For that reason, we end up using an alternative where we pass everything in! + /* FIXME: for some reason, CTX_data_active_object(C) returns NULL when called from these + * situations (as outlined above - see Campbell's #ifdefs). + * That causes the get_active function to fail when called from context. + * For that reason, we end up using an alternative where we pass everything in! */ bGPdata *gpd = ED_gpencil_data_get_active_direct((ID *)sc, sa, scene, obact); @@ -576,8 +577,9 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult } } else if (CTX_data_equals(member, "gpencil_data_owner")) { - /* pointer to which data/datablock owns the reference to the Grease Pencil data being used (as gpencil_data) - * XXX: see comment for gpencil_data case... + /* Pointer to which data/datablock owns the reference to the Grease Pencil data being used + * (as gpencil_data). + * XXX: see comment for gpencil_data case. */ bGPdata **gpd_ptr = NULL; PointerRNA ptr; @@ -726,8 +728,9 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); for (ale = anim_data.first; ale; ale = ale->next) { - if (ale->type == ANIMTYPE_FCURVE) + if (ale->type == ANIMTYPE_FCURVE) { CTX_data_list_add(result, ale->id, &RNA_FCurve, ale->data); + } } ANIM_animdata_freelist(&anim_data); diff --git a/source/blender/editors/screen/screen_draw.c b/source/blender/editors/screen/screen_draw.c index fb738bf40cd..1124070486f 100644 --- a/source/blender/editors/screen/screen_draw.c +++ b/source/blender/editors/screen/screen_draw.c @@ -40,7 +40,8 @@ #include "screen_intern.h" /** - * Draw horizontal shape visualizing future joining (left as well right direction of future joining). + * Draw horizontal shape visualizing future joining + * (left as well right direction of future joining). */ static void draw_horizontal_join_shape(ScrArea *sa, char dir, unsigned int pos) { @@ -540,7 +541,8 @@ void ED_screen_draw_split_preview(ScrArea *sa, const int dir, const float fac) /* Screen Thumbnail Preview */ /** - * Calculates a scale factor to squash the preview for \a screen into a rectangle of given size and aspect. + * Calculates a scale factor to squash the preview for \a screen into a rectangle + * of given size and aspect. */ static void screen_preview_scale_get( const bScreen *screen, float size_x, float size_y, const float asp[2], float r_scale[2]) @@ -588,7 +590,8 @@ static void screen_preview_draw_areas(const bScreen *screen, static void screen_preview_draw(const bScreen *screen, int size_x, int size_y) { const float asp[2] = {1.0f, 0.8f}; /* square previews look a bit ugly */ - /* could use theme color (tui.wcol_menu_item.text), but then we'd need to regenerate all previews when changing */ + /* could use theme color (tui.wcol_menu_item.text), + * but then we'd need to regenerate all previews when changing. */ const float col[4] = {1.0f, 1.0f, 1.0f, 1.0f}; float scale[2]; diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index 8caa960bb9a..2ce9d732eb7 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -113,14 +113,16 @@ ScrArea *area_split(const wmWindow *win, bScreen *sc, ScrArea *sa, char dir, flo short split; rcti window_rect; - if (sa == NULL) + if (sa == NULL) { return NULL; + } WM_window_rect_calc(win, &window_rect); split = screen_geom_find_area_split_point(sa, &window_rect, dir, fac); - if (split == 0) + if (split == 0) { return NULL; + } /* note regarding (fac > 0.5f) checks below. * normally it shouldn't matter which is used since the copy should match the original @@ -190,8 +192,9 @@ ScrArea *area_split(const wmWindow *win, bScreen *sc, ScrArea *sa, char dir, flo } /* remove double vertices en edges */ - if (merge) + if (merge) { BKE_screen_remove_double_scrverts(sc); + } BKE_screen_remove_double_scredges(sc); BKE_screen_remove_unused_scredges(sc); @@ -269,8 +272,9 @@ void screen_data_copy(bScreen *to, bScreen *from) } /* put at zero (needed?) */ - for (s1 = from->vertbase.first; s1; s1 = s1->next) + for (s1 = from->vertbase.first; s1; s1 = s1->next) { s1->newv = NULL; + } } /** @@ -291,8 +295,9 @@ int area_getorientation(ScrArea *sa, ScrArea *sb) ScrVert *sav1, *sav2, *sav3, *sav4; ScrVert *sbv1, *sbv2, *sbv3, *sbv4; - if (sa == NULL || sb == NULL) + if (sa == NULL || sb == NULL) { return -1; + } sav1 = sa->v1; sav2 = sa->v2; @@ -399,41 +404,26 @@ void ED_screen_do_listen(bContext *C, wmNotifier *note) /* generic notes */ switch (note->category) { case NC_WM: - if (note->data == ND_FILEREAD) + if (note->data == ND_FILEREAD) { screen->do_draw = true; + } break; case NC_WINDOW: screen->do_draw = true; break; case NC_SCREEN: - if (note->action == NA_EDITED) + if (note->action == NA_EDITED) { screen->do_draw = screen->do_refresh = true; + } break; case NC_SCENE: - if (note->data == ND_MODE) + if (note->data == ND_MODE) { region_cursor_set(win, true); + } break; } } -/* helper call for below, dpi changes headers */ -static void screen_refresh_headersizes(void) -{ - const ListBase *lb = BKE_spacetypes_list(); - SpaceType *st; - - for (st = lb->first; st; st = st->next) { - ARegionType *art; - art = BKE_regiontype_from_id(st, RGN_TYPE_HEADER); - if (art) - art->prefsizey = ED_area_headersize(); - - art = BKE_regiontype_from_id(st, RGN_TYPE_FOOTER); - if (art) - art->prefsizey = ED_area_headersize(); - } -} - /* make this screen usable */ /* for file read and first use, for scaling window, area moves */ void ED_screen_refresh(wmWindowManager *wm, wmWindow *win) @@ -446,7 +436,6 @@ void ED_screen_refresh(wmWindowManager *wm, wmWindow *win) WM_window_set_dpi(win); ED_screen_global_areas_refresh(win); - screen_refresh_headersizes(); screen_geom_vertices_scale(win, screen); @@ -458,8 +447,9 @@ void ED_screen_refresh(wmWindowManager *wm, wmWindow *win) } /* wake up animtimer */ - if (screen->animtimer) + if (screen->animtimer) { WM_event_timer_sleep(wm, win, screen->animtimer, false); + } } if (G.debug & G_DEBUG_EVENTS) { @@ -510,8 +500,9 @@ void ED_region_exit(bContext *C, ARegion *ar) wmWindow *win = CTX_wm_window(C); ARegion *prevar = CTX_wm_region(C); - if (ar->type && ar->type->exit) + if (ar->type && ar->type->exit) { ar->type->exit(wm, ar); + } CTX_wm_region_set(C, ar); @@ -541,13 +532,15 @@ void ED_area_exit(bContext *C, ScrArea *sa) ScrArea *prevsa = CTX_wm_area(C); ARegion *ar; - if (sa->type && sa->type->exit) + if (sa->type && sa->type->exit) { sa->type->exit(wm, sa); + } CTX_wm_area_set(C, sa); - for (ar = sa->regionbase.first; ar; ar = ar->next) + for (ar = sa->regionbase.first; ar; ar = ar->next) { ED_region_exit(C, ar); + } WM_event_remove_handlers(C, &sa->handlers); WM_event_modal_handler_area_replace(win, sa, NULL); @@ -562,8 +555,9 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen) CTX_wm_window_set(C, window); - if (screen->animtimer) + if (screen->animtimer) { WM_event_remove_timer(wm, window, screen->animtimer); + } screen->animtimer = NULL; screen->scrubbing = false; @@ -602,31 +596,39 @@ static void screen_cursor_set(wmWindow *win, const int xy[2]) AZone *az = NULL; ScrArea *sa; - for (sa = screen->areabase.first; sa; sa = sa->next) - if ((az = ED_area_actionzone_find_xy(sa, xy))) + for (sa = screen->areabase.first; sa; sa = sa->next) { + if ((az = ED_area_actionzone_find_xy(sa, xy))) { break; + } + } if (sa) { - if (az->type == AZONE_AREA) + if (az->type == AZONE_AREA) { WM_cursor_set(win, CURSOR_EDIT); + } else if (az->type == AZONE_REGION) { - if (az->edge == AE_LEFT_TO_TOPRIGHT || az->edge == AE_RIGHT_TO_TOPLEFT) + if (az->edge == AE_LEFT_TO_TOPRIGHT || az->edge == AE_RIGHT_TO_TOPLEFT) { WM_cursor_set(win, CURSOR_X_MOVE); - else + } + else { WM_cursor_set(win, CURSOR_Y_MOVE); + } } } else { ScrEdge *actedge = screen_geom_find_active_scredge(win, screen, xy[0], xy[1]); if (actedge) { - if (screen_geom_edge_is_horizontal(actedge)) + if (screen_geom_edge_is_horizontal(actedge)) { WM_cursor_set(win, CURSOR_Y_MOVE); - else + } + else { WM_cursor_set(win, CURSOR_X_MOVE); + } } - else + else { WM_cursor_set(win, CURSOR_STD); + } } } @@ -655,14 +657,15 @@ void ED_screen_set_active_region(bContext *C, wmWindow *win, const int xy[2]) if (sa) { /* make overlap active when mouse over */ for (ar = sa->regionbase.first; ar; ar = ar->next) { - if (BLI_rcti_isect_pt_v(&ar->winrct, xy)) { + if (ED_region_contains_xy(ar, xy)) { scr->active_region = ar; break; } } } - else + else { scr->active_region = NULL; + } /* check for redraw headers */ if (old_ar != scr->active_region) { @@ -679,7 +682,7 @@ void ED_screen_set_active_region(bContext *C, wmWindow *win, const int xy[2]) if (do_draw) { for (ar = area_iter->regionbase.first; ar; ar = ar->next) { - if (ar->regiontype == RGN_TYPE_HEADER) { + if (ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER)) { ED_region_tag_redraw_no_rebuild(ar); } } @@ -703,8 +706,9 @@ void ED_screen_set_active_region(bContext *C, wmWindow *win, const int xy[2]) UI_screen_free_active_but(C, scr); } } - else + else { region_cursor_set(win, false); + } } } } @@ -719,12 +723,15 @@ int ED_screen_area_active(const bContext *C) AZone *az = ED_area_actionzone_find_xy(sa, &win->eventstate->x); ARegion *ar; - if (az && az->type == AZONE_REGION) + if (az && az->type == AZONE_REGION) { return 1; + } - for (ar = sa->regionbase.first; ar; ar = ar->next) - if (ar == sc->active_region) + for (ar = sa->regionbase.first; ar; ar = ar->next) { + if (ar == sc->active_region) { return 1; + } + } } return 0; } @@ -813,16 +820,14 @@ static int screen_global_header_size(void) static void screen_global_topbar_area_refresh(wmWindow *win, bScreen *screen) { - const short size_min = screen_global_header_size(); - const short size_max = 2.25 * screen_global_header_size(); - const short size = (screen->flag & SCREEN_COLLAPSE_TOPBAR) ? size_min : size_max; + const short size = screen_global_header_size(); rcti rect; BLI_rcti_init(&rect, 0, WM_window_pixels_x(win) - 1, 0, WM_window_pixels_y(win) - 1); - rect.ymin = rect.ymax - size_max; + rect.ymin = rect.ymax - size; screen_global_area_refresh( - win, screen, SPACE_TOPBAR, GLOBAL_AREA_ALIGN_TOP, &rect, size, size_min, size_max); + win, screen, SPACE_TOPBAR, GLOBAL_AREA_ALIGN_TOP, &rect, size, size, size); } static void screen_global_statusbar_area_refresh(wmWindow *win, bScreen *screen) @@ -845,14 +850,11 @@ void ED_screen_global_areas_sync(wmWindow *win) * global areas should just become part of the screen instead. */ bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook); - screen->flag &= ~(SCREEN_COLLAPSE_STATUSBAR | SCREEN_COLLAPSE_TOPBAR); + screen->flag &= ~SCREEN_COLLAPSE_STATUSBAR; for (ScrArea *area = win->global_areas.areabase.first; area; area = area->next) { if (area->global->cur_fixed_height == area->global->size_min) { - if (area->spacetype == SPACE_TOPBAR) { - screen->flag |= SCREEN_COLLAPSE_TOPBAR; - } - else if (area->spacetype == SPACE_STATUSBAR) { + if (area->spacetype == SPACE_STATUSBAR) { screen->flag |= SCREEN_COLLAPSE_STATUSBAR; } } @@ -995,10 +997,12 @@ static void screen_set_3dview_camera(Scene *scene, ViewLayer *view_layer, ScrAre ListBase *regionbase; /* regionbase is in different place depending if space is active */ - if (v3d == sa->spacedata.first) + if (v3d == sa->spacedata.first) { regionbase = &sa->regionbase; - else + } + else { regionbase = &v3d->regionbase; + } for (ar = regionbase->first; ar; ar = ar->next) { if (ar->regiontype == RGN_TYPE_WINDOW) { @@ -1195,8 +1199,9 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *sa, const s sa->full = NULL; if (fullsa == NULL) { - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("%s: something wrong in areafullscreen\n", __func__); + } return NULL; } @@ -1278,6 +1283,7 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *sa, const s if (ELEM(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_HEADER, + RGN_TYPE_TOOL_HEADER, RGN_TYPE_FOOTER, RGN_TYPE_TOOLS, RGN_TYPE_NAV_BAR, @@ -1310,9 +1316,10 @@ void ED_refresh_viewport_fps(bContext *C) ScreenFrameRateInfo *fpsi = scene->fps_info; /* if there isn't any info, init it first */ - if (fpsi == NULL) + if (fpsi == NULL) { fpsi = scene->fps_info = MEM_callocN(sizeof(ScreenFrameRateInfo), "refresh_viewport_fps fps_info"); + } /* update the values */ fpsi->redrawtime = fpsi->lredrawtime; @@ -1320,8 +1327,9 @@ void ED_refresh_viewport_fps(bContext *C) } else { /* playback stopped or shouldn't be running */ - if (scene->fps_info) + if (scene->fps_info) { MEM_freeN(scene->fps_info); + } scene->fps_info = NULL; } } @@ -1355,16 +1363,18 @@ void ED_screen_animation_timer(bContext *C, int redraws, int refresh, int sync, sad->sfra = scene->r.cfra; scene->r.cfra = scene->r.psfra; } - else + else { sad->sfra = scene->r.cfra; + } } else { if (scene->r.sfra > scene->r.cfra) { sad->sfra = scene->r.cfra; scene->r.cfra = scene->r.sfra; } - else + else { sad->sfra = scene->r.cfra; + } } sad->redraws = redraws; sad->refresh = refresh; @@ -1375,8 +1385,9 @@ void ED_screen_animation_timer(bContext *C, int redraws, int refresh, int sync, char spacetype = -1; - if (sa) + if (sa) { spacetype = sa->spacetype; + } sad->from_anim_edit = (ELEM(spacetype, SPACE_GRAPH, SPACE_ACTION, SPACE_NLA)); @@ -1420,8 +1431,9 @@ void ED_screen_animation_timer_update(bScreen *screen, int redraws, int refresh) sad->redraws = redraws; sad->refresh = refresh; sad->ar = NULL; - if (redraws & TIME_REGION) + if (redraws & TIME_REGION) { sad->ar = time_top_left_3dwindow(screen); + } } } @@ -1447,20 +1459,6 @@ void ED_update_for_newframe(Main *bmain, Depsgraph *depsgraph) /* this function applies the changes too */ BKE_scene_graph_update_for_newframe(depsgraph, bmain); - - /* composite */ - if (scene->use_nodes && scene->nodetree) - ntreeCompositTagAnimated(scene->nodetree); - - /* update animated texture nodes */ - { - Tex *tex; - for (tex = bmain->textures.first; tex; tex = tex->id.next) { - if (tex->use_nodes && tex->nodetree) { - ntreeTexTagAnimated(tex->nodetree); - } - } - } } /* @@ -1476,8 +1474,9 @@ bool ED_screen_stereo3d_required(const bScreen *screen, const Scene *scene) case SPACE_VIEW3D: { View3D *v3d; - if (!is_multiview) + if (!is_multiview) { continue; + } v3d = sa->spacedata.first; if (v3d->camera && v3d->stereo3d_camera == STEREO_3D_ID) { @@ -1508,8 +1507,9 @@ bool ED_screen_stereo3d_required(const bScreen *screen, const Scene *scene) case SPACE_NODE: { SpaceNode *snode; - if (!is_multiview) + if (!is_multiview) { continue; + } snode = sa->spacedata.first; if ((snode->flag & SNODE_BACKDRAW) && ED_node_is_compositor(snode)) { @@ -1520,8 +1520,9 @@ bool ED_screen_stereo3d_required(const bScreen *screen, const Scene *scene) case SPACE_SEQ: { SpaceSeq *sseq; - if (!is_multiview) + if (!is_multiview) { continue; + } sseq = sa->spacedata.first; if (ELEM(sseq->view, SEQ_VIEW_PREVIEW, SEQ_VIEW_SEQUENCE_PREVIEW)) { diff --git a/source/blender/editors/screen/screen_geometry.c b/source/blender/editors/screen/screen_geometry.c index 1ad0e930582..25855382307 100644 --- a/source/blender/editors/screen/screen_geometry.c +++ b/source/blender/editors/screen/screen_geometry.c @@ -84,7 +84,8 @@ bool screen_geom_edge_is_horizontal(ScrEdge *se) } /** - * \param bounds_rect: Either window or screen bounds. Used to exclude edges along window/screen edges. + * \param bounds_rect: Either window or screen bounds. + * Used to exclude edges along window/screen edges. */ ScrEdge *screen_geom_area_map_find_active_scredge(const ScrAreaMap *area_map, const rcti *bounds_rect, @@ -102,8 +103,9 @@ ScrEdge *screen_geom_area_map_find_active_scredge(const ScrAreaMap *area_map, min = MIN2(se->v1->vec.x, se->v2->vec.x); max = MAX2(se->v1->vec.x, se->v2->vec.x); - if (abs(my - se->v1->vec.y) <= safety && mx >= min && mx <= max) + if (abs(my - se->v1->vec.y) <= safety && mx >= min && mx <= max) { return se; + } } } else { @@ -112,8 +114,9 @@ ScrEdge *screen_geom_area_map_find_active_scredge(const ScrAreaMap *area_map, min = MIN2(se->v1->vec.y, se->v2->vec.y); max = MAX2(se->v1->vec.y, se->v2->vec.y); - if (abs(mx - se->v1->vec.x) <= safety && my >= min && my <= max) + if (abs(mx - se->v1->vec.x) <= safety && my >= min && my <= max) { return se; + } } } } @@ -152,16 +155,11 @@ ScrEdge *screen_geom_find_active_scredge(const wmWindow *win, */ void screen_geom_vertices_scale(const wmWindow *win, bScreen *sc) { - /* clamp Y size of header sized areas when expanding windows - * avoids annoying empty space around file menu */ -#define USE_HEADER_SIZE_CLAMP - rcti window_rect, screen_rect; WM_window_rect_calc(win, &window_rect); WM_window_screen_rect_calc(win, &screen_rect); - const int headery_init = ED_area_headersize(); const int screen_size_x = BLI_rcti_size_x(&screen_rect); const int screen_size_y = BLI_rcti_size_y(&screen_rect); ScrVert *sv = NULL; @@ -181,33 +179,6 @@ void screen_geom_vertices_scale(const wmWindow *win, bScreen *sc) screen_size_x_prev = (max[0] - min[0]) + 1; screen_size_y_prev = (max[1] - min[1]) + 1; -#ifdef USE_HEADER_SIZE_CLAMP -# define TEMP_BOTTOM 1 -# define TEMP_TOP 2 - - /* if the window's Y axis grows, clamp header sized areas */ - if (screen_size_y_prev < screen_size_y) { /* growing? */ - const int headery_margin_max = headery_init + 5; - for (sa = sc->areabase.first; sa; sa = sa->next) { - ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); - sa->temp = 0; - - if (ar && !(ar->flag & RGN_FLAG_HIDDEN)) { - if (sa->v2->vec.y == max[1]) { - if (screen_geom_area_height(sa) < headery_margin_max) { - sa->temp = TEMP_TOP; - } - } - else if (sa->v1->vec.y == min[1]) { - if (screen_geom_area_height(sa) < headery_margin_max) { - sa->temp = TEMP_BOTTOM; - } - } - } - } - } -#endif - if (screen_size_x_prev != screen_size_x || screen_size_y_prev != screen_size_y) { const float facx = ((float)screen_size_x - 1) / ((float)screen_size_x_prev - 1); const float facy = ((float)screen_size_y - 1) / ((float)screen_size_y_prev - 1); @@ -220,85 +191,55 @@ void screen_geom_vertices_scale(const wmWindow *win, bScreen *sc) sv->vec.y = screen_rect.ymin + round_fl_to_short((sv->vec.y - min[1]) * facy); CLAMP(sv->vec.y, screen_rect.ymin, screen_rect.ymax - 1); } - } -#ifdef USE_HEADER_SIZE_CLAMP - if (screen_size_y_prev < screen_size_y) { /* growing? */ - for (sa = sc->areabase.first; sa; sa = sa->next) { - ScrEdge *se = NULL; - - if (sa->temp == 0) - continue; - - if (sa->v1 == sa->v2) - continue; - - /* adjust headery if verts are along the edge of window */ - if (sa->temp == TEMP_TOP) { - /* lower edge */ - const int yval = sa->v2->vec.y - headery_init; - se = BKE_screen_find_edge(sc, sa->v4, sa->v1); - if (se != NULL) { - screen_geom_select_connected_edge(win, se); - } - for (sv = sc->vertbase.first; sv; sv = sv->next) { - if (sv != sa->v2 && sv != sa->v3) { - if (sv->flag) { - sv->vec.y = yval; - } - } - } - } - else { - /* upper edge */ - const int yval = sa->v1->vec.y + headery_init; - se = BKE_screen_find_edge(sc, sa->v2, sa->v3); - if (se != NULL) { - screen_geom_select_connected_edge(win, se); - } - for (sv = sc->vertbase.first; sv; sv = sv->next) { - if (sv != sa->v1 && sv != sa->v4) { - if (sv->flag) { - sv->vec.y = yval; + /* test for collapsed areas. This could happen in some blender version... */ + /* ton: removed option now, it needs Context... */ + + int headery = ED_area_headersize() + (U.pixelsize * 2); + + if (facy > 1) { + /* Keep timeline small in video edit workspace. */ + for (sa = sc->areabase.first; sa; sa = sa->next) { + if (sa->spacetype == SPACE_ACTION && sa->v1->vec.y == screen_rect.ymin && + screen_geom_area_height(sa) <= headery * facy + 1) { + ScrEdge *se = BKE_screen_find_edge(sc, sa->v2, sa->v3); + if (se) { + const int yval = sa->v1->vec.y + headery - 1; + + screen_geom_select_connected_edge(win, se); + + /* all selected vertices get the right offset */ + for (sv = sc->vertbase.first; sv; sv = sv->next) { + /* if is a collapsed area */ + if (sv != sa->v1 && sv != sa->v4) { + if (sv->flag) { + sv->vec.y = yval; + } + } } } } } } - } - -# undef USE_HEADER_SIZE_CLAMP -# undef TEMP_BOTTOM -# undef TEMP_TOP -#endif - - /* test for collapsed areas. This could happen in some blender version... */ - /* ton: removed option now, it needs Context... */ - - /* make each window at least ED_area_headersize() high */ - for (sa = sc->areabase.first; sa; sa = sa->next) { - int headery = headery_init; - - /* adjust headery if verts are along the edge of window */ - if (sa->v1->vec.y > window_rect.ymin) - headery += U.pixelsize; - if (sa->v2->vec.y < (window_rect.ymax - 1)) - headery += U.pixelsize; - - if (screen_geom_area_height(sa) < headery) { - /* lower edge */ - ScrEdge *se = BKE_screen_find_edge(sc, sa->v4, sa->v1); - if (se && sa->v1 != sa->v2) { - const int yval = sa->v2->vec.y - headery + 1; - - screen_geom_select_connected_edge(win, se); - - /* all selected vertices get the right offset */ - for (sv = sc->vertbase.first; sv; sv = sv->next) { - /* if is a collapsed area */ - if (sv != sa->v2 && sv != sa->v3) { - if (sv->flag) { - sv->vec.y = yval; + if (facy < 1) { + /* make each window at least ED_area_headersize() high */ + for (sa = sc->areabase.first; sa; sa = sa->next) { + if (screen_geom_area_height(sa) < headery) { + /* lower edge */ + ScrEdge *se = BKE_screen_find_edge(sc, sa->v4, sa->v1); + if (se && sa->v1 != sa->v2) { + const int yval = sa->v2->vec.y - headery + 1; + + screen_geom_select_connected_edge(win, se); + + /* all selected vertices get the right offset */ + for (sv = sc->vertbase.first; sv; sv = sv->next) { + /* if is not a collapsed area */ + if (sv != sa->v2 && sv != sa->v3) { + if (sv->flag) { + sv->vec.y = yval; + } + } } } } @@ -306,7 +247,8 @@ void screen_geom_vertices_scale(const wmWindow *win, bScreen *sc) } } - /* Global areas have a fixed size that only changes with the DPI. Here we ensure that exactly this size is set. */ + /* Global areas have a fixed size that only changes with the DPI. + * Here we ensure that exactly this size is set. */ for (ScrArea *area = win->global_areas.areabase.first; area; area = area->next) { if (area->global->flag & GLOBAL_AREA_IS_HIDDEN) { continue; diff --git a/source/blender/editors/screen/screen_intern.h b/source/blender/editors/screen/screen_intern.h index d2c43d1df28..4971b310eff 100644 --- a/source/blender/editors/screen/screen_intern.h +++ b/source/blender/editors/screen/screen_intern.h @@ -89,9 +89,6 @@ extern const char *screen_context_dir[]; /* doc access */ /* screendump.c */ void SCREEN_OT_screenshot(struct wmOperatorType *ot); -/* screen_ops.c */ -void region_blend_start(struct bContext *C, struct ScrArea *sa, struct ARegion *ar); - /* workspace_layout_edit.c */ bool workspace_layout_set_poll(const struct WorkSpaceLayout *layout); diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 94b5f695de8..9f452dd79e0 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -102,44 +102,55 @@ bool ED_operator_regionactive(bContext *C) { - if (CTX_wm_window(C) == NULL) + if (CTX_wm_window(C) == NULL) { return 0; - if (CTX_wm_screen(C) == NULL) + } + if (CTX_wm_screen(C) == NULL) { return 0; - if (CTX_wm_region(C) == NULL) + } + if (CTX_wm_region(C) == NULL) { return 0; + } return 1; } bool ED_operator_areaactive(bContext *C) { - if (CTX_wm_window(C) == NULL) + if (CTX_wm_window(C) == NULL) { return 0; - if (CTX_wm_screen(C) == NULL) + } + if (CTX_wm_screen(C) == NULL) { return 0; - if (CTX_wm_area(C) == NULL) + } + if (CTX_wm_area(C) == NULL) { return 0; + } return 1; } bool ED_operator_screenactive(bContext *C) { - if (CTX_wm_window(C) == NULL) + if (CTX_wm_window(C) == NULL) { return 0; - if (CTX_wm_screen(C) == NULL) + } + if (CTX_wm_screen(C) == NULL) { return 0; + } return 1; } /* XXX added this to prevent anim state to change during renders */ static bool ED_operator_screenactive_norender(bContext *C) { - if (G.is_rendering) + if (G.is_rendering) { return 0; - if (CTX_wm_window(C) == NULL) + } + if (CTX_wm_window(C) == NULL) { return 0; - if (CTX_wm_screen(C) == NULL) + } + if (CTX_wm_screen(C) == NULL) { return 0; + } return 1; } @@ -147,29 +158,34 @@ static bool ED_operator_screenactive_norender(bContext *C) bool ED_operator_screen_mainwinactive(bContext *C) { bScreen *screen; - if (CTX_wm_window(C) == NULL) + if (CTX_wm_window(C) == NULL) { return 0; + } screen = CTX_wm_screen(C); - if (screen == NULL) + if (screen == NULL) { return 0; - if (screen->active_region != NULL) + } + if (screen->active_region != NULL) { return 0; + } return 1; } bool ED_operator_scene(bContext *C) { Scene *scene = CTX_data_scene(C); - if (scene) + if (scene) { return 1; + } return 0; } bool ED_operator_scene_editable(bContext *C) { Scene *scene = CTX_data_scene(C); - if (scene && !ID_IS_LINKED(scene)) + if (scene && !ID_IS_LINKED(scene)) { return 1; + } return 0; } @@ -178,14 +194,17 @@ bool ED_operator_objectmode(bContext *C) Scene *scene = CTX_data_scene(C); Object *obact = CTX_data_active_object(C); - if (scene == NULL || ID_IS_LINKED(scene)) + if (scene == NULL || ID_IS_LINKED(scene)) { return 0; - if (CTX_data_edit_object(C)) + } + if (CTX_data_edit_object(C)) { return 0; + } /* add a check for ob->mode too? */ - if (obact && (obact->mode != OB_MODE_OBJECT)) + if (obact && (obact->mode != OB_MODE_OBJECT)) { return 0; + } return 1; } @@ -206,8 +225,9 @@ bool ED_operator_view3d_active(bContext *C) bool ED_operator_region_view3d_active(bContext *C) { - if (CTX_wm_region_view3d(C)) + if (CTX_wm_region_view3d(C)) { return true; + } CTX_wm_operator_poll_msg_set(C, "expected a view3d region"); return false; @@ -218,8 +238,9 @@ bool ED_operator_animview_active(bContext *C) { if (ED_operator_areaactive(C)) { SpaceLink *sl = (SpaceLink *)CTX_wm_space_data(C); - if (sl && (ELEM(sl->spacetype, SPACE_SEQ, SPACE_ACTION, SPACE_NLA, SPACE_GRAPH))) + if (sl && (ELEM(sl->spacetype, SPACE_SEQ, SPACE_ACTION, SPACE_NLA, SPACE_GRAPH))) { return true; + } } CTX_wm_operator_poll_msg_set(C, "expected a timeline/animation area to be active"); @@ -236,10 +257,12 @@ bool ED_operator_outliner_active_no_editobject(bContext *C) if (ed_spacetype_test(C, SPACE_OUTLINER)) { Object *ob = ED_object_active_context(C); Object *obedit = CTX_data_edit_object(C); - if (ob && ob == obedit) + if (ob && ob == obedit) { return 0; - else + } + else { return 1; + } } return 0; } @@ -263,8 +286,9 @@ bool ED_operator_node_active(bContext *C) { SpaceNode *snode = CTX_wm_space_node(C); - if (snode && snode->edittree) + if (snode && snode->edittree) { return 1; + } return 0; } @@ -273,8 +297,9 @@ bool ED_operator_node_editable(bContext *C) { SpaceNode *snode = CTX_wm_space_node(C); - if (snode && snode->edittree && !ID_IS_LINKED(snode->edittree)) + if (snode && snode->edittree && !ID_IS_LINKED(snode->edittree)) { return 1; + } return 0; } @@ -348,8 +373,9 @@ bool ED_operator_object_active_editable_font(bContext *C) bool ED_operator_editmesh(bContext *C) { Object *obedit = CTX_data_edit_object(C); - if (obedit && obedit->type == OB_MESH) + if (obedit && obedit->type == OB_MESH) { return NULL != BKE_editmesh_from_object(obedit); + } return 0; } @@ -360,8 +386,9 @@ bool ED_operator_editmesh_view3d(bContext *C) bool ED_operator_editmesh_region_view3d(bContext *C) { - if (ED_operator_editmesh(C) && CTX_wm_region_view3d(C)) + if (ED_operator_editmesh(C) && CTX_wm_region_view3d(C)) { return 1; + } CTX_wm_operator_poll_msg_set(C, "expected a view3d region & editmesh"); return 0; @@ -379,8 +406,9 @@ bool ED_operator_editmesh_auto_smooth(bContext *C) bool ED_operator_editarmature(bContext *C) { Object *obedit = CTX_data_edit_object(C); - if (obedit && obedit->type == OB_ARMATURE) + if (obedit && obedit->type == OB_ARMATURE) { return NULL != ((bArmature *)obedit->data)->edbo; + } return 0; } @@ -482,15 +510,17 @@ bool ED_operator_uvmap(bContext *C) bool ED_operator_editsurfcurve(bContext *C) { Object *obedit = CTX_data_edit_object(C); - if (obedit && ELEM(obedit->type, OB_CURVE, OB_SURF)) + if (obedit && ELEM(obedit->type, OB_CURVE, OB_SURF)) { return NULL != ((Curve *)obedit->data)->editnurb; + } return 0; } bool ED_operator_editsurfcurve_region_view3d(bContext *C) { - if (ED_operator_editsurfcurve(C) && CTX_wm_region_view3d(C)) + if (ED_operator_editsurfcurve(C) && CTX_wm_region_view3d(C)) { return 1; + } CTX_wm_operator_poll_msg_set(C, "expected a view3d region & editcurve"); return 0; @@ -499,8 +529,9 @@ bool ED_operator_editsurfcurve_region_view3d(bContext *C) bool ED_operator_editcurve(bContext *C) { Object *obedit = CTX_data_edit_object(C); - if (obedit && obedit->type == OB_CURVE) + if (obedit && obedit->type == OB_CURVE) { return NULL != ((Curve *)obedit->data)->editnurb; + } return 0; } @@ -518,32 +549,36 @@ bool ED_operator_editcurve_3d(bContext *C) bool ED_operator_editsurf(bContext *C) { Object *obedit = CTX_data_edit_object(C); - if (obedit && obedit->type == OB_SURF) + if (obedit && obedit->type == OB_SURF) { return NULL != ((Curve *)obedit->data)->editnurb; + } return 0; } bool ED_operator_editfont(bContext *C) { Object *obedit = CTX_data_edit_object(C); - if (obedit && obedit->type == OB_FONT) + if (obedit && obedit->type == OB_FONT) { return NULL != ((Curve *)obedit->data)->editfont; + } return 0; } bool ED_operator_editlattice(bContext *C) { Object *obedit = CTX_data_edit_object(C); - if (obedit && obedit->type == OB_LATTICE) + if (obedit && obedit->type == OB_LATTICE) { return NULL != ((Lattice *)obedit->data)->editlatt; + } return 0; } bool ED_operator_editmball(bContext *C) { Object *obedit = CTX_data_edit_object(C); - if (obedit && obedit->type == OB_MBALL) + if (obedit && obedit->type == OB_MBALL) { return NULL != ((MetaBall *)obedit->data)->editelems; + } return 0; } @@ -588,8 +623,9 @@ static bool screen_active_editable(bContext *C) { if (ED_operator_screenactive(C)) { /* no full window splitting allowed */ - if (CTX_wm_screen(C)->state != SCREENNORMAL) + if (CTX_wm_screen(C)->state != SCREENNORMAL) { return 0; + } return 1; } return 0; @@ -658,9 +694,11 @@ static bool actionzone_area_poll(bContext *C) AZone *az; for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { - for (az = sa->actionzones.first; az; az = az->next) - if (BLI_rcti_isect_pt_v(&az->rect, xy)) + for (az = sa->actionzones.first; az; az = az->next) { + if (BLI_rcti_isect_pt_v(&az->rect, xy)) { return 1; + } + } } } return 0; @@ -685,12 +723,56 @@ static void fullscreen_click_rcti_init( BLI_rcti_init(rect, x, x + icon_size, y, y + icon_size); } +static bool azone_clipped_rect_calc(const AZone *az, rcti *r_rect_clip) +{ + const ARegion *ar = az->ar; + *r_rect_clip = az->rect; + if (az->type == AZONE_REGION) { + if (ar->overlap && (ar->v2d.keeptot != V2D_KEEPTOT_STRICT) && + /* Only when this isn't hidden (where it's displayed as an button that expands). */ + ((az->ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) == 0)) { + /* A floating region to be resized, clip by the visible region. */ + switch (az->edge) { + case AE_TOP_TO_BOTTOMRIGHT: + case AE_BOTTOM_TO_TOPLEFT: { + r_rect_clip->xmin = max_ii( + r_rect_clip->xmin, + (ar->winrct.xmin + UI_view2d_view_to_region_x(&ar->v2d, ar->v2d.tot.xmin)) - + UI_REGION_OVERLAP_MARGIN); + r_rect_clip->xmax = min_ii( + r_rect_clip->xmax, + (ar->winrct.xmin + UI_view2d_view_to_region_x(&ar->v2d, ar->v2d.tot.xmax)) + + UI_REGION_OVERLAP_MARGIN); + return true; + } + case AE_LEFT_TO_TOPRIGHT: + case AE_RIGHT_TO_TOPLEFT: { + r_rect_clip->ymin = max_ii( + r_rect_clip->ymin, + (ar->winrct.ymin + UI_view2d_view_to_region_y(&ar->v2d, ar->v2d.tot.ymin)) - + UI_REGION_OVERLAP_MARGIN); + r_rect_clip->ymax = min_ii( + r_rect_clip->ymax, + (ar->winrct.ymin + UI_view2d_view_to_region_y(&ar->v2d, ar->v2d.tot.ymax)) + + UI_REGION_OVERLAP_MARGIN); + return true; + } + } + } + } + return false; +} + static AZone *area_actionzone_refresh_xy(ScrArea *sa, const int xy[2], const bool test_only) { AZone *az = NULL; for (az = sa->actionzones.first; az; az = az->next) { - if (BLI_rcti_isect_pt_v(&az->rect, xy)) { + rcti az_rect_clip; + if (BLI_rcti_isect_pt_v(&az->rect, xy) && + /* Check clipping if this is clipped */ + (!azone_clipped_rect_calc(az, &az_rect_clip) || BLI_rcti_isect_pt_v(&az_rect_clip, xy))) { + if (az->type == AZONE_AREA) { break; } @@ -867,8 +949,9 @@ AZone *ED_area_azones_update(ScrArea *sa, const int xy[2]) static void actionzone_exit(wmOperator *op) { - if (op->customdata) + if (op->customdata) { MEM_freeN(op->customdata); + } op->customdata = NULL; } @@ -883,12 +966,15 @@ static void actionzone_apply(bContext *C, wmOperator *op, int type) wm_event_init_from_window(win, &event); - if (type == AZONE_AREA) + if (type == AZONE_AREA) { event.type = EVT_ACTIONZONE_AREA; - else if (type == AZONE_FULLSCREEN) + } + else if (type == AZONE_FULLSCREEN) { event.type = EVT_ACTIONZONE_FULLSCREEN; - else + } + else { event.type = EVT_ACTIONZONE_REGION; + } event.val = KM_NOTHING; event.customdata = op->customdata; @@ -904,9 +990,11 @@ static int actionzone_invoke(bContext *C, wmOperator *op, const wmEvent *event) AZone *az = screen_actionzone_find_xy(sc, &event->x); sActionzoneData *sad; - /* quick escape - Scroll azones only hide/unhide the scroll-bars, they have their own handling. */ - if (az == NULL || ELEM(az->type, AZONE_REGION_SCROLL)) + /* Quick escape - Scroll azones only hide/unhide the scroll-bars, + * they have their own handling. */ + if (az == NULL || ELEM(az->type, AZONE_REGION_SCROLL)) { return OPERATOR_PASS_THROUGH; + } /* ok we do the action-zone */ sad = op->customdata = MEM_callocN(sizeof(sActionzoneData), "sActionzoneData"); @@ -950,14 +1038,18 @@ static int actionzone_modal(bContext *C, wmOperator *op, const wmEvent *event) const int area_threshold = (0.1 * U.widget_unit); /* Calculate gesture cardinal direction. */ - if (delta_y > ABS(delta_x)) + if (delta_y > ABS(delta_x)) { sad->gesture_dir = 'n'; - else if (delta_x >= ABS(delta_y)) + } + else if (delta_x >= ABS(delta_y)) { sad->gesture_dir = 'e'; - else if (delta_y < -ABS(delta_x)) + } + else if (delta_y < -ABS(delta_x)) { sad->gesture_dir = 's'; - else + } + else { sad->gesture_dir = 'w'; + } if (sad->az->type == AZONE_AREA) { wmWindow *win = CTX_wm_window(C); @@ -978,14 +1070,18 @@ static int actionzone_modal(bContext *C, wmOperator *op, const wmEvent *event) } else { /* Different area, so posible join. */ - if (sad->gesture_dir == 'n') + if (sad->gesture_dir == 'n') { WM_cursor_set(win, BC_N_ARROWCURSOR); - else if (sad->gesture_dir == 's') + } + else if (sad->gesture_dir == 's') { WM_cursor_set(win, BC_S_ARROWCURSOR); - else if (sad->gesture_dir == 'e') + } + else if (sad->gesture_dir == 'e') { WM_cursor_set(win, BC_E_ARROWCURSOR); - else + } + else { WM_cursor_set(win, BC_W_ARROWCURSOR); + } is_gesture = (delta_max > join_threshold); } } @@ -1079,8 +1175,9 @@ static int area_swap_init(wmOperator *op, const wmEvent *event) sAreaSwapData *sd = NULL; sActionzoneData *sad = event->customdata; - if (sad == NULL || sad->sa1 == NULL) + if (sad == NULL || sad->sa1 == NULL) { return 0; + } sd = MEM_callocN(sizeof(sAreaSwapData), "sAreaSwapData"); sd->sa1 = sad->sa1; @@ -1093,8 +1190,9 @@ static int area_swap_init(wmOperator *op, const wmEvent *event) static void area_swap_exit(bContext *C, wmOperator *op) { WM_cursor_modal_restore(CTX_wm_window(C)); - if (op->customdata) + if (op->customdata) { MEM_freeN(op->customdata); + } op->customdata = NULL; } @@ -1106,8 +1204,9 @@ static void area_swap_cancel(bContext *C, wmOperator *op) static int area_swap_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - if (!area_swap_init(op, event)) + if (!area_swap_init(op, event)) { return OPERATOR_PASS_THROUGH; + } /* add modal handler */ WM_cursor_modal_set(CTX_wm_window(C), BC_SWAPAREA_CURSOR); @@ -1195,8 +1294,9 @@ static int area_dupli_invoke(bContext *C, wmOperator *op, const wmEvent *event) if (event->type == EVT_ACTIONZONE_AREA) { sActionzoneData *sad = event->customdata; - if (sad == NULL) + if (sad == NULL) { return OPERATOR_PASS_THROUGH; + } sa = sad->sa1; } @@ -1233,8 +1333,9 @@ static int area_dupli_invoke(bContext *C, wmOperator *op, const wmEvent *event) WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL); finally: - if (event->type == EVT_ACTIONZONE_AREA) + if (event->type == EVT_ACTIONZONE_AREA) { actionzone_exit(op); + } if (newwin) { return OPERATOR_FINISHED; @@ -1324,7 +1425,7 @@ static void area_move_set_limits( int size_max = ED_area_global_max_size_y(area) - 1; size_min = max_ii(size_min, 0); - BLI_assert(size_min < size_max); + BLI_assert(size_min <= size_max); /* logic here is only tested for lower edge :) */ /* left edge */ @@ -1365,35 +1466,43 @@ static void area_move_set_limits( int y1; areamin = areaminy; - if (sa->v1->vec.y > window_rect.ymin) + if (sa->v1->vec.y > window_rect.ymin) { areamin += U.pixelsize; - if (sa->v2->vec.y < (window_rect.ymax - 1)) + } + if (sa->v2->vec.y < (window_rect.ymax - 1)) { areamin += U.pixelsize; + } y1 = screen_geom_area_height(sa) - areamin; /* if top or down edge selected, test height */ - if (sa->v1->editflag && sa->v4->editflag) + if (sa->v1->editflag && sa->v4->editflag) { *bigger = min_ii(*bigger, y1); - else if (sa->v2->editflag && sa->v3->editflag) + } + else if (sa->v2->editflag && sa->v3->editflag) { *smaller = min_ii(*smaller, y1); + } } else { int x1; areamin = AREAMINX; - if (sa->v1->vec.x > window_rect.xmin) + if (sa->v1->vec.x > window_rect.xmin) { areamin += U.pixelsize; - if (sa->v4->vec.x < (window_rect.xmax - 1)) + } + if (sa->v4->vec.x < (window_rect.xmax - 1)) { areamin += U.pixelsize; + } x1 = screen_geom_area_width(sa) - areamin; /* if left or right edge selected, test width */ - if (sa->v1->editflag && sa->v2->editflag) + if (sa->v1->editflag && sa->v2->editflag) { *bigger = min_ii(*bigger, x1); - else if (sa->v3->editflag && sa->v4->editflag) + } + else if (sa->v3->editflag && sa->v4->editflag) { *smaller = min_ii(*smaller, x1); + } } } } @@ -1414,17 +1523,20 @@ static int area_move_init(bContext *C, wmOperator *op) /* setup */ actedge = screen_geom_find_active_scredge(win, sc, x, y); - if (actedge == NULL) + if (actedge == NULL) { return 0; + } md = MEM_callocN(sizeof(sAreaMoveData), "sAreaMoveData"); op->customdata = md; md->dir = screen_geom_edge_is_horizontal(actedge) ? 'h' : 'v'; - if (md->dir == 'h') + if (md->dir == 'h') { md->origval = actedge->v1->vec.y; - else + } + else { md->origval = actedge->v1->vec.x; + } screen_geom_select_connected_edge(win, actedge); /* now all vertices with 'flag == 1' are the ones that can be moved. Move this to editflag */ @@ -1623,8 +1735,9 @@ static void area_move_apply(bContext *C, wmOperator *op) static void area_move_exit(bContext *C, wmOperator *op) { - if (op->customdata) + if (op->customdata) { MEM_freeN(op->customdata); + } op->customdata = NULL; /* this makes sure aligned edges will result in aligned grabbing */ @@ -1636,8 +1749,9 @@ static void area_move_exit(bContext *C, wmOperator *op) static int area_move_exec(bContext *C, wmOperator *op) { - if (!area_move_init(C, op)) + if (!area_move_init(C, op)) { return OPERATOR_CANCELLED; + } area_move_apply(C, op); area_move_exit(C, op); @@ -1651,8 +1765,9 @@ static int area_move_invoke(bContext *C, wmOperator *op, const wmEvent *event) RNA_int_set(op->ptr, "x", event->x); RNA_int_set(op->ptr, "y", event->y); - if (!area_move_init(C, op)) + if (!area_move_init(C, op)) { return OPERATOR_PASS_THROUGH; + } G.moving |= G_TRANSFORM_WM; @@ -1830,17 +1945,20 @@ static int area_split_init(bContext *C, wmOperator *op) int dir; /* required context */ - if (sa == NULL) + if (sa == NULL) { return 0; + } /* required properties */ dir = RNA_enum_get(op->ptr, "direction"); /* minimal size */ - if (dir == 'v' && sa->winx < 2 * AREAMINX) + if (dir == 'v' && sa->winx < 2 * AREAMINX) { return 0; - if (dir == 'h' && sa->winy < 2 * areaminy) + } + if (dir == 'h' && sa->winy < 2 * areaminy) { return 0; + } /* custom data */ sd = (sAreaSplitData *)MEM_callocN(sizeof(sAreaSplitData), "op_area_split"); @@ -1914,10 +2032,12 @@ static int area_split_apply(bContext *C, wmOperator *op) sd->nedge->v1->editflag = 1; sd->nedge->v2->editflag = 1; - if (dir == 'h') + if (dir == 'h') { sd->origval = sd->nedge->v1->vec.y; - else + } + else { sd->origval = sd->nedge->v1->vec.x; + } ED_area_tag_redraw(sd->sarea); ED_area_tag_redraw(sd->narea); @@ -1936,13 +2056,16 @@ static void area_split_exit(bContext *C, wmOperator *op) { if (op->customdata) { sAreaSplitData *sd = (sAreaSplitData *)op->customdata; - if (sd->sarea) + if (sd->sarea) { ED_area_tag_redraw(sd->sarea); - if (sd->narea) + } + if (sd->narea) { ED_area_tag_redraw(sd->narea); + } - if (sd->draw_callback) + if (sd->draw_callback) { WM_draw_cb_exit(CTX_wm_window(C), sd->draw_callback); + } MEM_freeN(op->customdata); op->customdata = NULL; @@ -1986,12 +2109,14 @@ static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event) } /* verify *sad itself */ - if (sad->sa1 == NULL || sad->az == NULL) + if (sad->sa1 == NULL || sad->az == NULL) { return OPERATOR_PASS_THROUGH; + } /* is this our *sad? if areas not equal it should be passed on */ - if (CTX_wm_area(C) != sad->sa1 || sad->sa1 != sad->sa2) + if (CTX_wm_area(C) != sad->sa1 || sad->sa1 != sad->sa2) { return OPERATOR_PASS_THROUGH; + } /* The factor will be close to 1.0f when near the top-left and the bottom-right corners. */ const float factor_v = ((float)(event->y - sad->sa1->v1->vec.y)) / (float)sad->sa1->winy; @@ -2106,8 +2231,9 @@ static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event) static int area_split_exec(bContext *C, wmOperator *op) { - if (!area_split_init(C, op)) + if (!area_split_init(C, op)) { return OPERATOR_CANCELLED; + } area_split_apply(C, op); area_split_exit(C, op); @@ -2327,8 +2453,9 @@ static int area_max_regionsize(ScrArea *sa, ARegion *scalear, AZEdge edge) /* subtractwidth of regions on opposite side * prevents dragging regions into other opposite regions */ for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) { - if (ar == scalear) + if (ar == scalear) { continue; + } if (scalear->alignment == RGN_ALIGN_LEFT && ar->alignment == RGN_ALIGN_RIGHT) { dist -= ar->winx; @@ -2338,12 +2465,12 @@ static int area_max_regionsize(ScrArea *sa, ARegion *scalear, AZEdge edge) } else if (scalear->alignment == RGN_ALIGN_TOP && (ar->alignment == RGN_ALIGN_BOTTOM || - ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_FOOTER))) { + ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER, RGN_TYPE_FOOTER))) { dist -= ar->winy; } else if (scalear->alignment == RGN_ALIGN_BOTTOM && (ar->alignment == RGN_ALIGN_TOP || - ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_FOOTER))) { + ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER, RGN_TYPE_FOOTER))) { dist -= ar->winy; } } @@ -2379,10 +2506,12 @@ static int region_scale_invoke(bContext *C, wmOperator *op, const wmEvent *event rmd->maxsize = area_max_regionsize(rmd->sa, rmd->ar, rmd->edge); /* if not set we do now, otherwise it uses type */ - if (rmd->ar->sizex == 0) + if (rmd->ar->sizex == 0) { rmd->ar->sizex = rmd->ar->winx; - if (rmd->ar->sizey == 0) + } + if (rmd->ar->sizey == 0) { rmd->ar->sizey = rmd->ar->winy; + } /* now copy to regionmovedata */ if (rmd->edge == AE_LEFT_TO_TOPRIGHT || rmd->edge == AE_RIGHT_TO_TOPLEFT) { @@ -2408,15 +2537,18 @@ static void region_scale_validate_size(RegionMoveData *rmd) if ((rmd->ar->flag & RGN_FLAG_HIDDEN) == 0) { short *size, maxsize = -1; - if (rmd->edge == AE_LEFT_TO_TOPRIGHT || rmd->edge == AE_RIGHT_TO_TOPLEFT) + if (rmd->edge == AE_LEFT_TO_TOPRIGHT || rmd->edge == AE_RIGHT_TO_TOPLEFT) { size = &rmd->ar->sizex; - else + } + else { size = &rmd->ar->sizey; + } maxsize = rmd->maxsize - (UI_UNIT_Y / UI_DPI_FAC); - if (*size > maxsize && maxsize > 0) + if (*size > maxsize && maxsize > 0) { *size = maxsize; + } } } @@ -2430,6 +2562,18 @@ static void region_scale_toggle_hidden(bContext *C, RegionMoveData *rmd) region_toggle_hidden(C, rmd->ar, 0); region_scale_validate_size(rmd); + + if ((rmd->ar->flag & RGN_FLAG_HIDDEN) == 0) { + if (rmd->ar->regiontype == RGN_TYPE_HEADER) { + ARegion *ar_tool_header = BKE_area_find_region_type(rmd->sa, RGN_TYPE_TOOL_HEADER); + if (ar_tool_header != NULL) { + if ((ar_tool_header->flag & RGN_FLAG_HIDDEN_BY_USER) == 0 && + (ar_tool_header->flag & RGN_FLAG_HIDDEN) != 0) { + region_toggle_hidden(C, ar_tool_header, 0); + } + } + } + } } static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event) @@ -2445,8 +2589,9 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event) const int snap_size_threshold = (U.widget_unit * 2) / aspect; if (rmd->edge == AE_LEFT_TO_TOPRIGHT || rmd->edge == AE_RIGHT_TO_TOPLEFT) { delta = event->x - rmd->origx; - if (rmd->edge == AE_LEFT_TO_TOPRIGHT) + if (rmd->edge == AE_LEFT_TO_TOPRIGHT) { delta = -delta; + } /* region sizes now get multiplied */ delta /= UI_DPI_FAC; @@ -2463,8 +2608,9 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event) if (rmd->ar->sizex < UI_UNIT_X) { rmd->ar->sizex = rmd->origval; - if (!(rmd->ar->flag & RGN_FLAG_HIDDEN)) + if (!(rmd->ar->flag & RGN_FLAG_HIDDEN)) { region_scale_toggle_hidden(C, rmd); + } } else if (rmd->ar->flag & RGN_FLAG_HIDDEN) { region_scale_toggle_hidden(C, rmd); @@ -2475,8 +2621,9 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event) } else { delta = event->y - rmd->origy; - if (rmd->edge == AE_BOTTOM_TO_TOPLEFT) + if (rmd->edge == AE_BOTTOM_TO_TOPLEFT) { delta = -delta; + } /* region sizes now get multiplied */ delta /= UI_DPI_FAC; @@ -2496,8 +2643,9 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event) * otherwise its too easy to do this by accident */ if (rmd->ar->sizey < UI_UNIT_Y / 4) { rmd->ar->sizey = rmd->origval; - if (!(rmd->ar->flag & RGN_FLAG_HIDDEN)) + if (!(rmd->ar->flag & RGN_FLAG_HIDDEN)) { region_scale_toggle_hidden(C, rmd); + } } else if (rmd->ar->flag & RGN_FLAG_HIDDEN) { region_scale_toggle_hidden(C, rmd); @@ -2667,16 +2815,20 @@ static int frame_jump_exec(bContext *C, wmOperator *op) sad->flag |= ANIMPLAY_FLAG_USE_NEXT_FRAME; - if (RNA_boolean_get(op->ptr, "end")) + if (RNA_boolean_get(op->ptr, "end")) { sad->nextfra = PEFRA; - else + } + else { sad->nextfra = PSFRA; + } } else { - if (RNA_boolean_get(op->ptr, "end")) + if (RNA_boolean_get(op->ptr, "end")) { CFRA = PEFRA; - else + } + else { CFRA = PSFRA; + } areas_do_frame_follow(C, true); @@ -2724,8 +2876,9 @@ static int keyframe_jump_exec(bContext *C, wmOperator *op) bool done = false; /* sanity checks */ - if (scene == NULL) + if (scene == NULL) { return OPERATOR_CANCELLED; + } cfra = (float)(CFRA); @@ -2759,10 +2912,12 @@ static int keyframe_jump_exec(bContext *C, wmOperator *op) } /* find matching keyframe in the right direction */ - if (next) + if (next) { ak = (ActKeyColumn *)BLI_dlrbTree_search_next(&keys, compare_ak_cfraPtr, &cfra); - else + } + else { ak = (ActKeyColumn *)BLI_dlrbTree_search_prev(&keys, compare_ak_cfraPtr, &cfra); + } while ((ak != NULL) && (done == false)) { if (CFRA != (int)ak->cfra) { @@ -2932,8 +3087,9 @@ static int screen_maximize_area_exec(bContext *C, wmOperator *op) /* search current screen for 'fullscreen' areas */ /* prevents restoring info header, when mouse is over it */ for (sa = screen->areabase.first; sa; sa = sa->next) { - if (sa->full) + if (sa->full) { break; + } } if (sa == NULL) { @@ -3082,8 +3238,9 @@ static int area_join_init(bContext *C, wmOperator *op) static int area_join_apply(bContext *C, wmOperator *op) { sAreaJoinData *jd = (sAreaJoinData *)op->customdata; - if (!jd) + if (!jd) { return 0; + } if (!screen_area_join(C, CTX_wm_screen(C), jd->sa1, jd->sa2)) { return 0; @@ -3102,8 +3259,9 @@ static void area_join_exit(bContext *C, wmOperator *op) sAreaJoinData *jd = (sAreaJoinData *)op->customdata; if (jd) { - if (jd->draw_callback) + if (jd->draw_callback) { WM_draw_cb_exit(CTX_wm_window(C), jd->draw_callback); + } MEM_freeN(jd); op->customdata = NULL; @@ -3117,8 +3275,9 @@ static void area_join_exit(bContext *C, wmOperator *op) static int area_join_exec(bContext *C, wmOperator *op) { - if (!area_join_init(C, op)) + if (!area_join_init(C, op)) { return OPERATOR_CANCELLED; + } area_join_apply(C, op); area_join_exit(C, op); @@ -3138,12 +3297,14 @@ static int area_join_invoke(bContext *C, wmOperator *op, const wmEvent *event) } /* verify *sad itself */ - if (sad->sa1 == NULL || sad->sa2 == NULL) + if (sad->sa1 == NULL || sad->sa2 == NULL) { return OPERATOR_PASS_THROUGH; + } /* is this our *sad? if areas equal it should be passed on */ - if (sad->sa1 == sad->sa2) + if (sad->sa1 == sad->sa2) { return OPERATOR_PASS_THROUGH; + } /* prepare operator state vars */ RNA_int_set(op->ptr, "min_x", sad->sa1->totrct.xmin); @@ -3152,8 +3313,9 @@ static int area_join_invoke(bContext *C, wmOperator *op, const wmEvent *event) RNA_int_set(op->ptr, "max_y", sad->sa2->totrct.ymin); } - if (!area_join_init(C, op)) + if (!area_join_init(C, op)) { return OPERATOR_CANCELLED; + } /* add temp handler */ WM_event_add_modal_handler(C, op); @@ -3225,16 +3387,21 @@ static int area_join_modal(bContext *C, wmOperator *op, const wmEvent *event) } } - if (dir == 1) + if (dir == 1) { WM_cursor_set(win, BC_N_ARROWCURSOR); - else if (dir == 3) + } + else if (dir == 3) { WM_cursor_set(win, BC_S_ARROWCURSOR); - else if (dir == 2) + } + else if (dir == 2) { WM_cursor_set(win, BC_E_ARROWCURSOR); - else if (dir == 0) + } + else if (dir == 0) { WM_cursor_set(win, BC_W_ARROWCURSOR); - else + } + else { WM_cursor_set(win, BC_STOPCURSOR); + } break; } @@ -3304,8 +3471,9 @@ static int screen_area_options_invoke(bContext *C, wmOperator *op, const wmEvent actedge = screen_geom_area_map_find_active_scredge( AREAMAP_FROM_SCREEN(sc), &window_rect, event->x, event->y); - if (actedge == NULL) + if (actedge == NULL) { return OPERATOR_CANCELLED; + } pup = UI_popup_menu_begin(C, RNA_struct_ui_name(op->type->srna), ICON_NONE); layout = UI_popup_menu_layout(pup); @@ -3442,17 +3610,19 @@ static int repeat_history_invoke(bContext *C, wmOperator *op, const wmEvent *UNU int items, i; items = BLI_listbase_count(&wm->operators); - if (items == 0) + if (items == 0) { return OPERATOR_CANCELLED; + } pup = UI_popup_menu_begin(C, RNA_struct_ui_name(op->type->srna), ICON_NONE); layout = UI_popup_menu_layout(pup); - for (i = items - 1, lastop = wm->operators.last; lastop; lastop = lastop->prev, i--) + for (i = items - 1, lastop = wm->operators.last; lastop; lastop = lastop->prev, i--) { if ((lastop->type->flag & OPTYPE_REGISTER) && WM_operator_repeat_check(C, lastop)) { uiItemIntO( layout, RNA_struct_ui_name(lastop->type->srna), ICON_NONE, op->type->idname, "index", i); } + } UI_popup_menu_end(C, pup); @@ -3501,8 +3671,9 @@ static int redo_last_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent * { wmOperator *lastop = WM_operator_last_redo(C); - if (lastop) + if (lastop) { WM_operator_redo_popup(C, lastop); + } return OPERATOR_CANCELLED; } @@ -3660,8 +3831,10 @@ static int region_quadview_exec(bContext *C, wmOperator *op) RV3D_ORTHO); /* forcing camera is distracting */ #if 0 - if (v3d->camera) region_quadview_init_rv3d(sa, (ar = ar->next), 0, RV3D_VIEW_CAMERA, RV3D_CAMOB); - else region_quadview_init_rv3d(sa, (ar = ar->next), 0, RV3D_VIEW_USER, RV3D_PERSP); + if (v3d->camera) + region_quadview_init_rv3d(sa, (ar = ar->next), 0, RV3D_VIEW_CAMERA, RV3D_CAMOB); + else + region_quadview_init_rv3d(sa, (ar = ar->next), 0, RV3D_VIEW_USER, RV3D_PERSP); #else (void)v3d; #endif @@ -3697,17 +3870,22 @@ static int region_flip_exec(bContext *C, wmOperator *UNUSED(op)) { ARegion *ar = CTX_wm_region(C); - if (!ar) + if (!ar) { return OPERATOR_CANCELLED; + } - if (ar->alignment == RGN_ALIGN_TOP) + if (ar->alignment == RGN_ALIGN_TOP) { ar->alignment = RGN_ALIGN_BOTTOM; - else if (ar->alignment == RGN_ALIGN_BOTTOM) + } + else if (ar->alignment == RGN_ALIGN_BOTTOM) { ar->alignment = RGN_ALIGN_TOP; - else if (ar->alignment == RGN_ALIGN_LEFT) + } + else if (ar->alignment == RGN_ALIGN_LEFT) { ar->alignment = RGN_ALIGN_RIGHT; - else if (ar->alignment == RGN_ALIGN_RIGHT) + } + else if (ar->alignment == RGN_ALIGN_RIGHT) { ar->alignment = RGN_ALIGN_LEFT; + } ED_area_tag_redraw(CTX_wm_area(C)); WM_event_add_mousemove(C); @@ -3745,40 +3923,6 @@ static void SCREEN_OT_region_flip(wmOperatorType *ot) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Header Toggle Operator - * \{ */ - -static int header_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ARegion *ar = screen_find_region_type(C, RGN_TYPE_HEADER); - - if (ar == NULL) { - return OPERATOR_CANCELLED; - } - - ar->flag ^= RGN_FLAG_HIDDEN; - - ED_area_tag_redraw(CTX_wm_area(C)); - - WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL); - - return OPERATOR_FINISHED; -} - -static void SCREEN_OT_header(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Toggle Header"; - ot->description = "Toggle header display"; - ot->idname = "SCREEN_OT_header"; - - /* api callbacks */ - ot->exec = header_exec; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Header Toggle Menu Operator * \{ */ @@ -3826,9 +3970,25 @@ void ED_screens_header_tools_menu_create(bContext *C, uiLayout *layout, void *UN ARegion *ar = CTX_wm_region(C); const char *but_flip_str = (ar->alignment == RGN_ALIGN_TOP) ? IFACE_("Flip to Bottom") : IFACE_("Flip to Top"); + { + PointerRNA ptr; + RNA_pointer_create((ID *)CTX_wm_screen(C), &RNA_Space, sa->spacedata.first, &ptr); + uiItemR(layout, &ptr, "show_region_header", 0, IFACE_("Show Header"), ICON_NONE); - if (!ELEM(sa->spacetype, SPACE_TOPBAR)) { - uiItemO(layout, IFACE_("Toggle Header"), ICON_NONE, "SCREEN_OT_header"); + ARegion *ar_header = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); + uiLayout *col = uiLayoutColumn(layout, 0); + uiLayoutSetActive(col, (ar_header->flag & RGN_FLAG_HIDDEN) == 0); + + if (BKE_area_find_region_type(sa, RGN_TYPE_TOOL_HEADER)) { + uiItemR(col, &ptr, "show_region_tool_header", 0, IFACE_("Show Tool Settings"), ICON_NONE); + } + + uiItemO(col, + IFACE_("Show Menus"), + (sa->flag & HEADER_NO_PULLDOWN) ? ICON_CHECKBOX_DEHLT : ICON_CHECKBOX_HLT, + "SCREEN_OT_header_toggle_menus"); + + uiItemS(layout); } /* default is WM_OP_INVOKE_REGION_WIN, which we don't want here. */ @@ -3838,11 +3998,6 @@ void ED_screens_header_tools_menu_create(bContext *C, uiLayout *layout, void *UN uiItemO(layout, but_flip_str, ICON_NONE, "SCREEN_OT_region_flip"); } - uiItemO(layout, - IFACE_("Collapse Menus"), - (sa->flag & HEADER_NO_PULLDOWN) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT, - "SCREEN_OT_header_toggle_menus"); - /* File browser should be fullscreen all the time, top-bar should * never be. But other regions can be maximized/restored. */ if (!ELEM(sa->spacetype, SPACE_FILE, SPACE_TOPBAR)) { @@ -4011,8 +4166,9 @@ static int match_area_with_refresh(int spacetype, int refresh) { switch (spacetype) { case SPACE_TIME: - if (refresh & SPACE_TIME) + if (refresh & SPACE_TIME) { return 1; + } break; } @@ -4028,40 +4184,48 @@ static int match_region_with_redraws(int spacetype, switch (spacetype) { case SPACE_VIEW3D: - if ((redraws & TIME_ALL_3D_WIN) || from_anim_edit) + if ((redraws & TIME_ALL_3D_WIN) || from_anim_edit) { return 1; + } break; case SPACE_GRAPH: case SPACE_NLA: - if ((redraws & TIME_ALL_ANIM_WIN) || from_anim_edit) + if ((redraws & TIME_ALL_ANIM_WIN) || from_anim_edit) { return 1; + } break; case SPACE_ACTION: /* if only 1 window or 3d windows, we do timeline too * NOTE: Now we do do action editor in all these cases, since timeline is here */ - if ((redraws & (TIME_ALL_ANIM_WIN | TIME_REGION | TIME_ALL_3D_WIN)) || from_anim_edit) + if ((redraws & (TIME_ALL_ANIM_WIN | TIME_REGION | TIME_ALL_3D_WIN)) || from_anim_edit) { return 1; + } break; case SPACE_PROPERTIES: - if (redraws & TIME_ALL_BUTS_WIN) + if (redraws & TIME_ALL_BUTS_WIN) { return 1; + } break; case SPACE_SEQ: - if ((redraws & (TIME_SEQ | TIME_ALL_ANIM_WIN)) || from_anim_edit) + if ((redraws & (TIME_SEQ | TIME_ALL_ANIM_WIN)) || from_anim_edit) { return 1; + } break; case SPACE_NODE: - if (redraws & (TIME_NODES)) + if (redraws & (TIME_NODES)) { return 1; + } break; case SPACE_IMAGE: - if ((redraws & TIME_ALL_IMAGE_WIN) || from_anim_edit) + if ((redraws & TIME_ALL_IMAGE_WIN) || from_anim_edit) { return 1; + } break; case SPACE_CLIP: - if ((redraws & TIME_CLIPS) || from_anim_edit) + if ((redraws & TIME_CLIPS) || from_anim_edit) { return 1; + } break; } } @@ -4070,8 +4234,9 @@ static int match_region_with_redraws(int spacetype, case SPACE_GRAPH: case SPACE_ACTION: case SPACE_NLA: - if (redraws & TIME_ALL_ANIM_WIN) + if (redraws & TIME_ALL_ANIM_WIN) { return 1; + } break; } } @@ -4085,18 +4250,21 @@ static int match_region_with_redraws(int spacetype, return 1; } - if (redraws & TIME_ALL_BUTS_WIN) + if (redraws & TIME_ALL_BUTS_WIN) { return 1; + } } - else if (regiontype == RGN_TYPE_HEADER) { - if (spacetype == SPACE_ACTION) + else if (ELEM(regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER)) { + if (spacetype == SPACE_ACTION) { return 1; + } } else if (regiontype == RGN_TYPE_PREVIEW) { switch (spacetype) { case SPACE_SEQ: - if (redraws & (TIME_SEQ | TIME_ALL_ANIM_WIN)) + if (redraws & (TIME_SEQ | TIME_ALL_ANIM_WIN)) { return 1; + } break; case SPACE_CLIP: return 1; @@ -4129,22 +4297,27 @@ static int screen_animation_step(bContext *C, wmOperator *UNUSED(op), const wmEv float time; /* sync, don't sync, or follow scene setting */ - if (sad->flag & ANIMPLAY_FLAG_SYNC) + if (sad->flag & ANIMPLAY_FLAG_SYNC) { sync = 1; - else if (sad->flag & ANIMPLAY_FLAG_NO_SYNC) + } + else if (sad->flag & ANIMPLAY_FLAG_NO_SYNC) { sync = 0; - else + } + else { sync = (scene->flag & SCE_FRAME_DROP); + } if ((scene->audio.flag & AUDIO_SYNC) && (sad->flag & ANIMPLAY_FLAG_REVERSE) == false && isfinite(time = BKE_sound_sync_scene(scene))) { double newfra = (double)time * FPS; /* give some space here to avoid jumps */ - if (newfra + 0.5 > scene->r.cfra && newfra - 0.5 < scene->r.cfra) + if (newfra + 0.5 > scene->r.cfra && newfra - 0.5 < scene->r.cfra) { scene->r.cfra++; - else + } + else { scene->r.cfra = newfra + 0.5; + } #ifdef PROFILE_AUDIO_SYNCH newfra_int = scene->r.cfra; @@ -4166,17 +4339,21 @@ static int screen_animation_step(bContext *C, wmOperator *UNUSED(op), const wmEv const int step = max_ii(1, floor((wt->duration - sad->last_duration) * FPS)); /* skip frames */ - if (sad->flag & ANIMPLAY_FLAG_REVERSE) + if (sad->flag & ANIMPLAY_FLAG_REVERSE) { scene->r.cfra -= step; - else + } + else { scene->r.cfra += step; + } } else { /* one frame +/- */ - if (sad->flag & ANIMPLAY_FLAG_REVERSE) + if (sad->flag & ANIMPLAY_FLAG_REVERSE) { scene->r.cfra--; - else + } + else { scene->r.cfra++; + } } } @@ -4269,8 +4446,9 @@ static int screen_animation_step(bContext *C, wmOperator *UNUSED(op), const wmEv } } - if (match_area_with_refresh(sa->spacetype, sad->refresh)) + if (match_area_with_refresh(sa->spacetype, sad->refresh)) { ED_area_tag_refresh(sa); + } } } @@ -4283,7 +4461,8 @@ static int screen_animation_step(bContext *C, wmOperator *UNUSED(op), const wmEv /* Recalculate the time-step for the timer now that we've finished calculating this, * since the frames-per-second value may have been changed. */ - /* TODO: this may make evaluation a bit slower if the value doesn't change... any way to avoid this? */ + /* TODO: this may make evaluation a bit slower if the value doesn't change... + * any way to avoid this? */ wt->timestep = (1.0 / FPS); return OPERATOR_FINISHED; @@ -4356,8 +4535,9 @@ int ED_screen_animation_play(bContext *C, int sync, int mode) /* these settings are currently only available from a menu in the TimeLine */ int refresh = SPACE_ACTION; - if (mode == 1) /* XXX only play audio forwards!? */ + if (mode == 1) { /* XXX only play audio forwards!? */ BKE_sound_play_scene(scene); + } ED_screen_animation_timer(C, screen->redraws_flag, refresh, sync, mode); @@ -4377,8 +4557,9 @@ static int screen_animation_play_exec(bContext *C, wmOperator *op) int mode = (RNA_boolean_get(op->ptr, "reverse")) ? -1 : 1; int sync = -1; - if (RNA_struct_property_is_set(op->ptr, "sync")) + if (RNA_struct_property_is_set(op->ptr, "sync")) { sync = (RNA_boolean_get(op->ptr, "sync")); + } return ED_screen_animation_play(C, sync, mode); } @@ -4527,8 +4708,9 @@ static int fullscreen_back_exec(bContext *C, wmOperator *op) /* search current screen for 'fullscreen' areas */ for (sa = screen->areabase.first; sa; sa = sa->next) { - if (sa->full) + if (sa->full) { break; + } } if (!sa) { BKE_report(op->reports, RPT_ERROR, "No fullscreen areas were found"); @@ -4629,7 +4811,8 @@ static int drivers_editor_show_invoke(bContext *C, wmOperator *op, const wmEvent ANIM_set_active_channel(&ac, ac.data, ac.datatype, filter, fcu, ANIMTYPE_FCURVE); } else { - /* Just blindly isolate... This isn't the best, and shouldn't happen, but may be enough... */ + /* Just blindly isolate... + * This isn't the best, and shouldn't happen, but may be enough. */ fcu->flag |= (FCURVE_ACTIVE | FCURVE_SELECTED); } } @@ -4719,12 +4902,13 @@ static void SCREEN_OT_delete(wmOperatorType *ot) /* -------------------------------------------------------------------- */ /** \name Region Alpha Blending Operator + * + * Implementation note: a disappearing region needs at least 1 last draw with + * 100% backbuffer texture over it - then triple buffer will clear it entirely. + * This because flag #RGN_FLAG_HIDDEN is set in end - region doesn't draw at all then. + * * \{ */ -/* implementation note: a disappearing region needs at least 1 last draw with 100% backbuffer - * texture over it- then triple buffer will clear it entirely. - * This because flag RGN_HIDDEN is set in end - region doesn't draw at all then */ - typedef struct RegionAlphaInfo { ScrArea *sa; ARegion *ar, *child_ar; /* other region */ @@ -4747,8 +4931,9 @@ float ED_region_blend_alpha(ARegion *ar) alpha = (float)ar->regiontimer->duration / TIMEOUT; /* makes sure the blend out works 100% - without area redraws */ - if (rgi->hidden) + if (rgi->hidden) { alpha = 0.9f - TIMESTEP - alpha; + } CLAMP(alpha, 0.0f, 1.0f); return alpha; @@ -4763,13 +4948,15 @@ static void region_blend_end(bContext *C, ARegion *ar, const bool is_running) /* always send redraw */ ED_region_tag_redraw(ar); - if (rgi->child_ar) + if (rgi->child_ar) { ED_region_tag_redraw(rgi->child_ar); + } /* if running timer was hiding, the flag toggle went wrong */ if (is_running) { - if (rgi->hidden) + if (rgi->hidden) { rgi->ar->flag &= ~RGN_FLAG_HIDDEN; + } } else { if (rgi->hidden) { @@ -4783,7 +4970,7 @@ static void region_blend_end(bContext *C, ARegion *ar, const bool is_running) ar->regiontimer = NULL; } /* assumes that *ar itself is not a splitted version from previous region */ -void region_blend_start(bContext *C, ScrArea *sa, ARegion *ar) +void ED_region_visibility_change_update_animated(bContext *C, ScrArea *sa, ARegion *ar) { wmWindowManager *wm = CTX_wm_manager(C); wmWindow *win = CTX_wm_window(C); @@ -4802,10 +4989,12 @@ void region_blend_start(bContext *C, ScrArea *sa, ARegion *ar) ar->flag &= ~RGN_FLAG_HIDDEN; /* blend in, reinitialize regions because it got unhidden */ - if (rgi->hidden == 0) + if (rgi->hidden == 0) { ED_area_initialize(wm, win, sa); - else + } + else { WM_event_remove_handlers(C, &ar->handlers); + } if (ar->next) { if (ar->next->alignment & RGN_SPLIT_PREV) { @@ -4825,15 +5014,17 @@ static int region_blend_invoke(bContext *C, wmOperator *UNUSED(op), const wmEven wmTimer *timer = event->customdata; /* event type is TIMERREGION, but we better check */ - if (event->type != TIMERREGION || timer == NULL) + if (event->type != TIMERREGION || timer == NULL) { return OPERATOR_PASS_THROUGH; + } rgi = timer->customdata; /* always send redraws */ ED_region_tag_redraw(rgi->ar); - if (rgi->child_ar) + if (rgi->child_ar) { ED_region_tag_redraw(rgi->child_ar); + } /* end timer? */ if (rgi->ar->regiontimer->duration > (double)TIMEOUT) { @@ -5107,7 +5298,6 @@ void ED_operatortypes_screen(void) WM_operatortype_append(SCREEN_OT_region_quadview); WM_operatortype_append(SCREEN_OT_region_scale); WM_operatortype_append(SCREEN_OT_region_flip); - WM_operatortype_append(SCREEN_OT_header); WM_operatortype_append(SCREEN_OT_header_toggle_menus); WM_operatortype_append(SCREEN_OT_header_context_menu); WM_operatortype_append(SCREEN_OT_footer); @@ -5177,8 +5367,9 @@ static bool blend_file_drop_poll(bContext *UNUSED(C), const char **UNUSED(tooltip)) { if (drag->type == WM_DRAG_PATH) { - if (drag->icon == ICON_FILE_BLEND) + if (drag->icon == ICON_FILE_BLEND) { return 1; + } } return 0; } diff --git a/source/blender/editors/screen/screendump.c b/source/blender/editors/screen/screendump.c index 37ffdef0b9b..3b763c7d47a 100644 --- a/source/blender/editors/screen/screendump.c +++ b/source/blender/editors/screen/screendump.c @@ -71,8 +71,9 @@ static void screenshot_read_pixels(int x, int y, int w, int h, unsigned char *re glFinish(); /* clear alpha, it is not set to a meaningful value in opengl */ - for (i = 0, rect += 3; i < w * h; i++, rect += 4) + for (i = 0, rect += 3; i < w * h; i++, rect += 4) { *rect = 255; + } } /* get shot from frontbuffer */ @@ -137,8 +138,9 @@ static void screenshot_data_free(wmOperator *op) ScreenshotData *scd = op->customdata; if (scd) { - if (scd->dumprect) + if (scd->dumprect) { MEM_freeN(scd->dumprect); + } MEM_freeN(scd); op->customdata = NULL; } @@ -153,8 +155,9 @@ static void screenshot_crop(ImBuf *ibuf, rcti crop) int y; if (crop_x > 0 && crop_y > 0) { - for (y = 0; y < crop_y; y++, to += crop_x, from += ibuf->x) + for (y = 0; y < crop_y; y++, to += crop_x, from += ibuf->x) { memmove(to, from, sizeof(unsigned int) * crop_x); + } ibuf->x = crop_x; ibuf->y = crop_y; @@ -185,8 +188,9 @@ static int screenshot_exec(bContext *C, wmOperator *op) ibuf->rect = scd->dumprect; /* crop to show only single editor */ - if (!RNA_boolean_get(op->ptr, "full")) + if (!RNA_boolean_get(op->ptr, "full")) { screenshot_crop(ibuf, scd->crop); + } if (scd->im_format.planes == R_IMF_PLANES_BW) { /* bw screenshot? - users will notice if it fails! */ @@ -211,8 +215,9 @@ static int screenshot_exec(bContext *C, wmOperator *op) static int screenshot_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { if (screenshot_data_create(C, op)) { - if (RNA_struct_property_is_set(op->ptr, "filepath")) + if (RNA_struct_property_is_set(op->ptr, "filepath")) { return screenshot_exec(C, op); + } /* extension is added by 'screenshot_check' after */ char filepath[FILE_MAX] = "//screen"; @@ -267,8 +272,9 @@ static void screenshot_draw(bContext *UNUSED(C), wmOperator *op) static bool screenshot_poll(bContext *C) { - if (G.background) + if (G.background) { return false; + } return WM_operator_winactive(C); } diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c index 5750a1f36a7..6294a64af0f 100644 --- a/source/blender/editors/screen/workspace_edit.c +++ b/source/blender/editors/screen/workspace_edit.c @@ -89,8 +89,7 @@ static void workspace_change_update(WorkSpace *workspace_new, /* needs to be done before changing mode! (to ensure right context) */ UNUSED_VARS(workspace_old, workspace_new, C, wm); #if 0 - Object *ob_act = CTX_data_active_object(C) - eObjectMode mode_old = workspace_old->object_mode; + Object *ob_act = CTX_data_active_object(C) eObjectMode mode_old = workspace_old->object_mode; eObjectMode mode_new = workspace_new->object_mode; if (mode_old != mode_new) { @@ -110,7 +109,8 @@ static WorkSpaceLayout *workspace_change_get_new_layout(Main *bmain, WorkSpace *workspace_new, wmWindow *win) { - /* ED_workspace_duplicate may have stored a layout to activate once the workspace gets activated. */ + /* ED_workspace_duplicate may have stored a layout to activate + * once the workspace gets activated. */ WorkSpaceLayout *layout_old = WM_window_get_active_layout(win); WorkSpaceLayout *layout_new; bScreen *screen_new; @@ -159,7 +159,8 @@ bool ED_workspace_change(WorkSpace *workspace_new, bContext *C, wmWindowManager win->workspace_hook->temp_layout_store = NULL; if (workspace_old == workspace_new) { - /* Could also return true, everything that needs to be done was done (nothing :P), but nothing changed */ + /* Could also return true, everything that needs to be done was done (nothing :P), + * but nothing changed */ return false; } diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt index cddaf69b965..23617e687ea 100644 --- a/source/blender/editors/sculpt_paint/CMakeLists.txt +++ b/source/blender/editors/sculpt_paint/CMakeLists.txt @@ -29,8 +29,8 @@ set(INC ../../makesrna ../../render/extern/include ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index da183d190fa..65e24cecf82 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -96,12 +96,15 @@ static CursorSnapshot cursor_snap = {0}; /* delete overlay cursor textures to preserve memory and invalidate all overlay flags */ void paint_cursor_delete_textures(void) { - if (primary_snap.overlay_texture) + if (primary_snap.overlay_texture) { glDeleteTextures(1, &primary_snap.overlay_texture); - if (secondary_snap.overlay_texture) + } + if (secondary_snap.overlay_texture) { glDeleteTextures(1, &secondary_snap.overlay_texture); - if (cursor_snap.overlay_texture) + } + if (cursor_snap.overlay_texture) { glDeleteTextures(1, &cursor_snap.overlay_texture); + } memset(&primary_snap, 0, sizeof(TexSnapshot)); memset(&secondary_snap, 0, sizeof(TexSnapshot)); @@ -194,8 +197,8 @@ static void load_tex_task_cb_ex(void *__restrict userdata, len = sqrtf(x * x + y * y); if (ELEM(mtex->brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_STENCIL) || len <= 1.0f) { - /* it is probably worth optimizing for those cases where the texture is not rotated by skipping the calls to - * atan2, sqrtf, sin, and cos. */ + /* It is probably worth optimizing for those cases where the texture is not rotated by + * skipping the calls to atan2, sqrtf, sin, and cos. */ if (mtex->tex && (rotation > 0.001f || rotation < -0.001f)) { const float angle = atan2f(y, x) + rotation; @@ -271,16 +274,19 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima int s = BKE_brush_size_get(vc->scene, br); int r = 1; - for (s >>= 1; s > 0; s >>= 1) + for (s >>= 1; s > 0; s >>= 1) { r++; + } size = (1 << r); - if (size < 256) + if (size < 256) { size = 256; + } - if (size < target->old_size) + if (size < target->old_size) { size = target->old_size; + } } else { size = 512; @@ -296,10 +302,12 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima target->old_size = size; } - if (col) + if (col) { buffer = MEM_mallocN(sizeof(GLubyte) * size * size * 4, "load_tex"); - else + } + else { buffer = MEM_mallocN(sizeof(GLubyte) * size * size, "load_tex"); + } pool = BKE_image_pool_new(); @@ -324,14 +332,17 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima BLI_parallel_range_settings_defaults(&settings); BLI_task_parallel_range(0, size, &data, load_tex_task_cb_ex, &settings); - if (mtex->tex && mtex->tex->nodetree) + if (mtex->tex && mtex->tex->nodetree) { ntreeTexEndExecTree(mtex->tex->nodetree->execdata); + } - if (pool) + if (pool) { BKE_image_pool_free(pool); + } - if (!target->overlay_texture) + if (!target->overlay_texture) { glGenTextures(1, &target->overlay_texture); + } } else { size = target->old_size; @@ -352,8 +363,9 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, format, GL_UNSIGNED_BYTE, buffer); } - if (buffer) + if (buffer) { MEM_freeN(buffer); + } target->old_col = col; } @@ -422,16 +434,19 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) s = BKE_brush_size_get(vc->scene, br); r = 1; - for (s >>= 1; s > 0; s >>= 1) + for (s >>= 1; s > 0; s >>= 1) { r++; + } size = (1 << r); - if (size < 256) + if (size < 256) { size = 256; + } - if (size < cursor_snap.size) + if (size < cursor_snap.size) { size = cursor_snap.size; + } if (cursor_snap.size != size) { if (cursor_snap.overlay_texture) { @@ -457,8 +472,9 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) BLI_parallel_range_settings_defaults(&settings); BLI_task_parallel_range(0, size, &data, load_tex_cursor_task_cb, &settings); - if (!cursor_snap.overlay_texture) + if (!cursor_snap.overlay_texture) { glGenTextures(1, &cursor_snap.overlay_texture); + } } else { size = cursor_snap.size; @@ -475,8 +491,9 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_RED, GL_UNSIGNED_BYTE, buffer); } - if (buffer) + if (buffer) { MEM_freeN(buffer); + } } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -567,8 +584,9 @@ static bool sculpt_get_brush_geometry(bContext *C, *pixel_radius = project_brush_radius( vc, BKE_brush_unprojected_radius_get(scene, brush), location); - if (*pixel_radius == 0) + if (*pixel_radius == 0) { *pixel_radius = BKE_brush_size_get(scene, brush); + } mul_m4_v3(vc->obact->obmat, location); } @@ -665,10 +683,12 @@ static void paint_draw_tex_overlay(UnifiedPaintSettings *ups, quad.ymax = brush->mask_stencil_dimension[1]; } GPU_matrix_push(); - if (primary) + if (primary) { GPU_matrix_translate_2fv(brush->stencil_pos); - else + } + else { GPU_matrix_translate_2fv(brush->mask_stencil_pos); + } GPU_matrix_rotate_2d(RAD2DEGF(mtex->rot)); } @@ -787,8 +807,9 @@ static void paint_draw_cursor_overlay( GPU_blend_set_func(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA); - if (do_pop) + if (do_pop) { GPU_matrix_pop(); + } } } @@ -812,20 +833,25 @@ static void paint_draw_alpha_overlay(UnifiedPaintSettings *ups, x -= vc->ar->winrct.xmin; y -= vc->ar->winrct.ymin; - /* coloured overlay should be drawn separately */ + /* Colored overlay should be drawn separately. */ if (col) { - if (!(flags & PAINT_OVERLAY_OVERRIDE_PRIMARY)) + if (!(flags & PAINT_OVERLAY_OVERRIDE_PRIMARY)) { paint_draw_tex_overlay(ups, brush, vc, x, y, zoom, true, true); - if (!(flags & PAINT_OVERLAY_OVERRIDE_SECONDARY)) + } + if (!(flags & PAINT_OVERLAY_OVERRIDE_SECONDARY)) { paint_draw_tex_overlay(ups, brush, vc, x, y, zoom, false, false); - if (!(flags & PAINT_OVERLAY_OVERRIDE_CURSOR)) + } + if (!(flags & PAINT_OVERLAY_OVERRIDE_CURSOR)) { paint_draw_cursor_overlay(ups, brush, vc, x, y, zoom); + } } else { - if (!(flags & PAINT_OVERLAY_OVERRIDE_PRIMARY) && (mode != PAINT_MODE_WEIGHT)) + if (!(flags & PAINT_OVERLAY_OVERRIDE_PRIMARY) && (mode != PAINT_MODE_WEIGHT)) { paint_draw_tex_overlay(ups, brush, vc, x, y, zoom, false, true); - if (!(flags & PAINT_OVERLAY_OVERRIDE_CURSOR)) + } + if (!(flags & PAINT_OVERLAY_OVERRIDE_CURSOR)) { paint_draw_cursor_overlay(ups, brush, vc, x, y, zoom); + } } GPU_matrix_pop(); @@ -954,7 +980,7 @@ static void paint_draw_curve_cursor(Brush *brush, ViewContext *vc) draw_rect_point( pos, selec_col, handle_col, &cp->bez.vec[2][0], 8.0f, cp->bez.f3 || cp->bez.f2); - for (j = 0; j < 2; j++) + for (j = 0; j < 2; j++) { BKE_curve_forward_diff_bezier(cp->bez.vec[1][j], cp->bez.vec[2][j], cp_next->bez.vec[0][j], @@ -962,6 +988,7 @@ static void paint_draw_curve_cursor(Brush *brush, ViewContext *vc) data + j, PAINT_CURVE_NUM_SEGMENTS, sizeof(float[2])); + } float(*v)[2] = (float(*)[2])data; @@ -1010,21 +1037,25 @@ static void paint_cursor_on_hit(UnifiedPaintSettings *ups, /* update the brush's cached 3D radius */ if (!BKE_brush_use_locked_size(vc->scene, brush)) { /* get 2D brush radius */ - if (ups->draw_anchored) + if (ups->draw_anchored) { projected_radius = ups->anchored_size; + } else { - if (brush->flag & BRUSH_ANCHORED) + if (brush->flag & BRUSH_ANCHORED) { projected_radius = 8; - else + } + else { projected_radius = BKE_brush_size_get(vc->scene, brush); + } } /* convert brush radius from 2D to 3D */ unprojected_radius = paint_calc_object_space_radius(vc, location, projected_radius); /* scale 3D brush radius by pressure */ - if (ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush)) + if (ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush)) { unprojected_radius *= ups->size_pressure_value; + } /* set cached value in either Brush or UnifiedPaintSettings */ BKE_brush_unprojected_radius_set(vc->scene, brush, unprojected_radius); @@ -1053,8 +1084,9 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) ePaintMode mode = BKE_paintmode_get_active_from_context(C); /* check that brush drawing is enabled */ - if (ommit_cursor_drawing(paint, mode, brush)) + if (ommit_cursor_drawing(paint, mode, brush)) { return; + } /* can't use stroke vc here because this will be called during * mouse over too, not just during a stroke */ @@ -1100,8 +1132,9 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) /* test if brush is over the mesh */ bool hit = sculpt_get_brush_geometry(C, &vc, x, y, &pixel_radius, location, ups); - if (BKE_brush_use_locked_size(scene, brush)) + if (BKE_brush_use_locked_size(scene, brush)) { BKE_brush_size_set(scene, brush, pixel_radius); + } /* check if brush is subtracting, use different color then */ /* TODO: no way currently to know state of pen flip or @@ -1112,8 +1145,9 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) } /* only do if brush is over the mesh */ - if (hit) + if (hit) { paint_cursor_on_hit(ups, brush, &vc, location); + } } if (ups->draw_anchored) { diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c index bc6e019142a..d9fd194e96f 100644 --- a/source/blender/editors/sculpt_paint/paint_curve.c +++ b/source/blender/editors/sculpt_paint/paint_curve.c @@ -60,13 +60,15 @@ bool paint_curve_poll(bContext *C) RegionView3D *rv3d = CTX_wm_region_view3d(C); SpaceImage *sima; - if (rv3d && !(ob && ((ob->mode & OB_MODE_ALL_PAINT) != 0))) + if (rv3d && !(ob && ((ob->mode & OB_MODE_ALL_PAINT) != 0))) { return false; + } sima = CTX_wm_space_image(C); - if (sima && sima->mode != SI_MODE_PAINT) + if (sima && sima->mode != SI_MODE_PAINT) { return false; + } p = BKE_paint_get_active_from_context(C); @@ -95,8 +97,9 @@ static PaintCurvePoint *paintcurve_point_get_closest( if (dist < closest_dist) { closest = pcp; closest_dist = dist; - if (point) + if (point) { *point = SEL_F1; + } } } if (!ignore_pivot) { @@ -105,8 +108,9 @@ static PaintCurvePoint *paintcurve_point_get_closest( if (dist < closest_dist) { closest = pcp; closest_dist = dist; - if (point) + if (point) { *point = SEL_F2; + } } } } @@ -115,8 +119,9 @@ static PaintCurvePoint *paintcurve_point_get_closest( if (dist < closest_dist) { closest = pcp; closest_dist = dist; - if (point) + if (point) { *point = SEL_F3; + } } } } @@ -213,12 +218,14 @@ static void paintcurve_point_add(bContext *C, wmOperator *op, const int loc[2]) add_index = pc->add_index; if (pc->points) { - if (add_index > 0) + if (add_index > 0) { memcpy(pcp, pc->points, add_index * sizeof(PaintCurvePoint)); - if (add_index < pc->tot_points) + } + if (add_index < pc->tot_points) { memcpy(pcp + add_index + 1, pc->points + add_index, (pc->tot_points - add_index) * sizeof(PaintCurvePoint)); + } MEM_freeN(pc->points); } @@ -332,8 +339,9 @@ static int paintcurve_delete_point_exec(bContext *C, wmOperator *op) int j = 0; int new_tot = pc->tot_points - tot_del; PaintCurvePoint *points_new = NULL; - if (new_tot > 0) + if (new_tot > 0) { points_new = MEM_mallocN(new_tot * sizeof(PaintCurvePoint), "PaintCurvePoint"); + } for (i = 0, pcp = pc->points; i < pc->tot_points; i++, pcp++) { if (!(pcp->bez.f2 & DELETE_TAG)) { @@ -392,8 +400,9 @@ static bool paintcurve_point_select( pc = br->paint_curve; - if (!pc) + if (!pc) { return false; + } ED_paintcurve_undo_push_begin(op->type->name); @@ -429,22 +438,28 @@ static bool paintcurve_point_select( BKE_paint_curve_clamp_endpoint_add_index(pc, pcp - pc->points); if (selflag == SEL_F2) { - if (extend) + if (extend) { pcp->bez.f2 ^= SELECT; - else + } + else { pcp->bez.f2 |= SELECT; + } } else if (selflag == SEL_F1) { - if (extend) + if (extend) { pcp->bez.f1 ^= SELECT; - else + } + else { pcp->bez.f1 |= SELECT; + } } else if (selflag == SEL_F3) { - if (extend) + if (extend) { pcp->bez.f3 ^= SELECT; - else + } + else { pcp->bez.f3 |= SELECT; + } } } @@ -495,8 +510,9 @@ static int paintcurve_select_point_exec(bContext *C, wmOperator *op) bool toggle = RNA_boolean_get(op->ptr, "toggle"); bool extend = RNA_boolean_get(op->ptr, "extend"); RNA_int_get_array(op->ptr, "location", loc); - if (paintcurve_point_select(C, op, loc, toggle, extend)) + if (paintcurve_point_select(C, op, loc, toggle, extend)) { return OPERATOR_FINISHED; + } } return OPERATOR_CANCELLED; @@ -557,8 +573,9 @@ static int paintcurve_slide_invoke(bContext *C, wmOperator *op, const wmEvent *e PaintCurve *pc = br->paint_curve; PaintCurvePoint *pcp; - if (!pc) + if (!pc) { return OPERATOR_PASS_THROUGH; + } if (do_select) { pcp = paintcurve_point_get_closest(pc, loc_fl, align, PAINT_CURVE_SELECT_THRESHOLD, &select); @@ -589,8 +606,9 @@ static int paintcurve_slide_invoke(bContext *C, wmOperator *op, const wmEvent *e op->customdata = psd; /* first, clear all selection from points */ - for (i = 0; i < pc->tot_points; i++) + for (i = 0; i < pc->tot_points; i++) { pc->points[i].bez.f1 = pc->points[i].bez.f3 = pc->points[i].bez.f2 = 0; + } /* only select the active point */ PAINT_CURVE_POINT_SELECT(pcp, psd->select); @@ -622,8 +640,9 @@ static int paintcurve_slide_modal(bContext *C, wmOperator *op, const wmEvent *ev float diff[2] = {event->mval[0] - psd->initial_loc[0], event->mval[1] - psd->initial_loc[1]}; if (psd->select == 1) { int i; - for (i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { add_v2_v2v2(psd->pcp->bez.vec[i], diff, psd->point_initial_loc[i]); + } } else { add_v2_v2(diff, psd->point_initial_loc[psd->select]); @@ -718,8 +737,9 @@ static int paintcurve_cursor_invoke(bContext *C, wmOperator *UNUSED(op), const w SpaceImage *sima = CTX_wm_space_image(C); float location[2]; - if (!sima) + if (!sima) { return OPERATOR_CANCELLED; + } UI_view2d_region_to_view( &ar->v2d, event->mval[0], event->mval[1], &location[0], &location[1]); diff --git a/source/blender/editors/sculpt_paint/paint_hide.c b/source/blender/editors/sculpt_paint/paint_hide.c index c1f87f676e2..dded9fcf45a 100644 --- a/source/blender/editors/sculpt_paint/paint_hide.c +++ b/source/blender/editors/sculpt_paint/paint_hide.c @@ -66,8 +66,9 @@ static bool is_effected(PartialVisArea area, const float co[3], const float mask) { - if (area == PARTIALVIS_ALL) + if (area == PARTIALVIS_ALL) { return 1; + } else if (area == PARTIALVIS_MASKED) { return mask > 0.5f; } @@ -103,15 +104,18 @@ static void partialvis_update_mesh(Object *ob, /* hide vertex if in the hide volume */ if (is_effected(area, planes, v->co, vmask)) { - if (action == PARTIALVIS_HIDE) + if (action == PARTIALVIS_HIDE) { v->flag |= ME_HIDE; - else + } + else { v->flag &= ~ME_HIDE; + } any_changed = true; } - if (!(v->flag & ME_HIDE)) + if (!(v->flag & ME_HIDE)) { any_visible = true; + } } if (any_changed) { @@ -183,10 +187,12 @@ static void partialvis_update_grids(Object *ob, } /* keep track of whether any elements are still hidden */ - if (BLI_BITMAP_TEST(gh, y * key.grid_size + x)) + if (BLI_BITMAP_TEST(gh, y * key.grid_size + x)) { any_hidden = true; - else + } + else { any_visible = true; + } } } @@ -222,15 +228,18 @@ static void partialvis_update_bmesh_verts(BMesh *bm, /* hide vertex if in the hide volume */ if (is_effected(area, planes, v->co, *vmask)) { - if (action == PARTIALVIS_HIDE) + if (action == PARTIALVIS_HIDE) { BM_elem_flag_enable(v, BM_ELEM_HIDDEN); - else + } + else { BM_elem_flag_disable(v, BM_ELEM_HIDDEN); + } (*any_changed) = true; } - if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) + if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) { (*any_visible) = true; + } } } @@ -241,10 +250,12 @@ static void partialvis_update_bmesh_faces(GSet *faces) GSET_ITER (gs_iter, faces) { BMFace *f = BLI_gsetIterator_getKey(&gs_iter); - if (paint_is_bmesh_face_hidden(f)) + if (paint_is_bmesh_face_hidden(f)) { BM_elem_flag_enable(f, BM_ELEM_HIDDEN); - else + } + else { BM_elem_flag_disable(f, BM_ELEM_HIDDEN); + } } } @@ -375,8 +386,9 @@ static int hide_show_exec(bContext *C, wmOperator *op) } } - if (nodes) + if (nodes) { MEM_freeN(nodes); + } /* end undo */ sculpt_undo_push_end(); @@ -396,10 +408,12 @@ static int hide_show_invoke(bContext *C, wmOperator *op, const wmEvent *event) { PartialVisArea area = RNA_enum_get(op->ptr, "area"); - if (!ELEM(area, PARTIALVIS_ALL, PARTIALVIS_MASKED)) + if (!ELEM(area, PARTIALVIS_ALL, PARTIALVIS_MASKED)) { return WM_gesture_box_invoke(C, op, event); - else + } + else { return op->type->exec(C, op); + } } void PAINT_OT_hide_show(struct wmOperatorType *ot) diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 3a3f4335fd5..5a45f4946f2 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -81,8 +81,10 @@ #include "paint_intern.h" -/* This is a static resource for non-global access. - * Maybe it should be exposed as part of the paint operation, but for now just give a public interface. +/** + * This is a static resource for non-global access. + * Maybe it should be exposed as part of the paint operation, + * but for now just give a public interface. */ static ImagePaintPartialRedraw imapaintpartial = {0, 0, 0, 0, 0}; @@ -124,8 +126,9 @@ void ED_imapaint_dirty_region(Image *ima, ImBuf *ibuf, int x, int y, int w, int IMB_rectclip(ibuf, NULL, &x, &y, &srcx, &srcy, &w, &h); - if (w == 0 || h == 0) + if (w == 0 || h == 0) { return; + } if (!imapaintpartial.enabled) { imapaintpartial.x1 = x; @@ -145,14 +148,17 @@ void ED_imapaint_dirty_region(Image *ima, ImBuf *ibuf, int x, int y, int w, int ListBase *undo_tiles = ED_image_undo_get_tiles(); - for (ty = tiley; ty <= tileh; ty++) - for (tx = tilex; tx <= tilew; tx++) + for (ty = tiley; ty <= tileh; ty++) { + for (tx = tilex; tx <= tilew; tx++) { image_undo_push_tile(undo_tiles, ima, ibuf, &tmpibuf, tx, ty, NULL, NULL, false, find_old); + } + } ibuf->userflags |= IB_BITMAPDIRTY; - if (tmpibuf) + if (tmpibuf) { IMB_freeImBuf(tmpibuf); + } } void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, short texpaint) @@ -162,8 +168,9 @@ void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, short te ibuf, imapaintpartial.x1, imapaintpartial.y1, imapaintpartial.x2, imapaintpartial.y2); } - if (ibuf->mipmap[0]) + if (ibuf->mipmap[0]) { ibuf->userflags |= IB_MIPMAP_INVALID; + } /* todo: should set_tpage create ->rect? */ if (texpaint || (sima && sima->lock)) { @@ -195,8 +202,9 @@ BlurKernel *paint_new_blur_kernel(Brush *br, bool proj) kernel->pixel_len = radius; } else { - if (br->blur_kernel_radius <= 0) + if (br->blur_kernel_radius <= 0) { br->blur_kernel_radius = 1; + } radius = br->blur_kernel_radius; @@ -208,8 +216,9 @@ BlurKernel *paint_new_blur_kernel(Brush *br, bool proj) switch (type) { case KERNEL_BOX: - for (i = 0; i < kernel->side_squared; i++) + for (i = 0; i < kernel->side_squared; i++) { kernel->wdata[i] = 1.0; + } break; case KERNEL_GAUSSIAN: { @@ -244,8 +253,9 @@ BlurKernel *paint_new_blur_kernel(Brush *br, bool proj) void paint_delete_blur_kernel(BlurKernel *kernel) { - if (kernel->wdata) + if (kernel->wdata) { MEM_freeN(kernel->wdata); + } } /************************ image paint poll ************************/ @@ -262,8 +272,9 @@ static bool image_paint_poll_ex(bContext *C, bool check_tool) { Object *obact; - if (!image_paint_brush(C)) + if (!image_paint_brush(C)) { return 0; + } obact = CTX_data_active_object(C); if ((obact && obact->mode & OB_MODE_TEXTURE_PAINT) && CTX_wm_region_view3d(C)) { @@ -300,10 +311,13 @@ static bool image_paint_2d_clone_poll(bContext *C) { Brush *brush = image_paint_brush(C); - if (!CTX_wm_region_view3d(C) && image_paint_poll(C)) - if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE)) - if (brush->clone.image) + if (!CTX_wm_region_view3d(C) && image_paint_poll(C)) { + if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE)) { + if (brush->clone.image) { return 1; + } + } + } return 0; } @@ -351,8 +365,9 @@ void paint_brush_color_get(struct Scene *scene, float color[3], struct ColorManagedDisplay *display) { - if (invert) + if (invert) { copy_v3_v3(color, BKE_brush_secondary_color_get(scene, br)); + } else { if (br->flag & BRUSH_USE_GRADIENT) { float color_gr[4]; @@ -372,11 +387,13 @@ void paint_brush_color_get(struct Scene *scene, } copy_v3_v3(color, color_gr); } - else + else { copy_v3_v3(color, BKE_brush_color_get(scene, br)); + } } - if (color_correction) + if (color_correction) { IMB_colormanagement_display_to_scene_linear_v3(color, display); + } } void paint_brush_init_tex(Brush *brush) @@ -399,11 +416,13 @@ void paint_brush_exit_tex(Brush *brush) { if (brush) { MTex *mtex = &brush->mtex; - if (mtex->tex && mtex->tex->nodetree) + if (mtex->tex && mtex->tex->nodetree) { ntreeTexEndExecTree(mtex->tex->nodetree->execdata); + } mtex = &brush->mask_mtex; - if (mtex->tex && mtex->tex->nodetree) + if (mtex->tex && mtex->tex->nodetree) { ntreeTexEndExecTree(mtex->tex->nodetree->execdata); + } } } @@ -526,10 +545,12 @@ static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, Po return; } - if (BKE_brush_use_alpha_pressure(scene, brush)) + if (BKE_brush_use_alpha_pressure(scene, brush)) { BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * pressure * alphafac)); - else + } + else { BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * alphafac)); + } if ((brush->flag & BRUSH_DRAG_DOT) || (brush->flag & BRUSH_ANCHORED)) { UndoStack *ustack = CTX_wm_manager(C)->undo_stack; @@ -632,9 +653,15 @@ static void paint_stroke_done(const bContext *C, struct PaintStroke *stroke) /* duplicate warning, see texpaint_init */ #if 0 if (pop->s.warnmultifile) - BKE_reportf(op->reports, RPT_WARNING, "Image requires 4 color channels to paint: %s", pop->s.warnmultifile); + BKE_reportf(op->reports, + RPT_WARNING, + "Image requires 4 color channels to paint: %s", + pop->s.warnmultifile); if (pop->s.warnpackedfile) - BKE_reportf(op->reports, RPT_WARNING, "Packed MultiLayer files cannot be painted: %s", pop->s.warnpackedfile); + BKE_reportf(op->reports, + RPT_WARNING, + "Packed MultiLayer files cannot be painted: %s", + pop->s.warnpackedfile); #endif MEM_freeN(pop); } @@ -689,8 +716,9 @@ static int paint_exec(bContext *C, wmOperator *op) strokeprop = RNA_struct_find_property(op->ptr, "stroke"); - if (!RNA_property_collection_lookup_int(op->ptr, strokeprop, 0, &firstpoint)) + if (!RNA_property_collection_lookup_int(op->ptr, strokeprop, 0, &firstpoint)) { return OPERATOR_CANCELLED; + } RNA_float_get_array(&firstpoint, "mouse", mouse); @@ -759,8 +787,9 @@ static void toggle_paint_cursor(bContext *C, int enable) settings->imapaint.paintcursor = NULL; paint_cursor_delete_textures(); } - else if (enable) + else if (enable) { paint_cursor_start(C, image_paint_poll); + } } /* enable the paint cursor if it isn't already. @@ -1086,12 +1115,15 @@ void PAINT_OT_sample_color(wmOperatorType *ot) static bool texture_paint_toggle_poll(bContext *C) { Object *ob = CTX_data_active_object(C); - if (ob == NULL || ob->type != OB_MESH) + if (ob == NULL || ob->type != OB_MESH) { return 0; - if (!ob->data || ID_IS_LINKED(ob->data)) + } + if (!ob->data || ID_IS_LINKED(ob->data)) { return 0; - if (CTX_data_edit_object(C)) + } + if (CTX_data_edit_object(C)) { return 0; + } return 1; } @@ -1114,8 +1146,9 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) if (ob->mode & mode_flag) { ob->mode &= ~mode_flag; - if (U.glreslimit != 0) + if (U.glreslimit != 0) { GPU_free_images(bmain); + } GPU_paint_set_mipmap(bmain, 1); toggle_paint_cursor(C, 0); @@ -1136,8 +1169,9 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) /* set the current material active paint slot on image editor */ Material *ma = give_current_material(ob, ob->actcol); - if (ma && ma->texpaintslot) + if (ma && ma->texpaintslot) { ima = ma->texpaintslot[ma->paint_active_slot].ima; + } } else if (imapaint->mode == IMAGEPAINT_MODE_IMAGE) { ima = imapaint->canvas; @@ -1168,8 +1202,9 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) BKE_paint_toolslots_brush_validate(bmain, &imapaint->paint); - if (U.glreslimit != 0) + if (U.glreslimit != 0) { GPU_free_images(bmain); + } GPU_paint_set_mipmap(bmain, 0); toggle_paint_cursor(C, 1); @@ -1227,8 +1262,9 @@ static bool brush_colors_flip_poll(bContext *C) { if (image_paint_poll(C)) { Brush *br = image_paint_brush(C); - if (ELEM(br->imagepaint_tool, PAINT_TOOL_DRAW, PAINT_TOOL_FILL)) + if (ELEM(br->imagepaint_tool, PAINT_TOOL_DRAW, PAINT_TOOL_FILL)) { return true; + } } else { Object *ob = CTX_data_active_object(C); @@ -1275,9 +1311,11 @@ void ED_imapaint_bucket_fill(struct bContext *C, float color[3], wmOperator *op) static bool texture_paint_poll(bContext *C) { - if (texture_paint_toggle_poll(C)) - if (CTX_data_active_object(C)->mode & OB_MODE_TEXTURE_PAINT) + if (texture_paint_toggle_poll(C)) { + if (CTX_data_active_object(C)->mode & OB_MODE_TEXTURE_PAINT) { return 1; + } + } return 0; } diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c index 5390f18304a..474d3a8ceba 100644 --- a/source/blender/editors/sculpt_paint/paint_image_2d.c +++ b/source/blender/editors/sculpt_paint/paint_image_2d.c @@ -158,14 +158,18 @@ static void brush_painter_2d_require_imbuf(BrushPainter *painter, Brush *brush = painter->brush; if ((painter->cache.use_float != use_float)) { - if (painter->cache.ibuf) + if (painter->cache.ibuf) { IMB_freeImBuf(painter->cache.ibuf); - if (painter->cache.curve_mask) + } + if (painter->cache.curve_mask) { MEM_freeN(painter->cache.curve_mask); - if (painter->cache.tex_mask) + } + if (painter->cache.tex_mask) { MEM_freeN(painter->cache.tex_mask); - if (painter->cache.tex_mask_old) + } + if (painter->cache.tex_mask_old) { MEM_freeN(painter->cache.tex_mask_old); + } painter->cache.ibuf = NULL; painter->cache.curve_mask = NULL; painter->cache.tex_mask = NULL; @@ -182,16 +186,21 @@ static void brush_painter_2d_require_imbuf(BrushPainter *painter, static void brush_painter_2d_free(BrushPainter *painter) { - if (painter->cache.ibuf) + if (painter->cache.ibuf) { IMB_freeImBuf(painter->cache.ibuf); - if (painter->cache.texibuf) + } + if (painter->cache.texibuf) { IMB_freeImBuf(painter->cache.texibuf); - if (painter->cache.curve_mask) + } + if (painter->cache.curve_mask) { MEM_freeN(painter->cache.curve_mask); - if (painter->cache.tex_mask) + } + if (painter->cache.tex_mask) { MEM_freeN(painter->cache.tex_mask); - if (painter->cache.tex_mask_old) + } + if (painter->cache.tex_mask_old) { MEM_freeN(painter->cache.tex_mask_old); + } MEM_freeN(painter); } @@ -297,9 +306,10 @@ static void brush_painter_mask_imbuf_partial_update(BrushPainter *painter, int destx, desty, srcx, srcy, w, h, x1, y1, x2, y2; /* create brush image buffer if it didn't exist yet */ - if (!cache->tex_mask) + if (!cache->tex_mask) { cache->tex_mask = MEM_mallocN(sizeof(unsigned short) * diameter * diameter, "brush_painter_mask"); + } /* create new texture image buffer with coordinates relative to old */ tex_mask_old = cache->tex_mask_old; @@ -334,21 +344,27 @@ static void brush_painter_mask_imbuf_partial_update(BrushPainter *painter, y2 = min_ii(desty + h, diameter); /* blend existing texture in new position */ - if ((x1 < x2) && (y1 < y2)) + if ((x1 < x2) && (y1 < y2)) { brush_painter_mask_imbuf_update(painter, tex_mask_old, x1, y1, x2, y2, srcx, srcy, diameter); + } - if (tex_mask_old) + if (tex_mask_old) { MEM_freeN(tex_mask_old); + } /* sample texture in new areas */ - if ((0 < x1) && (0 < diameter)) + if ((0 < x1) && (0 < diameter)) { brush_painter_mask_imbuf_update(painter, NULL, 0, 0, x1, diameter, 0, 0, diameter); - if ((x2 < diameter) && (0 < diameter)) + } + if ((x2 < diameter) && (0 < diameter)) { brush_painter_mask_imbuf_update(painter, NULL, x2, 0, diameter, diameter, 0, 0, diameter); - if ((x1 < x2) && (0 < y1)) + } + if ((x1 < x2) && (0 < y1)) { brush_painter_mask_imbuf_update(painter, NULL, x1, 0, x2, y1, 0, 0, diameter); - if ((x1 < x2) && (y2 < diameter)) + } + if ((x1 < x2) && (y2 < diameter)) { brush_painter_mask_imbuf_update(painter, NULL, x1, y2, x2, diameter, 0, 0, diameter); + } /* through with sampling, now update sizes */ cache->tex_mask_old_w = diameter; @@ -556,8 +572,9 @@ static void brush_painter_imbuf_update( crgba[2] = ot[2]; crgba[3] = ot[3]; } - else + else { rgba_float_to_uchar(crgba, rgba); + } /* write to new texture buffer */ t[0] = crgba[0]; @@ -588,8 +605,9 @@ static void brush_painter_imbuf_partial_update(BrushPainter *painter, /* create brush image buffer if it didn't exist yet */ imbflag = (cache->use_float) ? IB_rectfloat : IB_rect; - if (!cache->ibuf) + if (!cache->ibuf) { cache->ibuf = IMB_allocImBuf(diameter, diameter, 32, imbflag); + } ibuf = cache->ibuf; /* create new texture image buffer with coordinates relative to old */ @@ -617,21 +635,27 @@ static void brush_painter_imbuf_partial_update(BrushPainter *painter, y2 = min_ii(desty + h, ibuf->y); /* blend existing texture in new position */ - if ((x1 < x2) && (y1 < y2)) + if ((x1 < x2) && (y1 < y2)) { brush_painter_imbuf_update(painter, oldtexibuf, x1, y1, x2, y2, srcx, srcy); + } - if (oldtexibuf) + if (oldtexibuf) { IMB_freeImBuf(oldtexibuf); + } /* sample texture in new areas */ - if ((0 < x1) && (0 < ibuf->y)) + if ((0 < x1) && (0 < ibuf->y)) { brush_painter_imbuf_update(painter, NULL, 0, 0, x1, ibuf->y, 0, 0); - if ((x2 < ibuf->x) && (0 < ibuf->y)) + } + if ((x2 < ibuf->x) && (0 < ibuf->y)) { brush_painter_imbuf_update(painter, NULL, x2, 0, ibuf->x, ibuf->y, 0, 0); - if ((x1 < x2) && (0 < y1)) + } + if ((x1 < x2) && (0 < y1)) { brush_painter_imbuf_update(painter, NULL, x1, 0, x2, y1, 0, 0); - if ((x1 < x2) && (y2 < ibuf->y)) + } + if ((x1 < x2) && (y2 < ibuf->y)) { brush_painter_imbuf_update(painter, NULL, x1, y2, x2, ibuf->y, 0, 0); + } } static void brush_painter_2d_tex_mapping(ImagePaintState *s, @@ -716,10 +740,12 @@ static void brush_painter_2d_refresh_cache(ImagePaintState *s, if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) { tex_rotation += ups->brush_rotation; } - else if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) + else if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) { do_random = true; - else if (!((brush->flag & BRUSH_ANCHORED) || update_color)) + } + else if (!((brush->flag & BRUSH_ANCHORED) || update_color)) { do_partial_update = true; + } brush_painter_2d_tex_mapping(s, diameter, @@ -765,10 +791,12 @@ static void brush_painter_2d_refresh_cache(ImagePaintState *s, brush->mask_mtex.brush_map_mode, &painter->mask_mapping); - if (do_partial_update_mask) + if (do_partial_update_mask) { brush_painter_mask_imbuf_partial_update(painter, pos, diameter); - else + } + else { cache->tex_mask = brush_painter_mask_ibuf_new(painter, diameter); + } cache->last_mask_rotation = mask_rotation; } } @@ -835,11 +863,13 @@ static void paint_2d_ibuf_rgb_set( { if (is_torus) { x %= ibuf->x; - if (x < 0) + if (x < 0) { x += ibuf->x; + } y %= ibuf->y; - if (y < 0) + if (y < 0) { y += ibuf->y; + } } if (ibuf->rect_float) { @@ -865,13 +895,15 @@ static void paint_2d_ibuf_tile_convert(ImBuf *ibuf, int *x, int *y, short tile) { if (tile & PAINT_TILE_X) { *x %= ibuf->x; - if (*x < 0) + if (*x < 0) { *x += ibuf->x; + } } if (tile & PAINT_TILE_Y) { *y %= ibuf->y; - if (*y < 0) + if (*y < 0) { *y += ibuf->y; + } } } @@ -879,15 +911,17 @@ static float paint_2d_ibuf_add_if(ImBuf *ibuf, int x, int y, float *outrgb, shor { float inrgb[4]; - if (tile) + if (tile) { paint_2d_ibuf_tile_convert(ibuf, &x, &y, tile); + } /* need to also do clipping here always since tiled coordinates * are not always within bounds */ if (x < ibuf->x && x >= 0 && y < ibuf->y && y >= 0) { paint_2d_ibuf_rgb_get(ibuf, x, y, inrgb); } - else + else { return 0; + } mul_v4_fl(inrgb, w); add_v4_v4(outrgb, inrgb); @@ -917,8 +951,9 @@ static void paint_2d_lift_soften( if (!tile) { IMB_rectclip(ibuf, ibufb, &in_off[0], &in_off[1], &out_off[0], &out_off[1], &dim[0], &dim[1]); - if ((dim[0] == 0) || (dim[1] == 0)) + if ((dim[0] == 0) || (dim[1] == 0)) { return; + } } /* find offset inside mask buffers to sample them */ @@ -933,10 +968,12 @@ static void paint_2d_lift_soften( count = 0.0; if (tile) { paint_2d_ibuf_tile_convert(ibuf, &xi, &yi, tile); - if (xi < ibuf->x && xi >= 0 && yi < ibuf->y && yi >= 0) + if (xi < ibuf->x && xi >= 0 && yi < ibuf->y && yi >= 0) { paint_2d_ibuf_rgb_get(ibuf, xi, yi, rgba); - else + } + else { zero_v4(rgba); + } } else { /* coordinates have been clipped properly here, it should be safe to do this */ @@ -962,8 +999,8 @@ static void paint_2d_lift_soften( /* subtract blurred image from normal image gives high pass filter */ sub_v3_v3v3(outrgb, rgba, outrgb); - /* now rgba_ub contains the edge result, but this should be converted to luminance to avoid - * colored speckles appearing in final image, and also to check for threshold */ + /* Now rgba_ub contains the edge result, but this should be converted to luminance to + * avoid colored speckles appearing in final image, and also to check for threshold. */ outrgb[0] = outrgb[1] = outrgb[2] = IMB_colormanagement_get_luminance(outrgb); if (fabsf(outrgb[0]) > threshold) { float mask = BKE_brush_alpha_get(s->scene, s->brush); @@ -974,12 +1011,14 @@ static void paint_2d_lift_soften( blend_color_add_float(outrgb, rgba, outrgb); outrgb[3] = alpha; } - else + else { copy_v4_v4(outrgb, rgba); + } } } - else + else { copy_v4_v4(outrgb, rgba); + } /* write into brush buffer */ xo = out_off[0] + x; yo = out_off[1] + y; @@ -1015,19 +1054,23 @@ static int paint_2d_torus_split_region(ImagePaintRegion region[4], /* convert destination and source coordinates to be within image */ if (tile & PAINT_TILE_X) { destx = destx % dbuf->x; - if (destx < 0) + if (destx < 0) { destx += dbuf->x; + } srcx = srcx % sbuf->x; - if (srcx < 0) + if (srcx < 0) { srcx += sbuf->x; + } } if (tile & PAINT_TILE_Y) { desty = desty % dbuf->y; - if (desty < 0) + if (desty < 0) { desty += dbuf->y; + } srcy = srcy % sbuf->y; - if (srcy < 0) + if (srcy < 0) { srcy += sbuf->y; + } } /* clip width of blending area to destination imbuf, to avoid writing the * same pixel twice */ @@ -1039,13 +1082,15 @@ static int paint_2d_torus_split_region(ImagePaintRegion region[4], paint_2d_set_region(®ion[tot++], destx, desty, srcx, srcy, w, h); /* do 3 other rects if needed */ - if ((tile & PAINT_TILE_X) && w < origw) + if ((tile & PAINT_TILE_X) && w < origw) { paint_2d_set_region( ®ion[tot++], (destx + w) % dbuf->x, desty, (srcx + w) % sbuf->x, srcy, origw - w, h); - if ((tile & PAINT_TILE_Y) && h < origh) + } + if ((tile & PAINT_TILE_Y) && h < origh) { paint_2d_set_region( ®ion[tot++], destx, (desty + h) % dbuf->y, srcx, (srcy + h) % sbuf->y, w, origh - h); - if ((tile & PAINT_TILE_X) && (tile & PAINT_TILE_Y) && (w < origw) && (h < origh)) + } + if ((tile & PAINT_TILE_X) && (tile & PAINT_TILE_Y) && (w < origw) && (h < origh)) { paint_2d_set_region(®ion[tot++], (destx + w) % dbuf->x, (desty + h) % dbuf->y, @@ -1053,6 +1098,7 @@ static int paint_2d_torus_split_region(ImagePaintRegion region[4], (srcy + h) % sbuf->y, origw - w, origh - h); + } return tot; } @@ -1065,7 +1111,7 @@ static void paint_2d_lift_smear(ImBuf *ibuf, ImBuf *ibufb, int *pos, short tile) paint_2d_set_region(region, 0, 0, pos[0], pos[1], ibufb->x, ibufb->y); tot = paint_2d_torus_split_region(region, ibufb, ibuf, tile); - for (a = 0; a < tot; a++) + for (a = 0; a < tot; a++) { IMB_rectblend(ibufb, ibufb, ibuf, @@ -1083,6 +1129,7 @@ static void paint_2d_lift_smear(ImBuf *ibuf, ImBuf *ibufb, int *pos, short tile) region[a].height, IMB_BLEND_COPY, false); + } } static ImBuf *paint_2d_lift_clone(ImBuf *ibuf, ImBuf *ibufb, int *pos) @@ -1161,11 +1208,13 @@ static void paint_2d_do_making_brush(ImagePaintState *s, int origx = region->destx - tx * IMAPAINT_TILE_SIZE; int origy = region->desty - ty * IMAPAINT_TILE_SIZE; - if (s->canvas->rect_float) + if (s->canvas->rect_float) { tmpbuf.rect_float = image_undo_find_tile( undo_tiles, s->image, s->canvas, tx, ty, &mask, false); - else + } + else { tmpbuf.rect = image_undo_find_tile(undo_tiles, s->image, s->canvas, tx, ty, &mask, false); + } IMB_rectblend(s->canvas, &tmpbuf, @@ -1244,8 +1293,9 @@ static int paint_2d_op(void *state, blend = IMB_BLEND_INTERPOLATE; } else if (s->tool == PAINT_TOOL_SMEAR) { - if (lastpos[0] == pos[0] && lastpos[1] == pos[1]) + if (lastpos[0] == pos[0] && lastpos[1] == pos[1]) { return 0; + } paint_2d_convert_brushco(ibufb, lastpos, blastpos); paint_2d_lift_smear(s->canvas, ibufb, blastpos, tile); @@ -1337,8 +1387,9 @@ static int paint_2d_op(void *state, } } - if (clonebuf) + if (clonebuf) { IMB_freeImBuf(clonebuf); + } return 1; } @@ -1359,8 +1410,9 @@ static int paint_2d_canvas_set(ImagePaintState *s, Image *ima) s->warnmultifile = ima->id.name + 2; return 0; } - else if (!ibuf || !(ibuf->rect || ibuf->rect_float)) + else if (!ibuf || !(ibuf->rect || ibuf->rect_float)) { return 0; + } s->image = ima; s->canvas = ibuf; @@ -1382,8 +1434,9 @@ static int paint_2d_canvas_set(ImagePaintState *s, Image *ima) if (s->canvas->rect_float && !s->clonecanvas->rect_float) { IMB_float_from_rect(s->clonecanvas); } - else if (!s->canvas->rect_float && !s->clonecanvas->rect) + else if (!s->canvas->rect_float && !s->clonecanvas->rect) { IMB_rect_from_float(s->clonecanvas); + } } /* set masking */ @@ -1419,12 +1472,14 @@ void paint_2d_stroke(void *ps, ImBuf *ibuf = BKE_image_acquire_ibuf(s->image, s->sima ? &s->sima->iuser : NULL, NULL); const bool is_data = (ibuf && ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA); - if (!ibuf) + if (!ibuf) { return; + } s->blend = s->brush->blend; - if (eraser) + if (eraser) { s->blend = IMB_BLEND_ERASE_ALPHA; + } UI_view2d_region_to_view(s->v2d, mval[0], mval[1], &newuv[0], &newuv[1]); UI_view2d_region_to_view(s->v2d, prev_mval[0], prev_mval[1], &olduv[0], &olduv[1]); @@ -1463,8 +1518,9 @@ void paint_2d_stroke(void *ps, painter->cache.curve_mask, painter->cache.tex_mask, olduv, - newuv)) + newuv)) { s->need_redraw = true; + } BKE_image_release_ibuf(s->image, ibuf, NULL); } @@ -1490,10 +1546,12 @@ void *paint_2d_new_stroke(bContext *C, wmOperator *op, int mode) s->symmetry = settings->imapaint.paint.symmetry_flags; if (!paint_2d_canvas_set(s, s->image)) { - if (s->warnmultifile) + if (s->warnmultifile) { BKE_report(op->reports, RPT_WARNING, "Image requires 4 color channels to paint"); - if (s->warnpackedfile) + } + if (s->warnpackedfile) { BKE_report(op->reports, RPT_WARNING, "Packed MultiLayer files cannot be painted"); + } MEM_freeN(s); return NULL; @@ -1530,18 +1588,21 @@ void paint_2d_redraw(const bContext *C, void *ps, bool final) } if (final) { - if (s->image && !(s->sima && s->sima->lock)) + if (s->image && !(s->sima && s->sima->lock)) { GPU_free_image(s->image); + } /* compositor listener deals with updating */ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, s->image); DEG_id_tag_update(&s->image->id, 0); } else { - if (!s->sima || !s->sima->lock) + if (!s->sima || !s->sima->lock) { ED_region_tag_redraw(CTX_wm_region(C)); - else + } + else { WM_event_add_notifier(C, NC_IMAGE | NA_PAINTING, s->image); + } } } @@ -1566,8 +1627,9 @@ static void paint_2d_fill_add_pixel_byte(const int x_px, { size_t coordinate; - if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0) + if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0) { return; + } coordinate = ((size_t)y_px) * ibuf->x + x_px; @@ -1594,8 +1656,9 @@ static void paint_2d_fill_add_pixel_float(const int x_px, { size_t coordinate; - if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0) + if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0) { return; + } coordinate = ((size_t)y_px) * ibuf->x + x_px; @@ -1624,13 +1687,15 @@ void paint_2d_bucket_fill( bool do_float; - if (!ima) + if (!ima) { return; + } ibuf = BKE_image_acquire_ibuf(ima, &sima->iuser, NULL); - if (!ibuf) + if (!ibuf) { return; + } do_float = (ibuf->rect_float != NULL); /* first check if our image is float. If it is not we should correct the color to @@ -1742,14 +1807,18 @@ void paint_2d_bucket_fill( paint_2d_fill_add_pixel_float( x_px + 1, y_px + 1, ibuf, stack, touched, pixel_color, threshold_sq); - if (x_px > maxx) + if (x_px > maxx) { maxx = x_px; - if (x_px < minx) + } + if (x_px < minx) { minx = x_px; - if (y_px > maxy) + } + if (y_px > maxy) { maxy = y_px; - if (x_px > miny) + } + if (x_px > miny) { miny = y_px; + } } } else { @@ -1782,14 +1851,18 @@ void paint_2d_bucket_fill( paint_2d_fill_add_pixel_byte( x_px + 1, y_px + 1, ibuf, stack, touched, pixel_color, threshold_sq); - if (x_px > maxx) + if (x_px > maxx) { maxx = x_px; - if (x_px < minx) + } + if (x_px < minx) { minx = x_px; - if (y_px > maxy) + } + if (y_px > maxy) { maxy = y_px; - if (x_px > miny) + } + if (x_px > miny) { miny = y_px; + } } } @@ -1822,13 +1895,15 @@ void paint_2d_gradient_fill( bool do_float; - if (!ima) + if (!ima) { return; + } ibuf = BKE_image_acquire_ibuf(ima, &sima->iuser, NULL); - if (!ibuf) + if (!ibuf) { return; + } UI_view2d_region_to_view( s->v2d, mouse_final[0], mouse_final[1], &image_final[0], &image_final[1]); diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 7a99f819913..0737218eea4 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -395,7 +395,7 @@ typedef struct ProjPaintState { * helps as an extra validation step for seam detection. */ char *faceWindingFlags; /** expanded UVs for faces to use as seams. */ - LoopSeamData(*loopSeamData); + LoopSeamData *loopSeamData; /** Only needed for when seam_bleed_px is enabled, use to find UV seams. */ LinkNode **vertFaces; /** Seams per vert, to find adjacent seams. */ @@ -627,8 +627,9 @@ static float VecZDepthPersp( w_tmp[1] = w_tmp[1] * wtot_inv; w_tmp[2] = w_tmp[2] * wtot_inv; } - else /* dummy values for zero area face */ + else { /* dummy values for zero area face */ w_tmp[0] = w_tmp[1] = w_tmp[2] = 1.0f / 3.0f; + } /* done mimicking barycentric_weights_v2() */ return (v1[2] * w_tmp[0]) + (v2[2] * w_tmp[1]) + (v3[2] * w_tmp[2]); @@ -644,8 +645,9 @@ static int project_paint_PickFace(const ProjPaintState *ps, const float pt[2], f float z_depth_best = FLT_MAX, z_depth; bucket_index = project_bucket_offset_safe(ps, pt); - if (bucket_index == -1) + if (bucket_index == -1) { return -1; + } /* we could return 0 for 1 face buckets, as long as this function assumes * that the point its testing is only every originated from an existing face */ @@ -686,10 +688,12 @@ static void uvco_to_wrapped_pxco(const float uv[2], int ibuf_x, int ibuf_y, floa *x = fmodf(uv[0], 1.0f); *y = fmodf(uv[1], 1.0f); - if (*x < 0.0f) + if (*x < 0.0f) { *x += 1.0f; - if (*y < 0.0f) + } + if (*y < 0.0f) { *y += 1.0f; + } *x = *x * ibuf_x - 0.5f; *y = *y * ibuf_y - 0.5f; @@ -713,8 +717,9 @@ static bool project_paint_PickColor(const ProjPaintState *ps, tri_index = project_paint_PickFace(ps, pt, w); - if (tri_index == -1) + if (tri_index == -1) { return 0; + } lt = &ps->mlooptri_eval[tri_index]; PS_LOOPTRI_ASSIGN_UV_3(lt_tri_uv, ps->poly_to_loop_uv, lt); @@ -724,8 +729,9 @@ static bool project_paint_PickColor(const ProjPaintState *ps, ima = project_paint_face_paint_image(ps, tri_index); /** we must have got the imbuf before getting here. */ ibuf = BKE_image_get_first_ibuf(ima); - if (!ibuf) + if (!ibuf) { return 0; + } if (interp) { float x, y; @@ -753,9 +759,9 @@ static bool project_paint_PickColor(const ProjPaintState *ps, } } else { - //xi = (int)((uv[0]*ibuf->x) + 0.5f); - //yi = (int)((uv[1]*ibuf->y) + 0.5f); - //if (xi < 0 || xi >= ibuf->x || yi < 0 || yi >= ibuf->y) return 0; + // xi = (int)((uv[0]*ibuf->x) + 0.5f); + // yi = (int)((uv[1]*ibuf->y) + 0.5f); + // if (xi < 0 || xi >= ibuf->x || yi < 0 || yi >= ibuf->y) return 0; /* wrap */ xi = mod_i((int)(uv[0] * ibuf->x), ibuf->x); @@ -802,12 +808,14 @@ static int project_paint_occlude_ptv(const float pt[3], const bool is_ortho) { /* if all are behind us, return false */ - if (v1[2] > pt[2] && v2[2] > pt[2] && v3[2] > pt[2]) + if (v1[2] > pt[2] && v2[2] > pt[2] && v3[2] > pt[2]) { return 0; + } /* do a 2D point in try intersection */ - if (!isect_point_tri_v2(pt, v1, v2, v3)) + if (!isect_point_tri_v2(pt, v1, v2, v3)) { return 0; + } /* From here on we know there IS an intersection */ /* if ALL of the verts are infront of us then we know it intersects ? */ @@ -818,12 +826,14 @@ static int project_paint_occlude_ptv(const float pt[3], /* we intersect? - find the exact depth at the point of intersection */ /* Is this point is occluded by another face? */ if (is_ortho) { - if (VecZDepthOrtho(pt, v1, v2, v3, w) < pt[2]) + if (VecZDepthOrtho(pt, v1, v2, v3, w) < pt[2]) { return 2; + } } else { - if (VecZDepthPersp(pt, v1, v2, v3, w) < pt[2]) + if (VecZDepthPersp(pt, v1, v2, v3, w) < pt[2]) { return 2; + } } } return -1; @@ -843,8 +853,9 @@ static int project_paint_occlude_ptv_clip(const float pt[3], float wco[3]; int ret = project_paint_occlude_ptv(pt, v1, v2, v3, w, is_ortho); - if (ret <= 0) + if (ret <= 0) { return ret; + } if (ret == 1) { /* weights not calculated */ if (is_ortho) { @@ -1009,15 +1020,19 @@ static bool cmp_uv(const float vec2a[2], const float vec2b[2]) float xb = fmodf(vec2b[0], 1.0f); float yb = fmodf(vec2b[1], 1.0f); - if (xa < 0.0f) + if (xa < 0.0f) { xa += 1.0f; - if (ya < 0.0f) + } + if (ya < 0.0f) { ya += 1.0f; + } - if (xb < 0.0f) + if (xb < 0.0f) { xb += 1.0f; - if (yb < 0.0f) + } + if (yb < 0.0f) { yb += 1.0f; + } return ((fabsf(xa - xb) < PROJ_GEOM_TOLERANCE) && (fabsf(ya - yb) < PROJ_GEOM_TOLERANCE)) ? 1 : 0; @@ -1093,8 +1108,9 @@ static void project_face_winding_init(const ProjPaintState *ps, const int tri_in const float *lt_tri_uv[3] = {PS_LOOPTRI_AS_UV_3(ps->poly_to_loop_uv, lt)}; float winding = cross_tri_v2(lt_tri_uv[0], lt_tri_uv[1], lt_tri_uv[2]); - if (winding > 0) + if (winding > 0) { ps->faceWindingFlags[tri_index] |= PROJ_FACE_WINDING_CW; + } ps->faceWindingFlags[tri_index] |= PROJ_FACE_WINDING_INIT; } @@ -1131,7 +1147,8 @@ static bool check_seam(const ProjPaintState *ps, i1_fidx = BKE_MESH_TESSTRI_VINDEX_ORDER(lt_vtri, i1); i2_fidx = BKE_MESH_TESSTRI_VINDEX_ORDER(lt_vtri, i2); - /* Only need to check if 'i2_fidx' is valid because we know i1_fidx is the same vert on both faces */ + /* Only need to check if 'i2_fidx' is valid because + * we know i1_fidx is the same vert on both faces. */ if (i2_fidx != -1) { const float *lt_tri_uv[3] = {PS_LOOPTRI_AS_UV_3(ps->poly_to_loop_uv, lt)}; Image *tpage = project_paint_face_paint_image(ps, tri_index); @@ -1148,8 +1165,9 @@ static bool check_seam(const ProjPaintState *ps, *orig_fidx = (i1_fidx < i2_fidx && (i2_fidx - i1_fidx == 1)) ? i1_fidx : i2_fidx; /* initialize face winding if needed */ - if ((ps->faceWindingFlags[tri_index] & PROJ_FACE_WINDING_INIT) == 0) + if ((ps->faceWindingFlags[tri_index] & PROJ_FACE_WINDING_INIT) == 0) { project_face_winding_init(ps, tri_index); + } /* first test if they have the same image */ if ((orig_tpage == tpage) && cmp_uv(orig_lt_tri_uv[orig_i1_fidx], lt_tri_uv[i1_fidx]) && @@ -1392,11 +1410,11 @@ static void insert_seam_vert_array(const ProjPaintState *ps, } } -/* - * Be tricky with flags, first 4 bits are PROJ_FACE_SEAM0 to 4, last 4 bits are PROJ_FACE_NOSEAM0 to 4 - * 1<<i - where i is (0-3) +/** + * Be tricky with flags, first 4 bits are #PROJ_FACE_SEAM0 to 4, + * last 4 bits are #PROJ_FACE_NOSEAM0 to 4. `1 << i` - where i is `(0..3)`. * - * If we're multithreadng, make sure threads are locked when this is called + * If we're multithreadng, make sure threads are locked when this is called. */ static void project_face_seams_init(const ProjPaintState *ps, MemArena *arena, @@ -1414,8 +1432,9 @@ static void project_face_seams_init(const ProjPaintState *ps, LinkNode *node; /* initialize face winding if needed */ - if ((ps->faceWindingFlags[tri_index] & PROJ_FACE_WINDING_INIT) == 0) + if ((ps->faceWindingFlags[tri_index] & PROJ_FACE_WINDING_INIT) == 0) { project_face_winding_init(ps, tri_index); + } do { if (init_all || (ps->mloop_eval[lt->tri[fidx[0]]].v == vert_index) || @@ -1427,7 +1446,8 @@ static void project_face_seams_init(const ProjPaintState *ps, insert_seam_vert_array(ps, arena, tri_index, fidx[0], ibuf_x, ibuf_y); if (other_face != -1) { - /* Check if the other seam is already set. We don't want to insert it in the list twice. */ + /* Check if the other seam is already set. + * We don't want to insert it in the list twice. */ if ((ps->faceSeamFlags[other_face] & (PROJ_FACE_SEAM0 << other_fidx)) == 0) { ps->faceSeamFlags[other_face] |= PROJ_FACE_SEAM0 << other_fidx; insert_seam_vert_array(ps, arena, other_face, other_fidx, ibuf_x, ibuf_y); @@ -1752,8 +1772,8 @@ static float project_paint_uvpixel_mask(const ProjPaintState *ps, } /* otherwise no mask normal is needed, were within the limit */ } - /* This only works when the opacity doesn't change while painting, stylus pressure messes with this - * so don't use it. */ + /* This only works when the opacity doesn't change while painting, stylus pressure messes with + * this so don't use it. */ // if (ps->is_airbrush == 0) mask *= BKE_brush_alpha_get(ps->brush); return mask; @@ -1777,14 +1797,16 @@ static int project_paint_undo_subtiles(const TileInfo *tinf, int tx, int ty) /* double check lock to avoid locking */ if (UNLIKELY(!pjIma->undoRect[tile_index])) { - if (tinf->lock) + if (tinf->lock) { BLI_spin_lock(tinf->lock); + } if (LIKELY(!pjIma->undoRect[tile_index])) { pjIma->undoRect[tile_index] = TILE_PENDING; generate_tile = true; } - if (tinf->lock) + if (tinf->lock) { BLI_spin_unlock(tinf->lock); + } } if (generate_tile) { @@ -1817,11 +1839,13 @@ static int project_paint_undo_subtiles(const TileInfo *tinf, int tx, int ty) pjIma->ibuf->userflags |= IB_BITMAPDIRTY; /* tile ready, publish */ - if (tinf->lock) + if (tinf->lock) { BLI_spin_lock(tinf->lock); + } pjIma->undoRect[tile_index] = undorect; - if (tinf->lock) + if (tinf->lock) { BLI_spin_unlock(tinf->lock); + } } return tile_index; @@ -1864,14 +1888,15 @@ static ProjPixel *project_paint_uvpixel_init(const ProjPaintState *ps, x_round = x_tile * IMAPAINT_TILE_SIZE; y_round = y_tile * IMAPAINT_TILE_SIZE; - //memset(projPixel, 0, size); + // memset(projPixel, 0, size); tile_offset = (x_px - x_round) + (y_px - y_round) * IMAPAINT_TILE_SIZE; tile_index = project_paint_undo_subtiles(tinf, x_tile, y_tile); /* other thread may be initializing the tile so wait here */ - while (projima->undoRect[tile_index] == TILE_PENDING) + while (projima->undoRect[tile_index] == TILE_PENDING) { ; + } BLI_assert(tile_index < (IMAPAINT_TILE_NUMBER(ibuf->x) * IMAPAINT_TILE_NUMBER(ibuf->y))); BLI_assert(tile_offset < (IMAPAINT_TILE_SIZE * IMAPAINT_TILE_SIZE)); @@ -1900,10 +1925,12 @@ static ProjPixel *project_paint_uvpixel_init(const ProjPaintState *ps, projPixel->y_px = y_px; projPixel->mask = (unsigned short)(mask * 65535); - if (ps->do_masking) + if (ps->do_masking) { projPixel->mask_accum = projima->maskRect[tile_index] + tile_offset; - else + } + else { projPixel->mask_accum = NULL; + } /* which bounding box cell are we in?, needed for undo */ projPixel->bb_cell_index = ((int)(((float)x_px / (float)ibuf->x) * PROJ_BOUNDBOX_DIV)) + @@ -1993,10 +2020,12 @@ static ProjPixel *project_paint_uvpixel_init(const ProjPaintState *ps, } #ifdef PROJ_DEBUG_PAINT - if (ibuf->rect_float) + if (ibuf->rect_float) { projPixel->pixel.f_pt[0] = 0; - else + } + else { projPixel->pixel.ch_pt[0] = 0; + } #endif /* pointer arithmetic */ projPixel->image_index = projima - ps->projImages; @@ -2089,8 +2118,9 @@ static bool line_clip_rect2f(const rctf *cliprect, } /* line inside rect */ - if (ok1 && ok2) + if (ok1 && ok2) { return 1; + } /* top/bottom */ if (line_isect_y(l1, l2, rect->ymin, &isect) && (isect >= cliprect->xmin) && @@ -2107,8 +2137,9 @@ static bool line_clip_rect2f(const rctf *cliprect, } } - if (ok1 && ok2) + if (ok1 && ok2) { return 1; + } if (line_isect_y(l1, l2, rect->ymax, &isect) && (isect >= cliprect->xmin) && (isect <= cliprect->xmax)) { @@ -2124,8 +2155,9 @@ static bool line_clip_rect2f(const rctf *cliprect, } } - if (ok1 && ok2) + if (ok1 && ok2) { return 1; + } /* left/right */ if (line_isect_x(l1, l2, rect->xmin, &isect) && (isect >= cliprect->ymin) && @@ -2142,8 +2174,9 @@ static bool line_clip_rect2f(const rctf *cliprect, } } - if (ok1 && ok2) + if (ok1 && ok2) { return 1; + } if (line_isect_x(l1, l2, rect->xmax, &isect) && (isect >= cliprect->ymin) && (isect <= cliprect->ymax)) { @@ -2170,8 +2203,8 @@ static bool line_clip_rect2f(const rctf *cliprect, /** * Scale the tri about its center - * scaling by #PROJ_FACE_SCALE_SEAM (0.99x) is used for getting fake UV pixel coords that are on the - * edge of the face but slightly inside it occlusion tests don't return hits on adjacent faces + * scaling by #PROJ_FACE_SCALE_SEAM (0.99x) is used for getting fake UV pixel coords that are on + * the edge of the face but slightly inside it occlusion tests don't return hits on adjacent faces. */ #ifndef PROJ_DEBUG_NOSEAMBLEED @@ -2194,7 +2227,7 @@ static void scale_tri(float insetCos[3][3], const float *origCos[4], const float add_v3_v3(insetCos[1], cent); add_v3_v3(insetCos[2], cent); } -#endif //PROJ_DEBUG_NOSEAMBLEED +#endif // PROJ_DEBUG_NOSEAMBLEED static float len_squared_v2v2_alt(const float v1[2], const float v2_1, const float v2_2) { @@ -2205,17 +2238,21 @@ static float len_squared_v2v2_alt(const float v1[2], const float v2_1, const flo return x * x + y * y; } -/* note, use a squared value so we can use len_squared_v2v2 - * be sure that you have done a bounds check first or this may fail */ -/* only give bucket_bounds as an arg because we need it elsewhere */ +/** + * \note Use a squared value so we can use #len_squared_v2v2 + * be sure that you have done a bounds check first or this may fail. + * + * Only give \a bucket_bounds as an arg because we need it elsewhere. + */ static bool project_bucket_isect_circle(const float cent[2], const float radius_squared, const rctf *bucket_bounds) { - /* Would normally to a simple intersection test, however we know the bounds of these 2 already intersect - * so we only need to test if the center is inside the vertical or horizontal bounds on either axis, - * this is even less work then an intersection test + /* Would normally to a simple intersection test, + * however we know the bounds of these 2 already intersect so we only need to test + * if the center is inside the vertical or horizontal bounds on either axis, + * this is even less work then an intersection test. */ #if 0 if (BLI_rctf_isect_pt_v(bucket_bounds, cent)) @@ -2266,8 +2303,8 @@ static bool project_bucket_isect_circle(const float cent[2], /* Note for rect_to_uvspace_ortho() and rect_to_uvspace_persp() * in ortho view this function gives good results when bucket_bounds are outside the triangle - * however in some cases, perspective view will mess up with faces that have minimal screenspace area - * (viewed from the side) + * however in some cases, perspective view will mess up with faces + * that have minimal screenspace area (viewed from the side). * * for this reason its not reliable in this case so we'll use the Simple Barycentric' * funcs that only account for points inside the triangle. @@ -2292,17 +2329,17 @@ static void rect_to_uvspace_ortho(const rctf *bucket_bounds, barycentric_weights_v2(v1coSS, v2coSS, v3coSS, uv, w); interp_v2_v2v2v2(bucket_bounds_uv[flip ? 3 : 0], uv1co, uv2co, uv3co, w); - //uv[0] = bucket_bounds->xmax; // set above + // uv[0] = bucket_bounds->xmax; // set above uv[1] = bucket_bounds->ymax; barycentric_weights_v2(v1coSS, v2coSS, v3coSS, uv, w); interp_v2_v2v2v2(bucket_bounds_uv[flip ? 2 : 1], uv1co, uv2co, uv3co, w); uv[0] = bucket_bounds->xmin; - //uv[1] = bucket_bounds->ymax; // set above + // uv[1] = bucket_bounds->ymax; // set above barycentric_weights_v2(v1coSS, v2coSS, v3coSS, uv, w); interp_v2_v2v2v2(bucket_bounds_uv[flip ? 1 : 2], uv1co, uv2co, uv3co, w); - //uv[0] = bucket_bounds->xmin; // set above + // uv[0] = bucket_bounds->xmin; // set above uv[1] = bucket_bounds->ymin; barycentric_weights_v2(v1coSS, v2coSS, v3coSS, uv, w); interp_v2_v2v2v2(bucket_bounds_uv[flip ? 0 : 3], uv1co, uv2co, uv3co, w); @@ -2328,17 +2365,17 @@ static void rect_to_uvspace_persp(const rctf *bucket_bounds, barycentric_weights_v2_persp(v1coSS, v2coSS, v3coSS, uv, w); interp_v2_v2v2v2(bucket_bounds_uv[flip ? 3 : 0], uv1co, uv2co, uv3co, w); - //uv[0] = bucket_bounds->xmax; // set above + // uv[0] = bucket_bounds->xmax; // set above uv[1] = bucket_bounds->ymax; barycentric_weights_v2_persp(v1coSS, v2coSS, v3coSS, uv, w); interp_v2_v2v2v2(bucket_bounds_uv[flip ? 2 : 1], uv1co, uv2co, uv3co, w); uv[0] = bucket_bounds->xmin; - //uv[1] = bucket_bounds->ymax; // set above + // uv[1] = bucket_bounds->ymax; // set above barycentric_weights_v2_persp(v1coSS, v2coSS, v3coSS, uv, w); interp_v2_v2v2v2(bucket_bounds_uv[flip ? 1 : 2], uv1co, uv2co, uv3co, w); - //uv[0] = bucket_bounds->xmin; // set above + // uv[0] = bucket_bounds->xmin; // set above uv[1] = bucket_bounds->ymin; barycentric_weights_v2_persp(v1coSS, v2coSS, v3coSS, uv, w); interp_v2_v2v2v2(bucket_bounds_uv[flip ? 0 : 3], uv1co, uv2co, uv3co, w); @@ -2351,8 +2388,10 @@ static float angle_2d_clockwise(const float p1[2], const float p2[2], const floa { float v1[2], v2[2]; - v1[0] = p1[0] - p2[0]; v1[1] = p1[1] - p2[1]; - v2[0] = p3[0] - p2[0]; v2[1] = p3[1] - p2[1]; + v1[0] = p1[0] - p2[0]; + v1[1] = p1[1] - p2[1]; + v2[0] = p3[0] - p2[0]; + v2[1] = p3[1] - p2[1]; return -atan2f(v1[0] * v2[1] - v1[1] * v2[0], v1[0] * v2[0] + v1[1] * v2[1]); } @@ -2422,8 +2461,9 @@ static bool line_rect_clip(const rctf *rect, } } - if (min == FLT_MAX) + if (min == FLT_MAX) { return false; + } tmp = (is_ortho) ? 1.0f : (l1[3] + min * (l2[3] - l1[3])); @@ -2496,8 +2536,9 @@ static void project_bucket_clip_face(const bool is_ortho, (*tot) = 0; - if (cull) + if (cull) { return; + } if (inside_bucket_flag & ISECT_1) { copy_v2_v2(bucket_bounds_uv[*tot], uv1co); @@ -2507,8 +2548,9 @@ static void project_bucket_clip_face(const bool is_ortho, flag = inside_bucket_flag & (ISECT_1 | ISECT_2); if (flag && flag != (ISECT_1 | ISECT_2)) { if (line_rect_clip( - bucket_bounds, v1coSS, v2coSS, uv1co, uv2co, bucket_bounds_uv[*tot], is_ortho)) + bucket_bounds, v1coSS, v2coSS, uv1co, uv2co, bucket_bounds_uv[*tot], is_ortho)) { (*tot)++; + } } if (inside_bucket_flag & ISECT_2) { @@ -2519,8 +2561,9 @@ static void project_bucket_clip_face(const bool is_ortho, flag = inside_bucket_flag & (ISECT_2 | ISECT_3); if (flag && flag != (ISECT_2 | ISECT_3)) { if (line_rect_clip( - bucket_bounds, v2coSS, v3coSS, uv2co, uv3co, bucket_bounds_uv[*tot], is_ortho)) + bucket_bounds, v2coSS, v3coSS, uv2co, uv3co, bucket_bounds_uv[*tot], is_ortho)) { (*tot)++; + } } if (inside_bucket_flag & ISECT_3) { @@ -2531,8 +2574,9 @@ static void project_bucket_clip_face(const bool is_ortho, flag = inside_bucket_flag & (ISECT_3 | ISECT_1); if (flag && flag != (ISECT_3 | ISECT_1)) { if (line_rect_clip( - bucket_bounds, v3coSS, v1coSS, uv3co, uv1co, bucket_bounds_uv[*tot], is_ortho)) + bucket_bounds, v3coSS, v1coSS, uv3co, uv1co, bucket_bounds_uv[*tot], is_ortho)) { (*tot)++; + } } if ((*tot) < 3) { @@ -2735,10 +2779,12 @@ static void project_bucket_clip_face(const bool is_ortho, v1_clipSS[0] * v2_clipSS[0] + v1_clipSS[1] * v2_clipSS[1]); } - if (flip) + if (flip) { qsort(isectVCosSS, *tot, sizeof(float) * 3, float_z_sort_flip); - else + } + else { qsort(isectVCosSS, *tot, sizeof(float) * 3, float_z_sort); + } doubles = true; while (doubles == true) { @@ -2787,12 +2833,14 @@ static void project_bucket_clip_face(const bool is_ortho, /* If there are ever any problems, */ float test_uv[4][2]; int i; - if (is_ortho) + if (is_ortho) { rect_to_uvspace_ortho( bucket_bounds, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, test_uv, flip); - else + } + else { rect_to_uvspace_persp( bucket_bounds, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, test_uv, flip); + } printf("( [(%f,%f), (%f,%f), (%f,%f), (%f,%f)], ", test_uv[0][0], test_uv[0][1], @@ -2878,12 +2926,14 @@ static void project_bucket_clip_face(const bool is_ortho, static bool IsectPoly2Df(const float pt[2], float uv[][2], const int tot) { int i; - if (line_point_side_v2(uv[tot - 1], uv[0], pt) < 0.0f) + if (line_point_side_v2(uv[tot - 1], uv[0], pt) < 0.0f) { return 0; + } for (i = 1; i < tot; i++) { - if (line_point_side_v2(uv[i - 1], uv[i], pt) < 0.0f) + if (line_point_side_v2(uv[i - 1], uv[i], pt) < 0.0f) { return 0; + } } return 1; @@ -2894,8 +2944,9 @@ static bool IsectPoly2Df_twoside(const float pt[2], float uv[][2], const int tot bool side = (line_point_side_v2(uv[tot - 1], uv[0], pt) > 0.0f); for (i = 1; i < tot; i++) { - if ((line_point_side_v2(uv[i - 1], uv[i], pt) > 0.0f) != side) + if ((line_point_side_v2(uv[i - 1], uv[i], pt) > 0.0f) != side) { return 0; + } } return 1; @@ -3025,7 +3076,8 @@ static void project_paint_face_init(const ProjPaintState *ps, &uv_clip_tot, do_backfacecull || ps->do_occlude); - /* sometimes this happens, better just allow for 8 intersectiosn even though there should be max 6 */ + /* Sometimes this happens, better just allow for 8 intersections + * even though there should be max 6 */ #if 0 if (uv_clip_tot > 6) { printf("this should never happen! %d\n", uv_clip_tot); @@ -3035,20 +3087,19 @@ static void project_paint_face_init(const ProjPaintState *ps, if (pixel_bounds_array(uv_clip, &bounds_px, ibuf->x, ibuf->y, uv_clip_tot)) { #if 0 project_paint_undo_tiles_init( - &bounds_px, ps->projImages + image_index, tmpibuf, - tile_width, threaded, ps->do_masking); + &bounds_px, ps->projImages + image_index, tmpibuf, tile_width, threaded, ps->do_masking); #endif /* clip face and */ has_isect = 0; for (y = bounds_px.ymin; y < bounds_px.ymax; y++) { - //uv[1] = (((float)y) + 0.5f) / (float)ibuf->y; + // uv[1] = (((float)y) + 0.5f) / (float)ibuf->y; /* use pixel offset UV coords instead */ uv[1] = (float)y / ibuf_yf; has_x_isect = 0; for (x = bounds_px.xmin; x < bounds_px.xmax; x++) { - //uv[0] = (((float)x) + 0.5f) / ibuf->x; + // uv[0] = (((float)x) + 0.5f) / ibuf->x; /* use pixel offset UV coords instead */ uv[0] = (float)x / ibuf_xf; @@ -3059,12 +3110,14 @@ static void project_paint_face_init(const ProjPaintState *ps, has_x_isect = has_isect = 1; - if (is_ortho) + if (is_ortho) { screen_px_from_ortho( uv, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, pixelScreenCo, w); - else + } + else { screen_px_from_persp( uv, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, pixelScreenCo, w); + } /* a pity we need to get the worldspace pixel location here */ if (do_clip || do_3d_mapping) { @@ -3081,7 +3134,7 @@ static void project_paint_face_init(const ProjPaintState *ps, /* Is this UV visible from the view? - raytrace */ /* project_paint_PickFace is less complex, use for testing */ - //if (project_paint_PickFace(ps, pixelScreenCo, w, &side) == tri_index) { + // if (project_paint_PickFace(ps, pixelScreenCo, w, &side) == tri_index) { if ((ps->do_occlude == false) || !project_bucket_point_occluded(ps, bucketFaceNodes, tri_index, pixelScreenCo)) { mask = project_paint_uvpixel_mask(ps, tri_index, w); @@ -3131,7 +3184,12 @@ static void project_paint_face_init(const ProjPaintState *ps, (face_seam_flag & PROJ_FACE_SEAM_INIT2) == 0) { project_face_seams_init(ps, arena, tri_index, 0, true, ibuf->x, ibuf->y); face_seam_flag = ps->faceSeamFlags[tri_index]; - //printf("seams - %d %d %d %d\n", flag&PROJ_FACE_SEAM0, flag&PROJ_FACE_SEAM1, flag&PROJ_FACE_SEAM2); +# if 0 + printf("seams - %d %d %d %d\n", + flag & PROJ_FACE_SEAM0, + flag & PROJ_FACE_SEAM1, + flag & PROJ_FACE_SEAM2); +# endif } if ((face_seam_flag & (PROJ_FACE_SEAM0 | PROJ_FACE_SEAM1 | PROJ_FACE_SEAM2)) == 0) { @@ -3249,7 +3307,7 @@ static void project_paint_face_init(const ProjPaintState *ps, for (x = bounds_px.xmin; x < bounds_px.xmax; x++) { float puv[2] = {(float)x, (float)y}; bool in_bounds; - //uv[0] = (((float)x) + 0.5f) / (float)ibuf->x; + // uv[0] = (((float)x) + 0.5f) / (float)ibuf->x; /* use offset uvs instead */ uv[0] = (float)x / ibuf_xf; @@ -3475,8 +3533,9 @@ static void project_bucket_init(const ProjPaintState *ps, } } - if (tmpibuf) + if (tmpibuf) { IMB_freeImBuf(tmpibuf); + } ps->bucketFlags[bucket_index] |= PROJ_BUCKET_INIT; } @@ -3821,8 +3880,9 @@ static void proj_paint_state_cavity_init(ProjPaintState *ps) /* augment the diffe*/ cavities[a] = saacos(10.0f * dot_v3v3(no, edges[a])) * (float)M_1_PI; } - else + else { cavities[a] = 0.0; + } } MEM_freeN(counter); @@ -3858,8 +3918,9 @@ static void proj_paint_state_thread_init(ProjPaintState *ps, const bool reset_th /* workaround for #35057, disable threading if diameter is less than is possible for * optimum bucket number generation */ - if (reset_threads) + if (reset_threads) { ps->thread_tot = 1; + } if (ps->is_shared_user == false) { if (ps->thread_tot > 1) { @@ -4035,8 +4096,9 @@ static void proj_paint_layer_clone_init(ProjPaintState *ps, ProjPaintLayerClone ps->poly_to_loop_uv_clone = MEM_mallocN(ps->totpoly_eval * sizeof(MLoopUV *), "proj_paint_mtfaces"); - if (layer_num != -1) + if (layer_num != -1) { mloopuv_clone_base = CustomData_get_layer_n(&ps->me_eval->ldata, CD_MLOOPUV, layer_num); + } if (mloopuv_clone_base == NULL) { /* get active instead */ @@ -4058,11 +4120,13 @@ static bool project_paint_clone_face_skip(ProjPaintState *ps, if (ps->do_material_slots) { lc->slot_clone = project_paint_face_clone_slot(ps, tri_index); /* all faces should have a valid slot, reassert here */ - if (ELEM(lc->slot_clone, NULL, slot)) + if (ELEM(lc->slot_clone, NULL, slot)) { return true; + } } - else if (ps->clone_ima == ps->canvas_ima) + else if (ps->clone_ima == ps->canvas_ima) { return true; + } if (ps->do_material_slots) { if (lc->slot_clone != lc->slot_last_clone) { @@ -4164,7 +4228,7 @@ static bool project_paint_winclip(const ProjPaintState *ps, const ProjPaintFaceC (coSS->v1[1] > ps->screenMax[1] && coSS->v2[1] > ps->screenMax[1] && coSS->v3[1] > ps->screenMax[1]))); } -#endif //PROJ_DEBUG_WINCLIP +#endif // PROJ_DEBUG_WINCLIP static void project_paint_build_proj_ima(ProjPaintState *ps, MemArena *arena, @@ -4229,8 +4293,9 @@ static void project_paint_prepare_all_faces(ProjPaintState *ps, else { if (slot != slot_last) { if (!slot->uvname || !(mloopuv_base = CustomData_get_layer_named( - &ps->me_eval->ldata, CD_MLOOPUV, slot->uvname))) + &ps->me_eval->ldata, CD_MLOOPUV, slot->uvname))) { mloopuv_base = CustomData_get_layer(&ps->me_eval->ldata, CD_MLOOPUV); + } slot_last = slot; } @@ -4241,6 +4306,7 @@ static void project_paint_prepare_all_faces(ProjPaintState *ps, * It's less trouble to set all faces to valid UV's, * avoiding NULL checks all over. */ skip_tri = true; + tpage = NULL; } else { tpage = slot->ima; @@ -4278,7 +4344,7 @@ static void project_paint_prepare_all_faces(ProjPaintState *ps, continue; } -#endif //PROJ_DEBUG_WINCLIP +#endif // PROJ_DEBUG_WINCLIP /* backface culls individual triangles but mask normal will use polygon */ if (ps->do_backfacecull) { @@ -4383,19 +4449,21 @@ static void project_paint_begin(const bContext *C, proj_paint_layer_clone_init(ps, &layer_clone); if (ps->do_layer_stencil || ps->do_stencil_brush) { - //int layer_num = CustomData_get_stencil_layer(&ps->me_eval->ldata, CD_MLOOPUV); + // int layer_num = CustomData_get_stencil_layer(&ps->me_eval->ldata, CD_MLOOPUV); int layer_num = CustomData_get_stencil_layer(&((Mesh *)ps->ob->data)->ldata, CD_MLOOPUV); - if (layer_num != -1) + if (layer_num != -1) { ps->mloopuv_stencil_eval = CustomData_get_layer_n( &ps->me_eval->ldata, CD_MLOOPUV, layer_num); + } if (ps->mloopuv_stencil_eval == NULL) { /* get active instead */ ps->mloopuv_stencil_eval = CustomData_get_layer(&ps->me_eval->ldata, CD_MLOOPUV); } - if (ps->do_stencil_brush) + if (ps->do_stencil_brush) { mloopuv_base = ps->mloopuv_stencil_eval; + } } /* when using subsurf or multires, mface arrays are thrown away, we need to keep a copy */ @@ -4500,11 +4568,13 @@ static void project_paint_end(ProjPaintState *ps) /* must be set for non-shared */ BLI_assert(ps->poly_to_loop_uv || ps->is_shared_user); - if (ps->poly_to_loop_uv) + if (ps->poly_to_loop_uv) { MEM_freeN((void *)ps->poly_to_loop_uv); + } - if (ps->do_layer_clone) + if (ps->do_layer_clone) { MEM_freeN((void *)ps->poly_to_loop_uv_clone); + } if (ps->thread_tot > 1) { BLI_spin_end(ps->tile_lock); MEM_freeN((void *)ps->tile_lock); @@ -4537,8 +4607,9 @@ static void project_paint_end(ProjPaintState *ps) MEM_freeN(ps->blurkernel); } - if (ps->vertFlags) + if (ps->vertFlags) { MEM_freeN(ps->vertFlags); + } for (a = 0; a < ps->thread_tot; a++) { BLI_memarena_free(ps->arena_mt[a]); @@ -4578,8 +4649,9 @@ static bool partial_redraw_array_merge(ImagePaintPartialRedraw *pr, pr->x2 = max_ii(pr->x2, pr_other->x2); pr->y2 = max_ii(pr->y2, pr_other->y2); - if (pr->x2 != -1) + if (pr->x2 != -1) { touch = 1; + } pr++; pr_other++; @@ -4665,10 +4737,11 @@ static bool project_bucket_iter_next(ProjPaintState *ps, { const int diameter = 2 * ps->brush_size; - if (ps->thread_tot > 1) + if (ps->thread_tot > 1) { BLI_thread_lock(LOCK_CUSTOM1); + } - //printf("%d %d\n", ps->context_bucket_x, ps->context_bucket_y); + // printf("%d %d\n", ps->context_bucket_x, ps->context_bucket_y); for (; ps->context_bucket_y < ps->bucketMax[1]; ps->context_bucket_y++) { for (; ps->context_bucket_x < ps->bucketMax[0]; ps->context_bucket_x++) { @@ -4681,8 +4754,9 @@ static bool project_bucket_iter_next(ProjPaintState *ps, *bucket_index = ps->context_bucket_x + (ps->context_bucket_y * ps->buckets_x); ps->context_bucket_x++; - if (ps->thread_tot > 1) + if (ps->thread_tot > 1) { BLI_thread_unlock(LOCK_CUSTOM1); + } return 1; } @@ -4690,8 +4764,9 @@ static bool project_bucket_iter_next(ProjPaintState *ps, ps->context_bucket_x = ps->bucketMin[0]; } - if (ps->thread_tot > 1) + if (ps->thread_tot > 1) { BLI_thread_unlock(LOCK_CUSTOM1); + } return 0; } @@ -4769,8 +4844,9 @@ static void do_projectpaint_smear(ProjPaintState *ps, { unsigned char rgba_ub[4]; - if (project_paint_PickColor(ps, co, NULL, rgba_ub, 1) == 0) + if (project_paint_PickColor(ps, co, NULL, rgba_ub, 1) == 0) { return; + } blend_color_interpolate_byte( ((ProjPixelClone *)projPixel)->clonepx.ch, projPixel->pixel.ch_pt, rgba_ub, mask); @@ -4786,8 +4862,9 @@ static void do_projectpaint_smear_f(ProjPaintState *ps, { float rgba[4]; - if (project_paint_PickColor(ps, co, rgba, NULL, 1) == 0) + if (project_paint_PickColor(ps, co, rgba, NULL, 1) == 0) { return; + } blend_color_interpolate_float( ((ProjPixelClone *)projPixel)->clonepx.f, projPixel->pixel.f_pt, rgba, mask); @@ -4842,8 +4919,9 @@ static void do_projectpaint_soften_f(ProjPaintState *ps, blend_color_add_float(rgba, projPixel->pixel.f_pt, rgba); rgba[3] = alpha; } - else + else { return; + } } else { blend_color_interpolate_float(rgba, projPixel->pixel.f_pt, rgba, mask); @@ -4909,8 +4987,9 @@ static void do_projectpaint_soften(ProjPaintState *ps, rgba[3] = alpha; premul_float_to_straight_uchar(rgba_ub, rgba); } - else + else { return; + } } else { premul_float_to_straight_uchar(rgba_ub, rgba); @@ -4970,8 +5049,9 @@ static void do_projectpaint_draw_f(ProjPaintState *ps, copy_v3_v3(rgba, ps->paint_color_linear); - if (ps->is_texbrush) + if (ps->is_texbrush) { mul_v3_v3(rgba, texrgb); + } mul_v3_fl(rgba, mask); rgba[3] = mask; @@ -5317,10 +5397,12 @@ static void *do_projectpaint_thread(void *ph_v) float mask_accum = *projPixel->mask_accum; float max_mask = brush_alpha * custom_mask * falloff * 65535.0f; - if (brush->flag & BRUSH_ACCUMULATE) + if (brush->flag & BRUSH_ACCUMULATE) { mask = mask_accum + max_mask; - else + } + else { mask = mask_accum + (max_mask - mask_accum * falloff); + } mask = min_ff(mask, 65535.0f); mask_short = (unsigned short)mask; @@ -5359,37 +5441,47 @@ static void *do_projectpaint_thread(void *ph_v) /* texrgb is not used for clone, smear or soften */ switch (tool) { case PAINT_TOOL_CLONE: - if (is_floatbuf) + if (is_floatbuf) { do_projectpaint_clone_f(ps, projPixel, mask); - else + } + else { do_projectpaint_clone(ps, projPixel, mask); + } break; case PAINT_TOOL_SMEAR: sub_v2_v2v2(co, projPixel->projCoSS, pos_ofs); - if (is_floatbuf) + if (is_floatbuf) { do_projectpaint_smear_f(ps, projPixel, mask, smearArena, &smearPixels_f, co); - else + } + else { do_projectpaint_smear(ps, projPixel, mask, smearArena, &smearPixels, co); + } break; case PAINT_TOOL_SOFTEN: - if (is_floatbuf) + if (is_floatbuf) { do_projectpaint_soften_f(ps, projPixel, mask, softenArena, &softenPixels_f); - else + } + else { do_projectpaint_soften(ps, projPixel, mask, softenArena, &softenPixels); + } break; case PAINT_TOOL_MASK: - if (is_floatbuf) + if (is_floatbuf) { do_projectpaint_mask_f(ps, projPixel, mask); - else + } + else { do_projectpaint_mask(ps, projPixel, mask); + } break; default: - if (is_floatbuf) + if (is_floatbuf) { do_projectpaint_draw_f(ps, projPixel, texrgb, mask); - else + } + else { do_projectpaint_draw( ps, projPixel, texrgb, mask, ps->dither, projPixel->x_px, projPixel->y_px); + } break; } @@ -5463,8 +5555,9 @@ static bool project_paint_op(void *state, const float lastpos[2], const float po return touch_any; } - if (ps->thread_tot > 1) + if (ps->thread_tot > 1) { BLI_threadpool_init(&threads, do_projectpaint_thread, ps->thread_tot); + } pool = BKE_image_pool_new(); @@ -5472,7 +5565,7 @@ static bool project_paint_op(void *state, const float lastpos[2], const float po for (a = 0; a < ps->thread_tot; a++) { /* set defaults in handles */ - //memset(&handles[a], 0, sizeof(BakeShade)); + // memset(&handles[a], 0, sizeof(BakeShade)); handles[a].ps = ps; copy_v2_v2(handles[a].mval, pos); @@ -5497,14 +5590,17 @@ static bool project_paint_op(void *state, const float lastpos[2], const float po handles[a].pool = pool; - if (ps->thread_tot > 1) + if (ps->thread_tot > 1) { BLI_threadpool_insert(&threads, &handles[a]); + } } - if (ps->thread_tot > 1) /* wait for everything to be done */ + if (ps->thread_tot > 1) { /* wait for everything to be done */ BLI_threadpool_end(&threads); - else + } + else { do_projectpaint_thread(&handles[0]); + } BKE_image_pool_free(pool); @@ -5569,8 +5665,9 @@ static void paint_proj_stroke_ps(const bContext *UNUSED(C), ps->brush_size = size; ps->blend = brush->blend; - if (eraser) + if (eraser) { ps->blend = IMB_BLEND_ERASE_ALPHA; + } /* handle gradient and inverted stroke color here */ if (ELEM(ps->tool, PAINT_TOOL_DRAW, PAINT_TOOL_FILL)) { @@ -5710,8 +5807,9 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int ps->do_backfacecull = ps->do_occlude = ps->do_mask_normal = 0; } - if (ps->tool == PAINT_TOOL_CLONE) + if (ps->tool == PAINT_TOOL_CLONE) { ps->do_layer_clone = (settings->imapaint.flag & IMAGEPAINT_PROJECT_LAYER_CLONE) ? 1 : 0; + } ps->do_stencil_brush = (ps->brush && ps->brush->imagepaint_tool == PAINT_TOOL_MASK); /* deactivate stenciling for the stencil brush :) */ @@ -5814,8 +5912,9 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m } /* Don't allow brush size below 2 */ - if (BKE_brush_size_get(scene, ps_handle->brush) < 2) + if (BKE_brush_size_get(scene, ps_handle->brush) < 2) { BKE_brush_size_set(scene, ps_handle->brush, 2 * U.pixelsize); + } /* allocate and initialize spatial data structures */ @@ -6074,10 +6173,12 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) maxsize = GPU_max_texture_size(); - if (w > maxsize) + if (w > maxsize) { w = maxsize; - if (h > maxsize) + } + if (h > maxsize) { h = maxsize; + } ibuf = ED_view3d_draw_offscreen_imbuf(depsgraph, scene, @@ -6242,14 +6343,18 @@ bool BKE_paint_proj_mesh_data_check( } } - if (!hasuvs) + if (!hasuvs) { imapaint->missing_data |= IMAGEPAINT_MISSING_UVS; - if (!hasmat) + } + if (!hasmat) { imapaint->missing_data |= IMAGEPAINT_MISSING_MATERIAL; - if (!hastex) + } + if (!hastex) { imapaint->missing_data |= IMAGEPAINT_MISSING_TEX; - if (!hasstencil) + } + if (!hasstencil) { imapaint->missing_data |= IMAGEPAINT_MISSING_STENCIL; + } if (uvs) { *uvs = hasuvs; @@ -6373,8 +6478,9 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op) Material *ma; Image *ima = NULL; - if (!ob) + if (!ob) { return false; + } ma = give_current_material(ob, ob->actcol); diff --git a/source/blender/editors/sculpt_paint/paint_image_undo.c b/source/blender/editors/sculpt_paint/paint_image_undo.c index 68abdfbf95b..b80144ac4af 100644 --- a/source/blender/editors/sculpt_paint/paint_image_undo.c +++ b/source/blender/editors/sculpt_paint/paint_image_undo.c @@ -417,7 +417,8 @@ static void paint_undosys_step_decode_restore_ids(ImageUndoStep *us) { ID *image_prev[2] = {NULL}; for (UndoImageTile *tile = us->tiles.first; tile; tile = tile->next) { - tile->ima = (Image *)BKE_undosys_ID_map_lookup_with_prev(us->id_map, &tile->ima->id, image_prev); + tile->ima = (Image *)BKE_undosys_ID_map_lookup_with_prev( + us->id_map, &tile->ima->id, image_prev); } } #endif diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 1a8d2f79290..ea4814857ba 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -279,9 +279,6 @@ struct ListBase *ED_image_undosys_step_get_tiles(struct UndoStep *us_p); struct ListBase *ED_image_undo_get_tiles(void); /* sculpt_uv.c */ -bool uv_sculpt_poll(struct bContext *C); -bool uv_sculpt_keymap_poll(struct bContext *C); - void SCULPT_OT_uv_sculpt_stroke(struct wmOperatorType *ot); /* paint_utils.c */ diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c index ca48030daed..79d09967b75 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.c +++ b/source/blender/editors/sculpt_paint/paint_mask.c @@ -121,8 +121,9 @@ static void mask_flood_fill_task_cb(void *__restrict userdata, BKE_pbvh_vertex_iter_end; BKE_pbvh_node_mark_redraw(node); - if (data->multires) + if (data->multires) { BKE_pbvh_node_mark_normals_update(node); + } } static int mask_flood_fill_exec(bContext *C, wmOperator *op) @@ -166,13 +167,15 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op) 0, totnode, &data, mask_flood_fill_task_cb, &settings); - if (multires) + if (multires) { multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED); + } sculpt_undo_push_end(); - if (nodes) + if (nodes) { MEM_freeN(nodes); + } ED_region_tag_redraw(ar); @@ -217,18 +220,24 @@ static bool is_effected(float planes[4][4], const float co[3]) static void flip_plane(float out[4], const float in[4], const char symm) { - if (symm & PAINT_SYMM_X) + if (symm & PAINT_SYMM_X) { out[0] = -in[0]; - else + } + else { out[0] = in[0]; - if (symm & PAINT_SYMM_Y) + } + if (symm & PAINT_SYMM_Y) { out[1] = -in[1]; - else + } + else { out[1] = in[1]; - if (symm & PAINT_SYMM_Z) + } + if (symm & PAINT_SYMM_Z) { out[2] = -in[2]; - else + } + else { out[2] = in[2]; + } out[3] = in[3]; } @@ -257,8 +266,9 @@ static void mask_box_select_task_cb(void *__restrict userdata, sculpt_undo_push_node(data->ob, node, SCULPT_UNDO_MASK); BKE_pbvh_node_mark_redraw(node); - if (data->multires) + if (data->multires) { BKE_pbvh_node_mark_normals_update(node); + } } mask_flood_fill_set_elem(vi.mask, mode, value); } @@ -326,13 +336,15 @@ bool ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti * totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, mask_box_select_task_cb, &settings); - if (nodes) + if (nodes) { MEM_freeN(nodes); + } } } - if (multires) + if (multires) { multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED); + } sculpt_undo_push_end(); @@ -354,9 +366,10 @@ typedef struct LassoMaskData { MaskTaskData task_data; } LassoMaskData; -/* Lasso select. This could be defined as part of VIEW3D_OT_select_lasso, still the shortcuts conflict, - * so we will use a separate operator */ - +/** + * Lasso select. This could be defined as part of #VIEW3D_OT_select_lasso, + * still the shortcuts conflict, so we will use a separate operator. + */ static bool is_effected_lasso(LassoMaskData *data, float co[3]) { float scr_co_f[2]; @@ -416,8 +429,9 @@ static void mask_gesture_lasso_task_cb(void *__restrict userdata, sculpt_undo_push_node(data->ob, node, SCULPT_UNDO_MASK); BKE_pbvh_node_mark_redraw(node); - if (data->multires) + if (data->multires) { BKE_pbvh_node_mark_normals_update(node); + } } mask_flood_fill_set_elem(vi.mask, mode, value); @@ -510,13 +524,15 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op) (totnode > SCULPT_THREADED_LIMIT)); BLI_task_parallel_range(0, totnode, &data, mask_gesture_lasso_task_cb, &settings); - if (nodes) + if (nodes) { MEM_freeN(nodes); + } } } - if (multires) + if (multires) { multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED); + } sculpt_undo_push_end(); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 6686e255b08..f58afcdadc1 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -168,8 +168,9 @@ static int brush_scale_size_exec(bContext *C, wmOperator *op) { float unprojected_radius = scalar * BKE_brush_unprojected_radius_get(scene, brush); - if (unprojected_radius < 0.001f) // XXX magic number + if (unprojected_radius < 0.001f) { // XXX magic number unprojected_radius = 0.001f; + } BKE_brush_unprojected_radius_set(scene, brush, unprojected_radius); } @@ -229,8 +230,9 @@ static bool palette_poll(bContext *C) { Paint *paint = BKE_paint_get_active_from_context(C); - if (paint && paint->palette != NULL) + if (paint && paint->palette != NULL) { return true; + } return false; } @@ -306,8 +308,9 @@ static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op)) Brush *brush = BKE_paint_brush(paint); Object *ob = CTX_data_active_object(C); - if (!ob || !brush) + if (!ob || !brush) { return OPERATOR_CANCELLED; + } /* TODO: other modes */ if (ob->mode & OB_MODE_SCULPT) { @@ -396,8 +399,9 @@ static Brush *brush_tool_toggle(Main *bmain, Paint *paint, Brush *brush_orig, co * for one that is */ br = brush_tool_cycle(bmain, paint, brush_orig, tool); /* store the previously-selected brush */ - if (br) + if (br) { br->toggle_brush = brush_orig; + } return br; } @@ -406,8 +410,9 @@ static Brush *brush_tool_toggle(Main *bmain, Paint *paint, Brush *brush_orig, co * back to the previously selected brush. */ return brush_orig->toggle_brush; } - else + else { return NULL; + } } static int brush_generic_tool_set(Main *bmain, @@ -519,37 +524,6 @@ static void PAINT_OT_brush_select(wmOperatorType *ot) RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); } -static int brush_uv_sculpt_tool_set_exec(bContext *C, wmOperator *op) -{ - Brush *brush; - Scene *scene = CTX_data_scene(C); - ToolSettings *ts = scene->toolsettings; - ts->uv_sculpt_tool = RNA_enum_get(op->ptr, "tool"); - brush = ts->uvsculpt->paint.brush; - /* To update toolshelf */ - WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush); - - return OPERATOR_FINISHED; -} - -static void BRUSH_OT_uv_sculpt_tool_set(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "UV Sculpt Tool Set"; - ot->description = "Set the UV sculpt tool"; - ot->idname = "BRUSH_OT_uv_sculpt_tool_set"; - - /* api callbacks */ - ot->exec = brush_uv_sculpt_tool_set_exec; - ot->poll = uv_sculpt_poll; - - /* flags */ - ot->flag = 0; - - /* props */ - ot->prop = RNA_def_enum(ot->srna, "tool", rna_enum_uv_sculpt_tool_items, 0, "Tool", ""); -} - /***** Stencil Control *****/ typedef enum { @@ -578,7 +552,8 @@ typedef struct { float area_size[2]; StencilControlMode mode; StencilConstraint constrain_mode; - int mask; /* we are twaking mask or colour stencil */ + /** We are tweaking mask or color stencil. */ + int mask; Brush *br; float *dim_target; float *rot_target; @@ -628,12 +603,14 @@ static int stencil_control_invoke(bContext *C, wmOperator *op, const wmEvent *ev int mask = RNA_enum_get(op->ptr, "texmode"); if (mask) { - if (br->mask_mtex.brush_map_mode != MTEX_MAP_MODE_STENCIL) + if (br->mask_mtex.brush_map_mode != MTEX_MAP_MODE_STENCIL) { return OPERATOR_CANCELLED; + } } else { - if (br->mtex.brush_map_mode != MTEX_MAP_MODE_STENCIL) + if (br->mtex.brush_map_mode != MTEX_MAP_MODE_STENCIL) { return OPERATOR_CANCELLED; + } } scd = MEM_mallocN(sizeof(StencilControlData), "stencil_control"); @@ -695,10 +672,12 @@ static void stencil_control_calculate(StencilControlData *scd, const int mval[2] len = len_v2(mdiff); factor = len / scd->lenorig; copy_v2_v2(mdiff, scd->init_sdim); - if (scd->constrain_mode != STENCIL_CONSTRAINT_Y) + if (scd->constrain_mode != STENCIL_CONSTRAINT_Y) { mdiff[0] = factor * scd->init_sdim[0]; - if (scd->constrain_mode != STENCIL_CONSTRAINT_X) + } + if (scd->constrain_mode != STENCIL_CONSTRAINT_X) { mdiff[1] = factor * scd->init_sdim[1]; + } CLAMP(mdiff[0], 5.0f, 10000.0f); CLAMP(mdiff[1], 5.0f, 10000.0f); copy_v2_v2(scd->dim_target, mdiff); @@ -709,10 +688,12 @@ static void stencil_control_calculate(StencilControlData *scd, const int mval[2] sub_v2_v2v2(mdiff, mvalf, scd->pos_target); angle = atan2f(mdiff[1], mdiff[0]); angle = scd->init_rot + angle - scd->init_angle; - if (angle < 0.0f) + if (angle < 0.0f) { angle += (float)(2 * M_PI); - if (angle > (float)(2 * M_PI)) + } + if (angle > (float)(2 * M_PI)) { angle -= (float)(2 * M_PI); + } *scd->rot_target = angle; break; } @@ -744,20 +725,24 @@ static int stencil_control_modal(bContext *C, wmOperator *op, const wmEvent *eve case XKEY: if (event->val == KM_PRESS) { - if (scd->constrain_mode == STENCIL_CONSTRAINT_X) + if (scd->constrain_mode == STENCIL_CONSTRAINT_X) { scd->constrain_mode = 0; - else + } + else { scd->constrain_mode = STENCIL_CONSTRAINT_X; + } stencil_control_calculate(scd, event->mval); } break; case YKEY: if (event->val == KM_PRESS) { - if (scd->constrain_mode == STENCIL_CONSTRAINT_Y) + if (scd->constrain_mode == STENCIL_CONSTRAINT_Y) { scd->constrain_mode = 0; - else + } + else { scd->constrain_mode = STENCIL_CONSTRAINT_Y; + } stencil_control_calculate(scd, event->mval); } @@ -778,8 +763,9 @@ static bool stencil_control_poll(bContext *C) Paint *paint; Brush *br; - if (!paint_supports_texture(mode)) + if (!paint_supports_texture(mode)) { return false; + } paint = BKE_paint_get_active_from_context(C); br = BKE_paint_brush(paint); @@ -905,8 +891,9 @@ static int stencil_reset_transform_exec(bContext *C, wmOperator *op) Brush *br = BKE_paint_brush(paint); bool do_mask = RNA_boolean_get(op->ptr, "mask"); - if (!br) + if (!br) { return OPERATOR_CANCELLED; + } if (do_mask) { br->mask_stencil_pos[0] = 256; @@ -996,7 +983,6 @@ void ED_operatortypes_paint(void) /* note, particle uses a different system, can be added with existing operators in wm.py */ WM_operatortype_append(PAINT_OT_brush_select); - WM_operatortype_append(BRUSH_OT_uv_sculpt_tool_set); /* image */ WM_operatortype_append(PAINT_OT_texture_paint_toggle); @@ -1083,9 +1069,6 @@ void ED_keymap_paint(wmKeyConfig *keyconf) keymap = WM_keymap_ensure(keyconf, "Face Mask", 0, 0); keymap->poll = facemask_paint_poll; - keymap = WM_keymap_ensure(keyconf, "UV Sculpt", 0, 0); - keymap->poll = uv_sculpt_keymap_poll; - /* paint stroke */ keymap = paint_stroke_modal_keymap(keyconf); WM_modalkeymap_assign(keymap, "SCULPT_OT_brush_stroke"); diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 4a586f4f7df..9a46dab8c20 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -309,8 +309,9 @@ static bool paint_brush_update(bContext *C, do_random = true; } - if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) + if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) { BKE_brush_randomize_texture_coords(ups, false); + } else { copy_v2_v2(ups->tex_mouse, mouse); } @@ -325,8 +326,9 @@ static bool paint_brush_update(bContext *C, do_random_mask = true; } - if (brush->mask_mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) + if (brush->mask_mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) { BKE_brush_randomize_texture_coords(ups, true); + } else { copy_v2_v2(ups->mask_tex_mouse, mouse); } @@ -427,8 +429,9 @@ static bool paint_brush_update(bContext *C, location_success = true; *r_location_is_set = true; } - else if (!paint_tool_require_location(brush, mode)) + else if (!paint_tool_require_location(brush, mode)) { location_success = true; + } } else { zero_v3(r_location); @@ -479,8 +482,7 @@ static void paint_brush_stroke_add_step(bContext *C, if (tablet && (pressure >= 0.99f) && ((pop->s.brush->flag & BRUSH_SPACING_PRESSURE) || BKE_brush_use_alpha_pressure(scene, pop->s.brush) || - BKE_brush_use_size_pressure(scene, pop->s.brush))) - { + BKE_brush_use_size_pressure(scene, pop->s.brush))) { return; } @@ -493,8 +495,7 @@ static void paint_brush_stroke_add_step(bContext *C, if (tablet && (pressure < 0.0002f) && ((pop->s.brush->flag & BRUSH_SPACING_PRESSURE) || BKE_brush_use_alpha_pressure(scene, pop->s.brush) || - BKE_brush_use_size_pressure(scene, pop->s.brush))) - { + BKE_brush_use_size_pressure(scene, pop->s.brush))) { return; } #endif @@ -508,8 +509,9 @@ static void paint_brush_stroke_add_step(bContext *C, float delta[2]; float factor = stroke->zoom_2d; - if (brush->flag & BRUSH_JITTER_PRESSURE) + if (brush->flag & BRUSH_JITTER_PRESSURE) { factor *= pressure; + } BKE_brush_jitter_pos(scene, brush, mouse_in, mouse_out); @@ -591,8 +593,9 @@ static float paint_space_stroke_spacing(const Scene *scene, float spacing = stroke->brush->spacing; /* apply spacing pressure */ - if (stroke->brush->flag & BRUSH_SPACING_PRESSURE) + if (stroke->brush->flag & BRUSH_SPACING_PRESSURE) { spacing = spacing * (1.5f - spacing_pressure); + } /* stroke system is used for 2d paint too, so we need to account for * the fact that brush can be scaled there. */ @@ -616,8 +619,9 @@ static float paint_stroke_overlapped_curve(Brush *br, float x, float spacing) xx = fabsf(x0 + i * h); - if (xx < 1.0f) + if (xx < 1.0f) { sum += BKE_brush_curve_strength(br, xx, 1); + } } return sum; @@ -632,8 +636,9 @@ static float paint_stroke_integrate_overlap(Brush *br, float factor) float spacing = br->spacing * factor; - if (!(br->flag & BRUSH_SPACE_ATTEN && (br->spacing < 100))) + if (!(br->flag & BRUSH_SPACE_ATTEN && (br->spacing < 100))) { return 1.0; + } m = 10; g = 1.0f / m; @@ -641,14 +646,17 @@ static float paint_stroke_integrate_overlap(Brush *br, float factor) for (i = 0; i < m; i++) { float overlap = fabs(paint_stroke_overlapped_curve(br, i * g, spacing)); - if (overlap > max) + if (overlap > max) { max = overlap; + } } - if (max == 0.0f) + if (max == 0.0f) { return 1.0f; - else + } + else { return 1.0f / max; + } } static float paint_space_stroke_spacing_variable( @@ -776,8 +784,9 @@ PaintStroke *paint_stroke_new(bContext *C, /* initialize here to avoid initialization conflict with threaded strokes */ curvemapping_initialize(br->curve); - if (p->flags & PAINT_USE_CAVITY_MASK) + if (p->flags & PAINT_USE_CAVITY_MASK) { curvemapping_initialize(p->cavity_curve); + } BKE_paint_set_overlay_override(br->overlay_flags); @@ -799,18 +808,22 @@ static void stroke_done(struct bContext *C, struct wmOperator *op) ups->stroke_active = false; /* reset rotation here to avoid doing so in cursor display */ - if (!(stroke->brush->mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) + if (!(stroke->brush->mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) { ups->brush_rotation = 0.0f; + } - if (!(stroke->brush->mask_mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) + if (!(stroke->brush->mask_mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) { ups->brush_rotation_sec = 0.0f; + } if (stroke->stroke_started) { - if (stroke->redraw) + if (stroke->redraw) { stroke->redraw(C, stroke, true); + } - if (stroke->done) + if (stroke->done) { stroke->done(C, stroke); + } } if (stroke->timer) { @@ -821,8 +834,9 @@ static void stroke_done(struct bContext *C, struct wmOperator *op) BLI_rng_free(stroke->rng); } - if (stroke->stroke_cursor) + if (stroke->stroke_cursor) { WM_paint_cursor_end(CTX_wm_manager(C), stroke->stroke_cursor); + } BLI_freelistN(&stroke->line); @@ -847,13 +861,15 @@ static bool sculpt_is_grab_tool(Brush *br) /* return true if the brush size can change during paint (normally used for pressure) */ bool paint_supports_dynamic_size(Brush *br, ePaintMode mode) { - if (br->flag & BRUSH_ANCHORED) + if (br->flag & BRUSH_ANCHORED) { return false; + } switch (mode) { case PAINT_MODE_SCULPT: - if (sculpt_is_grab_tool(br)) + if (sculpt_is_grab_tool(br)) { return false; + } break; case PAINT_MODE_TEXTURE_2D: /* fall through */ @@ -878,8 +894,9 @@ bool paint_supports_smooth_stroke(Brush *br, ePaintMode mode) switch (mode) { case PAINT_MODE_SCULPT: - if (sculpt_is_grab_tool(br)) + if (sculpt_is_grab_tool(br)) { return false; + } break; default: break; @@ -897,13 +914,15 @@ bool paint_supports_texture(ePaintMode mode) /* return true if the brush size can change during paint (normally used for pressure) */ bool paint_supports_dynamic_tex_coords(Brush *br, ePaintMode mode) { - if (br->flag & BRUSH_ANCHORED) + if (br->flag & BRUSH_ANCHORED) { return false; + } switch (mode) { case PAINT_MODE_SCULPT: - if (sculpt_is_grab_tool(br)) + if (sculpt_is_grab_tool(br)) { return false; + } break; default: break; @@ -944,10 +963,12 @@ static void paint_stroke_add_sample( sample->pressure = pressure; stroke->cur_sample++; - if (stroke->cur_sample >= max_samples) + if (stroke->cur_sample >= max_samples) { stroke->cur_sample = 0; - if (stroke->num_samples < max_samples) + } + if (stroke->num_samples < max_samples) { stroke->num_samples++; + } } static void paint_stroke_sample_average(const PaintStroke *stroke, PaintSample *average) @@ -993,8 +1014,9 @@ static void paint_line_strokes_spacing(bContext *C, BLI_assert(length >= 0.0f); - if (length == 0.0f) + if (length == 0.0f) { return; + } while (length > 0.0f) { float spacing_final = spacing - *length_residue; @@ -1045,8 +1067,9 @@ static bool paint_stroke_curve_end(bContext *C, wmOperator *op, PaintStroke *str float length_residue = 0.0f; int i; - if (!pc) + if (!pc) { return true; + } #ifdef DEBUG_TIME TIMEIT_START_AVERAGED(whole_stroke); @@ -1177,22 +1200,25 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event) * this isn't perfect... even when an extra MOUSEMOVE is spoofed, the stroke discards it * since the 2D deltas are zero -- code in this file needs to be updated to use the * post-NDOF_MOTION MOUSEMOVE */ - if (event->type == NDOF_MOTION) + if (event->type == NDOF_MOTION) { return OPERATOR_PASS_THROUGH; + } #endif /* one time initialization */ if (!stroke->stroke_init) { - if (paint_stroke_curve_end(C, op, stroke)) + if (paint_stroke_curve_end(C, op, stroke)) { return OPERATOR_FINISHED; + } - if (paint_supports_smooth_stroke(br, mode)) + if (paint_supports_smooth_stroke(br, mode)) { stroke->stroke_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), SPACE_TYPE_ANY, RGN_TYPE_ANY, paint_poll, paint_draw_smooth_cursor, stroke); + } stroke->stroke_init = true; first_modal = true; @@ -1206,9 +1232,10 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event) BLI_assert((stroke->stroke_started & ~1) == 0); /* 0/1 */ if (stroke->stroke_started) { - if (br->flag & BRUSH_AIRBRUSH) + if (br->flag & BRUSH_AIRBRUSH) { stroke->timer = WM_event_add_timer( CTX_wm_manager(C), CTX_wm_window(C), TIMER, stroke->brush->rate); + } if (br->flag & BRUSH_LINE) { stroke->stroke_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), @@ -1249,10 +1276,12 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_FINISHED; } else if (br->flag & BRUSH_LINE) { - if (event->alt) + if (event->alt) { stroke->constrain_line = true; - else + } + else { stroke->constrain_line = false; + } copy_v2_fl2(mouse, event->mval[0], event->mval[1]); paint_stroke_line_constrain(stroke, mouse); @@ -1276,8 +1305,9 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event) if (paint_smooth_stroke(stroke, &sample_average, mode, mouse, &pressure)) { if (stroke->stroke_started) { if (paint_space_stroke_enabled(br, mode)) { - if (paint_space_stroke(C, op, mouse, pressure)) + if (paint_space_stroke(C, op, mouse, pressure)) { redraw = true; + } } else { float dmouse[2]; @@ -1305,11 +1335,13 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event) ARegion *ar = CTX_wm_region(C); /* At the very least, invalidate the cursor */ - if (ar && (p->flags & PAINT_SHOW_BRUSH)) + if (ar && (p->flags & PAINT_SHOW_BRUSH)) { WM_paint_cursor_tag_redraw(window, ar); + } - if (redraw && stroke->redraw) + if (redraw && stroke->redraw) { stroke->redraw(C, stroke, false); + } } return OPERATOR_RUNNING_MODAL; diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 098e38dbdb5..6d003820723 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -93,8 +93,9 @@ bool paint_convert_bb_to_rect(rcti *rect, BLI_rcti_init_minmax(rect); /* return zero if the bounding box has non-positive volume */ - if (bb_min[0] > bb_max[0] || bb_min[1] > bb_max[1] || bb_min[2] > bb_max[2]) + if (bb_min[0] > bb_max[0] || bb_min[1] > bb_max[1] || bb_min[2] > bb_max[2]) { return 0; + } ED_view3d_ob_project_mat_get(rv3d, ob, projection_mat); @@ -195,8 +196,9 @@ void paint_get_tex_pixel_col(const MTex *mtex, rgba[3] = 1.0f; } - if (convert_to_linear) + if (convert_to_linear) { IMB_colormanagement_colorspace_to_scene_linear_v3(rgba, colorspace); + } linearrgb_to_srgb_v3_v3(rgba, rgba); @@ -382,8 +384,9 @@ static int imapaint_pick_face(ViewContext *vc, unsigned int *r_index, unsigned int totpoly) { - if (totpoly == 0) + if (totpoly == 0) { return 0; + } /* sample only on the exact position */ *r_index = ED_view3d_select_id_sample(vc, mval[0], mval[1]); @@ -410,18 +413,24 @@ static Image *imapaint_face_image(Object *ob, Mesh *me, int face_index) /* Uses symm to selectively flip any axis of a coordinate. */ void flip_v3_v3(float out[3], const float in[3], const char symm) { - if (symm & PAINT_SYMM_X) + if (symm & PAINT_SYMM_X) { out[0] = -in[0]; - else + } + else { out[0] = in[0]; - if (symm & PAINT_SYMM_Y) + } + if (symm & PAINT_SYMM_Y) { out[1] = -in[1]; - else + } + else { out[1] = in[1]; - if (symm & PAINT_SYMM_Z) + } + if (symm & PAINT_SYMM_Z) { out[2] = -in[2]; - else + } + else { out[2] = in[2]; + } } void flip_qt_qt(float out[4], const float in[4], const char symm) @@ -474,7 +483,7 @@ void paint_sample_color( } if (CTX_wm_view3d(C) && texpaint_proj) { - /* first try getting a colour directly from the mesh faces if possible */ + /* first try getting a color directly from the mesh faces if possible */ ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = OBACT(view_layer); Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); @@ -501,10 +510,12 @@ void paint_sample_color( if (imapaint_pick_face(&vc, mval, &faceindex, totpoly)) { Image *image; - if (use_material) + if (use_material) { image = imapaint_face_image(ob_eval, me_eval, faceindex); - else + } + else { image = imapaint->canvas; + } if (image) { ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL); @@ -517,10 +528,12 @@ void paint_sample_color( u = fmodf(uv[0], 1.0f); v = fmodf(uv[1], 1.0f); - if (u < 0.0f) + if (u < 0.0f) { u += 1.0f; - if (v < 0.0f) + } + if (v < 0.0f) { v += 1.0f; + } u = u * ibuf->x; v = v * ibuf->y; @@ -563,8 +576,9 @@ void paint_sample_color( x + ar->winrct.xmin, y + ar->winrct.ymin, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col); glReadBuffer(GL_BACK); } - else + else { return; + } } else { glReadBuffer(GL_FRONT); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 70783ff004e..7852cd61ae1 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -312,16 +312,20 @@ static uint vpaint_blend(const VPaint *vp, for (a = 0; a < 4; a++) { if (ct[a] < co[a]) { - if (cp[a] < ct[a]) + if (cp[a] < ct[a]) { cp[a] = ct[a]; - else if (cp[a] > co[a]) + } + else if (cp[a] > co[a]) { cp[a] = co[a]; + } } else { - if (cp[a] < co[a]) + if (cp[a] < co[a]) { cp[a] = co[a]; - else if (cp[a] > ct[a]) + } + else if (cp[a] > ct[a]) { cp[a] = ct[a]; + } } } } @@ -400,12 +404,15 @@ static float wpaint_blend(const VPaint *wp, static float wpaint_clamp_monotonic(float oldval, float curval, float newval) { - if (newval < oldval) + if (newval < oldval) { return MIN2(newval, curval); - else if (newval > oldval) + } + else if (newval > oldval) { return MAX2(newval, curval); - else + } + else { return newval; + } } /* ----------------------------------------------------- */ @@ -553,7 +560,8 @@ static void do_weight_paint_normalize_all_locked_try_active(MDeformVert *dvert, if (!success) { /** - * Locks prevented the first pass from full completion, so remove restriction on active group; e.g: + * Locks prevented the first pass from full completion, + * so remove restriction on active group; e.g: * * - With 1.0 weight painted into active: * nonzero locked weight; first pass zeroed out unlocked weight; scale 1 down to fit. @@ -565,9 +573,11 @@ static void do_weight_paint_normalize_all_locked_try_active(MDeformVert *dvert, } #if 0 /* UNUSED */ -static bool has_unselected_unlocked_bone_group( - int defbase_tot, bool *defbase_sel, int selected, - const bool *lock_flags, const bool *vgroup_validmap) +static bool has_unselected_unlocked_bone_group(int defbase_tot, + bool *defbase_sel, + int selected, + const bool *lock_flags, + const bool *vgroup_validmap) { int i; if (defbase_tot == selected) { @@ -843,15 +853,15 @@ static void do_weight_paint_vertex_single( dv_mirr, wpi->defbase_tot, wpi->vgroup_validmap, wpi->lock_flags, wpi->mirror.lock); } else { - /* this case accounts for... - * - painting onto a center vertex of a mesh - * - x mirror is enabled - * - auto normalize is enabled - * - the group you are painting onto has a L / R version + /* This case accounts for: + * - Painting onto a center vertex of a mesh. + * - X-mirror is enabled. + * - Auto normalize is enabled. + * - The group you are painting onto has a L / R version. * * We want L/R vgroups to have the same weight but this cant be if both are over 0.5, - * We _could_ have special check for that, but this would need its own normalize function which - * holds 2 groups from changing at once. + * We _could_ have special check for that, but this would need its own + * normalize function which holds 2 groups from changing at once. * * So! just balance out the 2 weights, it keeps them equal and everything normalized. * @@ -1287,7 +1297,8 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op) BKE_paint_toolslots_brush_validate(bmain, &ts->wpaint->paint); } - /* When locked, it's almost impossible to select the pose then the object to enter weight paint mode. + /* When locked, it's almost impossible to select the pose + * then the object to enter weight paint mode. * In this case move our pose object in/out of pose mode. * This is in fits with the convention of selecting multiple objects and entering a mode. */ if (scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK) { @@ -1322,12 +1333,15 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op) static bool paint_poll_test(bContext *C) { Object *ob = CTX_data_active_object(C); - if (ob == NULL || ob->type != OB_MESH) + if (ob == NULL || ob->type != OB_MESH) { return 0; - if (!ob->data || ID_IS_LINKED(ob->data)) + } + if (!ob->data || ID_IS_LINKED(ob->data)) { return 0; - if (CTX_data_edit_object(C)) + } + if (CTX_data_edit_object(C)) { return 0; + } return 1; } @@ -1395,20 +1409,24 @@ static void vwpaint_update_cache_invariants( } /* Initial mouse location */ - if (mouse) + if (mouse) { copy_v2_v2(cache->initial_mouse, mouse); - else + } + else { zero_v2(cache->initial_mouse); + } mode = RNA_enum_get(op->ptr, "mode"); cache->invert = mode == BRUSH_STROKE_INVERT; cache->alt_smooth = mode == BRUSH_STROKE_SMOOTH; /* not very nice, but with current events system implementation * we can't handle brush appearance inversion hotkey separately (sergey) */ - if (cache->invert) + if (cache->invert) { ups->draw_inverted = true; - else + } + else { ups->draw_inverted = false; + } copy_v2_v2(cache->mouse, cache->initial_mouse); /* Truly temporary data that isn't stored in properties */ @@ -1665,8 +1683,9 @@ static void do_wpaint_precompute_weight_cb_ex(void *__restrict userdata, static void precompute_weight_values( bContext *C, Object *ob, Brush *brush, struct WPaintData *wpd, WeightPaintInfo *wpi, Mesh *me) { - if (wpd->precomputed_weight_ready && !brush_use_accumulate_ex(brush, ob->mode)) + if (wpd->precomputed_weight_ready && !brush_use_accumulate_ex(brush, ob->mode)) { return; + } /* threaded loop over vertices */ SculptThreadedTaskData data = { @@ -1872,8 +1891,9 @@ static void do_wpaint_brush_smear_task_cb_ex(void *__restrict userdata, const float final_alpha = brush_fade * brush_strength * grid_alpha * brush_alpha_pressure; - if (final_alpha <= 0.0f) + if (final_alpha <= 0.0f) { continue; + } do_weight_paint_vertex( data->vp, data->ob, data->wpi, v_index, final_alpha, (float)weight_final); @@ -2156,8 +2176,9 @@ static void wpaint_do_paint(bContext *C, wpaint_paint_leaves(C, ob, sd, wp, wpd, wpi, me, nodes, totnode); - if (nodes) + if (nodes) { MEM_freeN(nodes); + } } static void wpaint_do_radial_symmetry(bContext *C, @@ -2306,8 +2327,9 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P /* previous is not set in the current cache else * the partial rect will always grow */ if (ss->cache) { - if (!BLI_rcti_is_empty(&ss->cache->previous_r)) + if (!BLI_rcti_is_empty(&ss->cache->previous_r)) { BLI_rcti_union(&r, &ss->cache->previous_r); + } } r.xmin += vc->ar->winrct.xmin - 2; @@ -2326,18 +2348,24 @@ static void wpaint_stroke_done(const bContext *C, struct PaintStroke *stroke) struct WPaintData *wpd = paint_stroke_mode_data(stroke); if (wpd) { - if (wpd->defbase_sel) + if (wpd->defbase_sel) { MEM_freeN((void *)wpd->defbase_sel); - if (wpd->vgroup_validmap) + } + if (wpd->vgroup_validmap) { MEM_freeN((void *)wpd->vgroup_validmap); - if (wpd->lock_flags) + } + if (wpd->lock_flags) { MEM_freeN((void *)wpd->lock_flags); - if (wpd->active.lock) + } + if (wpd->active.lock) { MEM_freeN((void *)wpd->active.lock); - if (wpd->mirror.lock) + } + if (wpd->mirror.lock) { MEM_freeN((void *)wpd->mirror.lock); - if (wpd->precomputed_weight) + } + if (wpd->precomputed_weight) { MEM_freeN(wpd->precomputed_weight); + } MEM_freeN(wpd); } @@ -2568,12 +2596,14 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f /* context checks could be a poll() */ me = BKE_mesh_from_object(ob); - if (me == NULL || me->totpoly == 0) + if (me == NULL || me->totpoly == 0) { return false; + } ED_mesh_color_ensure(me, NULL); - if (me->mloopcol == NULL) + if (me->mloopcol == NULL) { return false; + } /* make mode data storage */ vpd = MEM_callocN(sizeof(*vpd), "VPaintData"); @@ -3278,12 +3308,15 @@ static void vpaint_stroke_done(const bContext *C, struct PaintStroke *stroke) ED_vpaint_proj_handle_free(vpd->vp_handle); } - if (vpd->mlooptag) + if (vpd->mlooptag) { MEM_freeN(vpd->mlooptag); - if (vpd->smear.color_prev) + } + if (vpd->smear.color_prev) { MEM_freeN(vpd->smear.color_prev); - if (vpd->smear.color_curr) + } + if (vpd->smear.color_curr) { MEM_freeN(vpd->smear.color_curr); + } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c index ad7cfebb8d5..fed477ace14 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c @@ -82,8 +82,9 @@ static bool vertex_color_set(Object *ob, uint paintcol) for (i = 0; i < me->totpoly; i++, mp++) { MLoopCol *lcol = me->mloopcol + mp->loopstart; - if (use_face_sel && !(mp->flag & ME_FACE_SEL)) + if (use_face_sel && !(mp->flag & ME_FACE_SEL)) { continue; + } j = 0; do { @@ -151,7 +152,7 @@ static bool vertex_paint_from_weight(Object *ob) } /* TODO: respect selection. */ - /* TODO: Do we want to take weights from evaluated mesh instead? 2.7x was not doing it anyway... */ + /* TODO: Do we want to take weights from evaluated mesh instead? 2.7x was not doing it anyway. */ mp = me->mpoly; vgroup_active = ob->actdef - 1; for (int i = 0; i < me->totpoly; i++, mp++) { @@ -220,8 +221,9 @@ static void vertex_color_smooth_looptag(Mesh *me, bool *mlooptag) /* if no mloopcol: do not do */ /* if mtexpoly: only the involved faces, otherwise all */ - if (me->mloopcol == NULL || me->totvert == 0 || me->totpoly == 0) + if (me->mloopcol == NULL || me->totvert == 0 || me->totpoly == 0) { return; + } scol = MEM_callocN(sizeof(int) * me->totvert * 5, "scol"); @@ -289,8 +291,9 @@ static bool vertex_color_smooth(Object *ob) const MLoop *ml = me->mloop + mp->loopstart; int ml_index = mp->loopstart; - if (use_face_sel && !(mp->flag & ME_FACE_SEL)) + if (use_face_sel && !(mp->flag & ME_FACE_SEL)) { continue; + } for (j = 0; j < mp->totloop; j++, ml_index++, ml++) { mlooptag[ml_index] = true; diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c index 29d150c44fe..c1c2964156f 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c @@ -130,6 +130,7 @@ static int weight_from_bones_exec(bContext *C, wmOperator *op) op->reports, depsgraph, scene, ob, armob, type, (me->editflag & ME_EDIT_MIRROR_X)); DEG_id_tag_update(&me->id, 0); + DEG_relations_tag_update(CTX_data_main(C)); WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); return OPERATOR_FINISHED; diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c index 88aed201b48..c71315872f6 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c @@ -41,6 +41,8 @@ #include "BKE_report.h" #include "BKE_object.h" +#include "DEG_depsgraph_build.h" + /* Only for blend modes. */ #include "IMB_imbuf.h" @@ -93,6 +95,7 @@ bool ED_wpaint_ensure_data(bContext *C, bDeformGroup *dg = defgroup_find_name(ob, pchan->name); if (dg == NULL) { dg = BKE_object_defgroup_add_name(ob, pchan->name); /* sets actdef */ + DEG_relations_tag_update(CTX_data_main(C)); } else { int actdef = 1 + BLI_findindex(&ob->defbase, dg); @@ -105,6 +108,7 @@ bool ED_wpaint_ensure_data(bContext *C, } if (BLI_listbase_is_empty(&ob->defbase)) { BKE_object_defgroup_add(ob); + DEG_relations_tag_update(CTX_data_main(C)); } /* ensure we don't try paint onto an invalid group */ diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 9309def4a77..9ba7561b18b 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -109,8 +109,9 @@ static bool sculpt_has_active_modifiers(Scene *scene, Object *ob) /* exception for shape keys because we can edit those */ for (; md; md = md->next) { - if (modifier_isEnabled(scene, md, eModifierMode_Realtime)) + if (modifier_isEnabled(scene, md, eModifierMode_Realtime)) { return 1; + } } return 0; @@ -394,17 +395,20 @@ static void paint_mesh_restore_co_task_cb(void *__restrict userdata, if (orig_data.unode->type == SCULPT_UNDO_COORDS) { copy_v3_v3(vd.co, orig_data.co); - if (vd.no) + if (vd.no) { copy_v3_v3_short(vd.no, orig_data.no); - else + } + else { normal_short_to_float_v3(vd.fno, orig_data.no); + } } else if (orig_data.unode->type == SCULPT_UNDO_MASK) { *vd.mask = orig_data.mask; } - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } BKE_pbvh_vertex_iter_end; @@ -422,9 +426,10 @@ static void paint_mesh_restore_co(Sculpt *sd, Object *ob) BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode); - /* Disable OpenMP when dynamic-topology is enabled. Otherwise, new entries might be inserted by - * sculpt_undo_push_node() into the GHash used internally by BM_log_original_vert_co() by a different thread. - * See T33787. */ + /** + * Disable OpenMP when dynamic-topology is enabled. Otherwise, new entries might be inserted by + * #sculpt_undo_push_node() into the GHash used internally by #BM_log_original_vert_co() + * by a different thread. See T33787. */ SculptThreadedTaskData data = { .sd = sd, .ob = ob, @@ -438,8 +443,9 @@ static void paint_mesh_restore_co(Sculpt *sd, Object *ob) totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, paint_mesh_restore_co_task_cb, &settings); - if (nodes) + if (nodes) { MEM_freeN(nodes); + } } /*** BVH Tree ***/ @@ -455,8 +461,9 @@ static void sculpt_extend_redraw_rect_previous(Object *ob, rcti *rect) SculptSession *ss = ob->sculpt; if (ss->cache) { - if (!BLI_rcti_is_empty(&ss->cache->previous_r)) + if (!BLI_rcti_is_empty(&ss->cache->previous_r)) { BLI_rcti_union(rect, &ss->cache->previous_r); + } } } @@ -466,8 +473,9 @@ bool sculpt_get_redraw_rect(ARegion *ar, RegionView3D *rv3d, Object *ob, rcti *r PBVH *pbvh = ob->sculpt->pbvh; float bb_min[3], bb_max[3]; - if (!pbvh) + if (!pbvh) { return 0; + } BKE_pbvh_redraw_BB(pbvh, bb_min, bb_max); @@ -496,8 +504,9 @@ void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *ar, Object *ob) ob->sculpt->cache->previous_r = ob->sculpt->cache->current_r; /* clear redraw flag from nodes */ - if (pbvh) + if (pbvh) { BKE_pbvh_update(pbvh, PBVH_UpdateRedraw, NULL); + } } /************************ Brush Testing *******************/ @@ -676,7 +685,10 @@ static float frontface(const Brush *br, #if 0 -static bool sculpt_brush_test_cyl(SculptBrushTest *test, float co[3], float location[3], const float area_no[3]) +static bool sculpt_brush_test_cyl(SculptBrushTest *test, + float co[3], + float location[3], + const float area_no[3]) { if (sculpt_brush_test_sphere_fast(test, co)) { float t1[3], t2[3], t3[3], dist; @@ -722,10 +734,12 @@ static float calc_overlap(StrokeCache *cache, const char symm, const char axis, /* distsq = len_squared_v3v3(mirror, cache->traced_location); */ distsq = len_squared_v3v3(mirror, cache->true_location); - if (distsq <= 4.0f * (cache->radius_squared)) + if (distsq <= 4.0f * (cache->radius_squared)) { return (2.0f * (cache->radius) - sqrtf(distsq)) / (2.0f * (cache->radius)); - else + } + else { return 0; + } } static float calc_radial_symmetry_feather(Sculpt *sd, @@ -837,10 +851,12 @@ static void calc_area_normal_and_center_task_cb(void *__restrict userdata, normal_tri_v3(no, UNPACK3(co_tri)); flip_index = (dot_v3v3(ss->cache->view_normal, no) <= 0.0f); - if (area_cos) + if (area_cos) { add_v3_v3(private_co[flip_index], co); - if (area_nos) + } + if (area_nos) { add_v3_v3(private_no[flip_index], no); + } private_count[flip_index] += 1; } } @@ -884,10 +900,12 @@ static void calc_area_normal_and_center_task_cb(void *__restrict userdata, } flip_index = (dot_v3v3(ss->cache->view_normal, no) <= 0.0f); - if (area_cos) + if (area_cos) { add_v3_v3(private_co[flip_index], co); - if (area_nos) + } + if (area_nos) { add_v3_v3(private_no[flip_index], no); + } private_count[flip_index] += 1; } } @@ -1208,8 +1226,9 @@ float tex_strength(SculptSession *ss, flip_v3_v3(symm_point, point, cache->mirror_symmetry_pass); - if (cache->radial_symmetry_pass) + if (cache->radial_symmetry_pass) { mul_m4_v3(cache->symm_rot_mat_inv, symm_point); + } ED_view3d_project_float_v2_m4(cache->vc->ar, symm_point, point_2d, cache->projection_mat); @@ -1259,18 +1278,23 @@ bool sculpt_search_sphere_cb(PBVHNode *node, void *data_v) float t[3], bb_min[3], bb_max[3]; int i; - if (data->original) + if (data->original) { BKE_pbvh_node_get_original_BB(node, bb_min, bb_max); - else + } + else { BKE_pbvh_node_get_BB(node, bb_min, bb_max); + } for (i = 0; i < 3; ++i) { - if (bb_min[i] > center[i]) + if (bb_min[i] > center[i]) { nearest[i] = bb_min[i]; - else if (bb_max[i] < center[i]) + } + else if (bb_max[i] < center[i]) { nearest[i] = bb_max[i]; - else + } + else { nearest[i] = center[i]; + } } sub_v3_v3v3(t, center, nearest); @@ -1284,10 +1308,12 @@ bool sculpt_search_circle_cb(PBVHNode *node, void *data_v) SculptSearchCircleData *data = data_v; float bb_min[3], bb_max[3]; - if (data->original) + if (data->original) { BKE_pbvh_node_get_original_BB(node, bb_min, bb_max); - else + } + else { BKE_pbvh_node_get_BB(node, bb_min, bb_min); + } float dummy_co[3], dummy_depth; const float dist_sq = dist_squared_ray_to_aabb_v3( @@ -1302,13 +1328,16 @@ static void sculpt_clip(Sculpt *sd, SculptSession *ss, float co[3], const float int i; for (i = 0; i < 3; ++i) { - if (sd->flags & (SCULPT_LOCK_X << i)) + if (sd->flags & (SCULPT_LOCK_X << i)) { continue; + } - if ((ss->cache->flag & (CLIP_X << i)) && (fabsf(co[i]) <= ss->cache->clip_tolerance[i])) + if ((ss->cache->flag & (CLIP_X << i)) && (fabsf(co[i]) <= ss->cache->clip_tolerance[i])) { co[i] = 0.0f; - else + } + else { co[i] = val[i]; + } } } @@ -1533,10 +1562,12 @@ static float neighbor_average_mask(SculptSession *ss, unsigned vert) } } - if (total > 0) + if (total > 0) { return avg / (float)total; - else + } + else { return vmask[vert]; + } } /* Same logic as neighbor_average(), but for bmesh rather than mesh */ @@ -1767,8 +1798,9 @@ static void do_smooth_brush_mesh_task_cb_ex(void *__restrict userdata, sculpt_clip(sd, ss, vd.co, val); } - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -1821,8 +1853,9 @@ static void do_smooth_brush_bmesh_task_cb_ex(void *__restrict userdata, sculpt_clip(sd, ss, vd.co, val); } - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -1877,8 +1910,9 @@ static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata, sculpt_clip(sd, ss, vd.co, val); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -1920,20 +1954,24 @@ static void do_smooth_brush_multires_task_cb_ex(void *__restrict userdata, grid_hidden = BKE_pbvh_grid_hidden(ss->pbvh); - if (smooth_mask) + if (smooth_mask) { tmpgrid_mask = (void *)(data_chunk + 1); - else + } + else { tmpgrid_co = (void *)(data_chunk + 1); + } for (i = 0; i < totgrid; i++) { int gi = grid_indices[i]; const BLI_bitmap *gh = grid_hidden[gi]; gddata = griddata[gi]; - if (smooth_mask) + if (smooth_mask) { memset(tmpgrid_mask, 0, data_chunk->tmpgrid_size); - else + } + else { memset(tmpgrid_co, 0, data_chunk->tmpgrid_size); + } for (y = 0; y < gridsize - 1; y++) { const int v = y * gridsize; @@ -1990,8 +2028,9 @@ static void do_smooth_brush_multires_task_cb_ex(void *__restrict userdata, const int index = y * gridsize + x; if (gh) { - if (BLI_BITMAP_TEST(gh, index)) + if (BLI_BITMAP_TEST(gh, index)) { continue; + } } co = CCG_elem_offset_co(&key, gddata, index); @@ -2006,11 +2045,13 @@ static void do_smooth_brush_multires_task_cb_ex(void *__restrict userdata, ss, brush, co, sqrtf(test.dist), NULL, fno, strength_mask, tls->thread_id); float f = 1.0f / 16.0f; - if (x == 0 || x == gridsize - 1) + if (x == 0 || x == gridsize - 1) { f *= 2.0f; + } - if (y == 0 || y == gridsize - 1) + if (y == 0 || y == gridsize - 1) { f *= 2.0f; + } if (smooth_mask) { *mask += ((tmpgrid_mask[index] * f) - *mask) * fade; @@ -2101,8 +2142,9 @@ static void smooth(Sculpt *sd, break; } - if (ss->multires) + if (ss->multires) { multires_stitch_grids(ob); + } } } @@ -2166,8 +2208,9 @@ static void do_mask_brush_draw_task_cb_ex(void *__restrict userdata, (*vd.mask) += fade * bstrength; CLAMP(*vd.mask, 0, 1); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } BKE_pbvh_vertex_iter_end; } @@ -2239,8 +2282,9 @@ static void do_draw_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], offset, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2330,8 +2374,9 @@ static void do_crease_brush_task_cb_ex(void *__restrict userdata, add_v3_v3v3(proxy[vd.i], val1, val2); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2354,20 +2399,24 @@ static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod mul_v3_v3(offset, ss->cache->scale); mul_v3_fl(offset, bstrength); - /* we divide out the squared alpha and multiply by the squared crease to give us the pinch strength */ + /* We divide out the squared alpha and multiply by the squared crease + * to give us the pinch strength. */ crease_correction = brush->crease_pinch_factor * brush->crease_pinch_factor; brush_alpha = BKE_brush_alpha_get(scene, brush); - if (brush_alpha > 0.0f) + if (brush_alpha > 0.0f) { crease_correction /= brush_alpha * brush_alpha; + } /* we always want crease to pinch or blob to relax even when draw is negative */ flippedbstrength = (bstrength < 0) ? -crease_correction * bstrength : crease_correction * bstrength; - if (brush->sculpt_tool == SCULPT_TOOL_BLOB) + if (brush->sculpt_tool == SCULPT_TOOL_BLOB) { flippedbstrength *= -1.0f; + } - /* Use surface normal for 'spvc', so the vertices are pinched towards a line instead of a single point. + /* Use surface normal for 'spvc', + * so the vertices are pinched towards a line instead of a single point. * Without this we get a 'flat' surface surrounding the pinch */ sculpt_project_v3_cache_init(&spvc, ss->cache->sculpt_normal_symm); @@ -2425,8 +2474,9 @@ static void do_pinch_brush_task_cb_ex(void *__restrict userdata, } mul_v3_v3fl(proxy[vd.i], val, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2487,8 +2537,9 @@ static void do_grab_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], grab_delta, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2553,8 +2604,9 @@ static void do_nudge_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], cono, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2660,8 +2712,9 @@ static void do_snake_hook_brush_task_cb_ex(void *__restrict userdata, add_v3_v3(proxy[vd.i], delta_rotate); } - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2678,8 +2731,9 @@ static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); - if (bstrength < 0) + if (bstrength < 0) { negate_v3(grab_delta); + } if (ss->cache->normal_weight > 0.0f) { sculpt_project_v3_normal_align(ss, ss->cache->normal_weight, grab_delta); @@ -2743,8 +2797,9 @@ static void do_thumb_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], cono, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2819,8 +2874,9 @@ static void do_rotate_brush_task_cb_ex(void *__restrict userdata, add_v3_v3(proxy[vd.i], ss->cache->location); sub_v3_v3(proxy[vd.i], orig_data.co); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2896,8 +2952,9 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata, *disp += fade; /* Don't let the displacement go past the limit */ - if ((lim < 0.0f && *disp < lim) || (lim >= 0.0f && *disp > lim)) + if ((lim < 0.0f && *disp < lim) || (lim >= 0.0f && *disp > lim)) { *disp = lim; + } mul_v3_v3fl(val, offset, *disp); @@ -2913,8 +2970,9 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata, sculpt_clip(sd, ss, vd.co, val); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2976,16 +3034,19 @@ static void do_inflate_brush_task_cb_ex(void *__restrict userdata, tls->thread_id); float val[3]; - if (vd.fno) + if (vd.fno) { copy_v3_v3(val, vd.fno); - else + } + else { normal_short_to_float_v3(val, vd.no); + } mul_v3_fl(val, fade * ss->cache->radius); mul_v3_v3v3(proxy[vd.i], val, ss->cache->scale); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -3048,8 +3109,9 @@ static void calc_sculpt_plane( /* for flatten center */ /* flatten center has not been calculated yet if we are not using the area normal */ - if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA) + if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA) { calc_area_center(sd, ob, nodes, totnode, r_area_co); + } /* for area normal */ copy_v3_v3(ss->cache->sculpt_normal, r_area_no); @@ -3090,8 +3152,9 @@ static int plane_trim(const StrokeCache *cache, const Brush *brush, const float static bool plane_point_side_flip(const float co[3], const float plane[4], const bool flip) { float d = plane_point_side_v3(plane, co); - if (flip) + if (flip) { d = -d; + } return d <= 0.0f; } @@ -3158,8 +3221,9 @@ static void do_flatten_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], val, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } } @@ -3251,8 +3315,9 @@ static void do_clay_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], val, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } } @@ -3347,8 +3412,9 @@ static void do_clay_strips_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], val, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } } @@ -3377,14 +3443,21 @@ static void do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int t calc_sculpt_plane(sd, ob, nodes, totnode, area_no_sp, area_co); - if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA || (brush->flag & BRUSH_ORIGINAL_NORMAL)) + if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA || (brush->flag & BRUSH_ORIGINAL_NORMAL)) { calc_area_normal(sd, ob, nodes, totnode, area_no); - else + } + else { copy_v3_v3(area_no, area_no_sp); + } /* delay the first daub because grab delta is not setup */ - if (ss->cache->first_time) + if (ss->cache->first_time) { return; + } + + if (is_zero_v3(ss->cache->grab_delta_symmetry)) { + return; + } mul_v3_v3v3(temp, area_no_sp, ss->cache->scale); mul_v3_fl(temp, displace); @@ -3467,8 +3540,9 @@ static void do_fill_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], val, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } } @@ -3558,8 +3632,9 @@ static void do_scrape_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], val, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } } @@ -3637,8 +3712,9 @@ static void do_gravity_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], offset, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -3704,8 +3780,9 @@ void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3]) if (kb == me->key->refkey) { MVert *mvert = me->mvert; - for (a = 0; a < me->totvert; a++, mvert++) + for (a = 0; a < me->totvert; a++, mvert++) { copy_v3_v3(mvert->co, vertCos[a]); + } BKE_mesh_calc_normals(me); } @@ -3819,11 +3896,13 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &task_data, do_brush_action_task_cb, &settings); - if (sculpt_brush_needs_normal(ss, brush)) + if (sculpt_brush_needs_normal(ss, brush)) { update_sculpt_normal(sd, ob, nodes, totnode); + } - if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA) + if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA) { update_brush_local_mat(sd, ob); + } /* Apply one type of brush action */ switch (brush->sculpt_tool) { @@ -3898,8 +3977,9 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe bmesh_topology_rake(sd, ob, nodes, totnode, brush->topology_rake_factor); } - if (ss->cache->supports_gravity) + if (ss->cache->supports_gravity) { do_gravity(sd, ob, nodes, totnode, sd->gravity_factor); + } MEM_freeN(nodes); @@ -3929,8 +4009,9 @@ static void sculpt_flush_pbvhvert_deform(Object *ob, PBVHVertexIter *vd) copy_v3_v3(ss->deform_cos[index], vd->co); copy_v3_v3(ss->orig_cos[index], newco); - if (!ss->kb) + if (!ss->kb) { copy_v3_v3(me->mvert[index].co, newco); + } } static void sculpt_combine_proxies_task_cb(void *__restrict userdata, @@ -3951,8 +4032,9 @@ static void sculpt_combine_proxies_task_cb(void *__restrict userdata, int proxy_count; float(*orco)[3] = NULL; - if (use_orco && !ss->bm) + if (use_orco && !ss->bm) { orco = sculpt_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COORDS)->co; + } BKE_pbvh_node_get_proxies(data->nodes[n], &proxies, &proxy_count); @@ -3973,13 +4055,15 @@ static void sculpt_combine_proxies_task_cb(void *__restrict userdata, copy_v3_v3(val, vd.co); } - for (p = 0; p < proxy_count; p++) + for (p = 0; p < proxy_count; p++) { add_v3_v3(val, proxies[p].co[vd.i]); + } sculpt_clip(sd, ss, vd.co, val); - if (ss->modifiers_active) + if (ss->modifiers_active) { sculpt_flush_pbvhvert_deform(ob, &vd); + } } BKE_pbvh_vertex_iter_end; @@ -4010,8 +4094,9 @@ static void sculpt_combine_proxies(Sculpt *sd, Object *ob) BLI_task_parallel_range(0, totnode, &data, sculpt_combine_proxies_task_cb, &settings); } - if (nodes) + if (nodes) { MEM_freeN(nodes); + } } /* copy the modified vertices from bvh to the active key */ @@ -4022,16 +4107,19 @@ static void sculpt_update_keyblock(Object *ob) /* Keyblock update happens after handling deformation caused by modifiers, * so ss->orig_cos would be updated with new stroke */ - if (ss->orig_cos) + if (ss->orig_cos) { vertCos = ss->orig_cos; - else + } + else { vertCos = BKE_pbvh_get_vertCos(ss->pbvh); + } if (vertCos) { sculpt_vertcos_to_key(ob, ss->kb, vertCos); - if (vertCos != ss->orig_cos) + if (vertCos != ss->orig_cos) { MEM_freeN(vertCos); + } } } @@ -4191,8 +4279,9 @@ static void do_tiled( start[dim] = (bbMin[dim] - orgLoc[dim] - radius) / step[dim]; end[dim] = (bbMax[dim] - orgLoc[dim] + radius) / step[dim]; } - else + else { start[dim] = end[dim] = 0; + } } /* first do the "untiled" position to initialize the stroke for this location */ @@ -4204,8 +4293,9 @@ static void do_tiled( for (cur[0] = start[0]; cur[0] <= end[0]; ++cur[0]) { for (cur[1] = start[1]; cur[1] <= end[1]; ++cur[1]) { for (cur[2] = start[2]; cur[2] <= end[2]; ++cur[2]) { - if (!cur[0] && !cur[1] && !cur[2]) + if (!cur[0] && !cur[1] && !cur[2]) { continue; /* skip tile at orgLoc, this was already handled before all others */ + } ++cache->tile_pass; @@ -4248,8 +4338,9 @@ static void sculpt_fix_noise_tear(Sculpt *sd, Object *ob) Brush *brush = BKE_paint_brush(&sd->paint); MTex *mtex = &brush->mtex; - if (ss->multires && mtex->tex && mtex->tex->type == TEX_NOISE) + if (ss->multires && mtex->tex && mtex->tex->type == TEX_NOISE) { multires_stitch_grids(ob); + } } static void do_symmetrical_brush_actions(Sculpt *sd, @@ -4268,7 +4359,8 @@ static void do_symmetrical_brush_actions(Sculpt *sd, cache->bstrength = brush_strength(sd, cache, feather, ups); cache->symmetry = symm; - /* symm is a bit combination of XYZ - 1 is mirror X; 2 is Y; 3 is XY; 4 is Z; 5 is XZ; 6 is YZ; 7 is XYZ */ + /* symm is a bit combination of XYZ - + * 1 is mirror X; 2 is Y; 3 is XY; 4 is Z; 5 is XZ; 6 is YZ; 7 is XYZ */ for (i = 0; i <= symm; ++i) { if (i == 0 || (symm & i && (symm != 5 || i != 3) && (symm != 6 || (i != 3 && i != 5)))) { cache->mirror_symmetry_pass = i; @@ -4383,8 +4475,9 @@ static const char *sculpt_tool_name(Sculpt *sd) void sculpt_cache_free(StrokeCache *cache) { - if (cache->dial) + if (cache->dial) { MEM_freeN(cache->dial); + } MEM_freeN(cache); } @@ -4456,10 +4549,12 @@ static void sculpt_update_cache_invariants( sculpt_init_mirror_clipping(ob, ss); /* Initial mouse location */ - if (mouse) + if (mouse) { copy_v2_v2(cache->initial_mouse, mouse); - else + } + else { zero_v2(cache->initial_mouse); + } mode = RNA_enum_get(op->ptr, "mode"); cache->invert = mode == BRUSH_STROKE_INVERT; @@ -4476,10 +4571,12 @@ static void sculpt_update_cache_invariants( /* not very nice, but with current events system implementation * we can't handle brush appearance inversion hotkey separately (sergey) */ - if (cache->invert) + if (cache->invert) { ups->draw_inverted = true; - else + } + else { ups->draw_inverted = false; + } /* Alt-Smooth */ if (cache->alt_smooth) { @@ -4550,8 +4647,9 @@ static void sculpt_update_cache_invariants( if (brush->sculpt_tool == SCULPT_TOOL_LAYER) { /* not supported yet for multires or dynamic topology */ if (!ss->multires && !ss->bm && !ss->layer_co && (brush->flag & BRUSH_PERSISTENT)) { - if (!ss->layer_co) + if (!ss->layer_co) { ss->layer_co = MEM_mallocN(sizeof(float) * 3 * ss->totvert, "sculpt mesh vertices copy"); + } if (ss->deform_cos) { memcpy(ss->layer_co, ss->deform_cos, ss->totvert); @@ -4585,8 +4683,9 @@ static void sculpt_update_cache_invariants( cache->first_time = 1; #define PIXEL_INPUT_THRESHHOLD 5 - if (brush->sculpt_tool == SCULPT_TOOL_ROTATE) + if (brush->sculpt_tool == SCULPT_TOOL_ROTATE) { cache->dial = BLI_dial_initialize(cache->initial_mouse, PIXEL_INPUT_THRESHHOLD); + } #undef PIXEL_INPUT_THRESHHOLD } @@ -4613,8 +4712,9 @@ static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Bru if (cache->first_time) { copy_v3_v3(cache->orig_grab_location, cache->true_location); } - else if (tool == SCULPT_TOOL_SNAKE_HOOK) + else if (tool == SCULPT_TOOL_SNAKE_HOOK) { add_v3_v3(cache->true_location, cache->grab_delta); + } /* compute 3d coordinate at same z from original location + mouse */ mul_v3_m4v3(loc, ob->obmat, cache->orig_grab_location); @@ -4660,10 +4760,12 @@ static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Bru copy_v3_v3(cache->old_grab_location, grab_location); - if (tool == SCULPT_TOOL_GRAB) + if (tool == SCULPT_TOOL_GRAB) { copy_v3_v3(cache->anchored_location, cache->true_location); - else if (tool == SCULPT_TOOL_THUMB) + } + else if (tool == SCULPT_TOOL_THUMB) { copy_v3_v3(cache->anchored_location, cache->orig_grab_location); + } if (ELEM(tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_THUMB)) { /* location stays the same for finding vertices in brush radius */ @@ -5179,8 +5281,9 @@ static bool sculpt_stroke_test_start(bContext *C, struct wmOperator *op, const f return 1; } - else + else { return 0; + } } static void sculpt_stroke_update_step(bContext *C, @@ -5249,8 +5352,9 @@ static void sculpt_brush_exit_tex(Sculpt *sd) Brush *brush = BKE_paint_brush(&sd->paint); MTex *mtex = &brush->mtex; - if (mtex->tex && mtex->tex->nodetree) + if (mtex->tex && mtex->tex->nodetree) { ntreeTexEndExecTree(mtex->tex->nodetree->execdata); + } } static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(stroke)) @@ -5291,20 +5395,23 @@ static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(str BKE_pbvh_update(ss->pbvh, PBVH_UpdateOriginalBB, NULL); - if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) + if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) { BKE_pbvh_bmesh_after_stroke(ss->pbvh); + } /* optimization: if there is locked key and active modifiers present in */ /* the stack, keyblock is updating at each step. otherwise we could update */ /* keyblock only when stroke is finished */ - if (ss->kb && !ss->modifiers_active) + if (ss->kb && !ss->modifiers_active) { sculpt_update_keyblock(ob); + } ss->partial_redraw = 0; /* try to avoid calling this, only for e.g. linked duplicates now */ - if (((Mesh *)ob->data)->id.us > 1) + if (((Mesh *)ob->data)->id.us > 1) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); } @@ -5378,8 +5485,8 @@ static void sculpt_brush_stroke_cancel(bContext *C, wmOperator *op) Sculpt *sd = CTX_data_tool_settings(C)->sculpt; const Brush *brush = BKE_paint_brush(&sd->paint); - /* XXX Canceling strokes that way does not work with dynamic topology, user will have to do real undo for now. - * See T46456. */ + /* XXX Canceling strokes that way does not work with dynamic topology, + * user will have to do real undo for now. See T46456. */ if (ss->cache && !sculpt_stroke_is_dynamic_topology(ss, brush)) { paint_mesh_restore_co(sd, ob); } @@ -5429,8 +5536,9 @@ static int sculpt_set_persistent_base_exec(bContext *C, wmOperator *UNUSED(op)) SculptSession *ss = CTX_data_active_object(C)->sculpt; if (ss) { - if (ss->layer_co) + if (ss->layer_co) { MEM_freeN(ss->layer_co); + } ss->layer_co = NULL; } @@ -5758,8 +5866,9 @@ static enum eDynTopoWarnFlag sculpt_dynamic_topology_check(Scene *scene, Object /* exception for shape keys because we can edit those */ for (; md; md = md->next) { const ModifierTypeInfo *mti = modifierType_getInfo(md->type); - if (!modifier_isEnabled(scene, md, eModifierMode_Realtime)) + if (!modifier_isEnabled(scene, md, eModifierMode_Realtime)) { continue; + } if (mti->type == eModifierTypeType_Constructive) { flag |= DYNTOPO_WARN_MODIFIER; @@ -5938,8 +6047,9 @@ void ED_object_sculptmode_enter_ex(Main *bmain, const int flush_recalc = ed_object_sculptmode_flush_recalc_flag(scene, ob, mmd); - if (flush_recalc) + if (flush_recalc) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + } /* Create sculpt mode session data */ if (ob->sculpt) { @@ -6166,8 +6276,9 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *UNUSED(op)) BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnodes); - if (!totnodes) + if (!totnodes) { return OPERATOR_CANCELLED; + } for (i = 0; i < totnodes; i++) { BKE_pbvh_node_mark_topology_update(nodes[i]); @@ -6188,8 +6299,9 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *UNUSED(op)) while (BKE_pbvh_bmesh_update_topology( ss->pbvh, PBVH_Collapse | PBVH_Subdivide, center, NULL, size, false, false)) { - for (i = 0; i < totnodes; i++) + for (i = 0; i < totnodes; i++) { BKE_pbvh_node_mark_topology_update(nodes[i]); + } } MEM_freeN(nodes); diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h index 97f2ca1a143..be4ab5809e4 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.h +++ b/source/blender/editors/sculpt_paint/sculpt_intern.h @@ -147,8 +147,10 @@ typedef struct SculptThreadedTaskData { void *custom_data; /* Data specific to some callbacks. */ - /* Note: even if only one or two of those are used at a time, keeping them separated, names help figuring out - * what it is, and memory overhead is ridiculous anyway... */ + + /* Note: even if only one or two of those are used at a time, + * keeping them separated, names help figuring out + * what it is, and memory overhead is ridiculous anyway. */ float flippedbstrength; float angle; float strength; diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index 0b995860feb..c66c1d91a77 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -81,8 +81,9 @@ static UndoSculpt *sculpt_undo_get_nodes(void); static void update_cb(PBVHNode *node, void *rebuild) { BKE_pbvh_node_mark_update(node); - if (*((bool *)rebuild)) + if (*((bool *)rebuild)) { BKE_pbvh_node_mark_rebuild_draw(node); + } BKE_pbvh_node_fully_hidden_set(node, 0); } @@ -314,8 +315,9 @@ static bool sculpt_undo_restore_mask(bContext *C, SculptUndoNode *unode) for (j = 0; j < unode->totgrid; j++) { grid = grids[unode->grids[j]]; - for (i = 0; i < gridsize * gridsize; i++, mask++) + for (i = 0; i < gridsize * gridsize; i++, mask++) { SWAP(float, *CCG_elem_offset_mask(&key, grid, i), *mask); + } } } @@ -357,8 +359,9 @@ static void sculpt_undo_bmesh_restore_generic(bContext *C, BLI_task_parallel_range( 0, totnode, nodes, sculpt_undo_bmesh_restore_generic_task_cb, &settings); - if (nodes) + if (nodes) { MEM_freeN(nodes); + } } else { sculpt_pbvh_clear(ob); @@ -483,18 +486,21 @@ static void sculpt_undo_restore_list(bContext *C, ListBase *lb) BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, false, need_mask); - if (lb->first && sculpt_undo_bmesh_restore(C, lb->first, ob, ss)) + if (lb->first && sculpt_undo_bmesh_restore(C, lb->first, ob, ss)) { return; + } for (unode = lb->first; unode; unode = unode->next) { - if (!STREQ(unode->idname, ob->id.name)) + if (!STREQ(unode->idname, ob->id.name)) { continue; + } /* check if undo data matches current data well enough to * continue */ if (unode->maxvert) { - if (ss->totvert != unode->maxvert) + if (ss->totvert != unode->maxvert) { continue; + } } else if (unode->maxgrid && subdiv_ccg != NULL) { if ((subdiv_ccg->num_grids != unode->maxgrid) || @@ -508,16 +514,19 @@ static void sculpt_undo_restore_list(bContext *C, ListBase *lb) switch (unode->type) { case SCULPT_UNDO_COORDS: - if (sculpt_undo_restore_coords(C, unode)) + if (sculpt_undo_restore_coords(C, unode)) { update = true; + } break; case SCULPT_UNDO_HIDDEN: - if (sculpt_undo_restore_hidden(C, unode)) + if (sculpt_undo_restore_hidden(C, unode)) { rebuild = true; + } break; case SCULPT_UNDO_MASK: - if (sculpt_undo_restore_mask(C, unode)) + if (sculpt_undo_restore_mask(C, unode)) { update = true; + } break; case SCULPT_UNDO_DYNTOPO_BEGIN: @@ -548,10 +557,12 @@ static void sculpt_undo_restore_list(bContext *C, ListBase *lb) NULL); if (BKE_sculpt_multires_active(scene, ob)) { - if (rebuild) + if (rebuild) { multires_mark_as_modified(ob, MULTIRES_HIDDEN_MODIFIED); - else + } + else { multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED); + } } tag_update |= ((Mesh *)ob->data)->id.us > 1; @@ -578,40 +589,52 @@ static void sculpt_undo_free_list(ListBase *lb) SculptUndoNode *unode = lb->first; while (unode != NULL) { SculptUndoNode *unode_next = unode->next; - if (unode->co) + if (unode->co) { MEM_freeN(unode->co); - if (unode->no) + } + if (unode->no) { MEM_freeN(unode->no); - if (unode->index) + } + if (unode->index) { MEM_freeN(unode->index); - if (unode->grids) + } + if (unode->grids) { MEM_freeN(unode->grids); - if (unode->orig_co) + } + if (unode->orig_co) { MEM_freeN(unode->orig_co); - if (unode->vert_hidden) + } + if (unode->vert_hidden) { MEM_freeN(unode->vert_hidden); + } if (unode->grid_hidden) { for (int i = 0; i < unode->totgrid; i++) { - if (unode->grid_hidden[i]) + if (unode->grid_hidden[i]) { MEM_freeN(unode->grid_hidden[i]); + } } MEM_freeN(unode->grid_hidden); } - if (unode->mask) + if (unode->mask) { MEM_freeN(unode->mask); + } if (unode->bm_entry) { BM_log_entry_drop(unode->bm_entry); } - if (unode->bm_enter_totvert) + if (unode->bm_enter_totvert) { CustomData_free(&unode->bm_enter_vdata, unode->bm_enter_totvert); - if (unode->bm_enter_totedge) + } + if (unode->bm_enter_totedge) { CustomData_free(&unode->bm_enter_edata, unode->bm_enter_totedge); - if (unode->bm_enter_totloop) + } + if (unode->bm_enter_totloop) { CustomData_free(&unode->bm_enter_ldata, unode->bm_enter_totloop); - if (unode->bm_enter_totpoly) + } + if (unode->bm_enter_totpoly) { CustomData_free(&unode->bm_enter_pdata, unode->bm_enter_totpoly); + } MEM_freeN(unode); @@ -665,10 +688,12 @@ static void sculpt_undo_alloc_and_store_hidden(PBVH *pbvh, SculptUndoNode *unode unode->grid_hidden = MEM_mapallocN(sizeof(*unode->grid_hidden) * totgrid, "unode->grid_hidden"); for (i = 0; i < totgrid; i++) { - if (grid_hidden[grid_indices[i]]) + if (grid_hidden[grid_indices[i]]) { unode->grid_hidden[i] = MEM_dupallocN(grid_hidden[grid_indices[i]]); - else + } + else { unode->grid_hidden[i] = NULL; + } } } @@ -690,8 +715,9 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt unode->totvert = totvert; } - else + else { maxgrid = 0; + } /* we will use this while sculpting, is mapalloc slow to access then? */ @@ -704,10 +730,12 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt usculpt->undo_size = (sizeof(float[3]) + sizeof(short[3]) + sizeof(int)) * allvert; break; case SCULPT_UNDO_HIDDEN: - if (maxgrid) + if (maxgrid) { sculpt_undo_alloc_and_store_hidden(ss->pbvh, unode); - else + } + else { unode->vert_hidden = BLI_BITMAP_NEW(allvert, "SculptUndoNode.vert_hidden"); + } break; case SCULPT_UNDO_MASK: @@ -738,8 +766,9 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt unode->index = MEM_mapallocN(sizeof(int) * allvert, "SculptUndoNode.index"); } - if (ss->modifiers_active) + if (ss->modifiers_active) { unode->orig_co = MEM_callocN(allvert * sizeof(*unode->orig_co), "undoSculpt orig_cos"); + } return unode; } @@ -752,13 +781,16 @@ static void sculpt_undo_store_coords(Object *ob, SculptUndoNode *unode) BKE_pbvh_vertex_iter_begin(ss->pbvh, unode->node, vd, PBVH_ITER_ALL) { copy_v3_v3(unode->co[vd.i], vd.co); - if (vd.no) + if (vd.no) { copy_v3_v3_short(unode->no[vd.i], vd.no); - else + } + else { normal_float_to_short_v3(unode->no[vd.i], vd.fno); + } - if (ss->modifiers_active) + if (ss->modifiers_active) { copy_v3_v3(unode->orig_co[vd.i], ss->orig_cos[unode->index[vd.i]]); + } } BKE_pbvh_vertex_iter_end; } @@ -944,10 +976,12 @@ SculptUndoNode *sculpt_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType } /* store active shape key */ - if (ss->kb) + if (ss->kb) { BLI_strncpy(unode->shapeName, ss->kb->name, sizeof(ss->kb->name)); - else + } + else { unode->shapeName[0] = '\0'; + } BLI_thread_unlock(LOCK_CUSTOM1); @@ -973,8 +1007,9 @@ void sculpt_undo_push_end(void) unode->no = NULL; } - if (unode->node) + if (unode->node) { BKE_pbvh_node_layer_disp_free(unode->node); + } } /* We could remove this and enforce all callers run in an operator using 'OPTYPE_UNDO'. */ diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c index 39ada703b9b..3356edd6b36 100644 --- a/source/blender/editors/sculpt_paint/sculpt_uv.c +++ b/source/blender/editors/sculpt_paint/sculpt_uv.c @@ -139,120 +139,6 @@ typedef struct UvSculptData { char invert; } UvSculptData; -static Brush *uv_sculpt_brush(bContext *C) -{ - Scene *scene = CTX_data_scene(C); - ToolSettings *settings = scene->toolsettings; - - if (!settings->uvsculpt) - return NULL; - return BKE_paint_brush(&settings->uvsculpt->paint); -} - -static bool uv_sculpt_brush_poll_do(bContext *C, const bool check_region) -{ - BMEditMesh *em; - int ret; - Object *obedit = CTX_data_edit_object(C); - SpaceImage *sima = CTX_wm_space_image(C); - Scene *scene = CTX_data_scene(C); - ToolSettings *toolsettings = scene->toolsettings; - - if (!uv_sculpt_brush(C) || !obedit || obedit->type != OB_MESH || !sima || - ED_space_image_show_render(sima) || (sima->mode == SI_MODE_PAINT)) { - return 0; - } - - em = BKE_editmesh_from_object(obedit); - ret = EDBM_uv_check(em); - - if (ret) { - ARegion *ar = CTX_wm_region(C); - if ((!toolsettings->use_uv_sculpt) || - (check_region && ar && (ar->regiontype != RGN_TYPE_WINDOW))) { - ret = 0; - } - } - - return ret; -} - -static bool uv_sculpt_brush_poll(bContext *C) -{ - return uv_sculpt_brush_poll_do(C, true); -} - -static void brush_drawcursor_uvsculpt(bContext *C, int x, int y, void *UNUSED(customdata)) -{ -#define PX_SIZE_FADE_MAX 12.0f -#define PX_SIZE_FADE_MIN 4.0f - - Scene *scene = CTX_data_scene(C); - //Brush *brush = image_paint_brush(C); - Paint *paint = BKE_paint_get_active_from_context(C); - Brush *brush = BKE_paint_brush(paint); - - if (paint && brush && paint->flags & PAINT_SHOW_BRUSH) { - const float size = (float)BKE_brush_size_get(scene, brush); - float alpha = 0.5f; - - /* fade out the brush (cheap trick to work around brush interfering with sampling [#])*/ - if (size < PX_SIZE_FADE_MIN) { - return; - } - else if (size < PX_SIZE_FADE_MAX) { - alpha *= (size - PX_SIZE_FADE_MIN) / (PX_SIZE_FADE_MAX - PX_SIZE_FADE_MIN); - } - - uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - immUniformColor3fvAlpha(brush->add_col, alpha); - - GPU_line_smooth(true); - GPU_blend(true); - imm_draw_circle_wire_2d(pos, (float)x, (float)y, size, 40); - GPU_blend(false); - GPU_line_smooth(false); - - immUnbindProgram(); - } -#undef PX_SIZE_FADE_MAX -#undef PX_SIZE_FADE_MIN -} - -void ED_space_image_uv_sculpt_update(Main *bmain, wmWindowManager *wm, Scene *scene) -{ - ToolSettings *settings = scene->toolsettings; - if (settings->use_uv_sculpt) { - if (settings->uvsculpt == NULL) { - settings->uv_sculpt_tool = UV_SCULPT_TOOL_GRAB; - settings->uv_sculpt_settings = UV_SCULPT_LOCK_BORDERS | UV_SCULPT_ALL_ISLANDS; - settings->uv_relax_method = UV_SCULPT_TOOL_RELAX_LAPLACIAN; - } - BKE_paint_ensure(settings, (Paint **)&settings->uvsculpt); - BKE_paint_init(bmain, scene, PAINT_MODE_SCULPT_UV, PAINT_CURSOR_SCULPT); - - settings->uvsculpt->paint.paint_cursor = WM_paint_cursor_activate( - wm, SPACE_IMAGE, RGN_TYPE_WINDOW, uv_sculpt_brush_poll, brush_drawcursor_uvsculpt, NULL); - } - else { - if (settings->uvsculpt) { - WM_paint_cursor_end(wm, settings->uvsculpt->paint.paint_cursor); - settings->uvsculpt->paint.paint_cursor = NULL; - } - } -} - -bool uv_sculpt_poll(bContext *C) -{ - return uv_sculpt_brush_poll_do(C, true); -} - -bool uv_sculpt_keymap_poll(bContext *C) -{ - return uv_sculpt_brush_poll_do(C, false); -} - /*********** Improved Laplacian Relaxation Operator ************************/ /* original code by Raul Fernandez Hernandez "farsthary" * * adapted to uv smoothing by Antony Riakiatakis * @@ -306,8 +192,9 @@ static void HC_relaxation_iteration_uv(BMEditMesh *em, for (i = 0; i < sculptdata->totalUniqueUvs; i++) { float dist; - /* This is supposed to happen only if "Pin Edges" is on, since we have initialization on stroke start - * If ever uv brushes get their own mode we should check for toolsettings option too */ + /* This is supposed to happen only if "Pin Edges" is on, + * since we have initialization on stroke start. + * If ever uv brushes get their own mode we should check for toolsettings option too. */ if ((sculptdata->uv[i].flag & MARK_BOUNDARY)) { continue; } @@ -334,8 +221,9 @@ static void HC_relaxation_iteration_uv(BMEditMesh *em, MLoopUV *luv; BMLoop *l; - if (element->separate && element != sculptdata->uv[i].element) + if (element->separate && element != sculptdata->uv[i].element) { break; + } l = element->l; luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); @@ -375,8 +263,8 @@ static void laplacian_relaxation_iteration_uv(BMEditMesh *em, add_v2_v2(tmp_uvdata[tmpedge->uv1].sum_co, sculptdata->uv[tmpedge->uv2].uv); } - /* Original Lacplacian algorithm included removal of normal component of translation. here it is not - * needed since we translate along the UV plane always.*/ + /* Original Lacplacian algorithm included removal of normal component of translation. + * here it is not needed since we translate along the UV plane always. */ for (i = 0; i < sculptdata->totalUniqueUvs; i++) { copy_v2_v2(tmp_uvdata[i].p, tmp_uvdata[i].sum_co); mul_v2_fl(tmp_uvdata[i].p, 1.f / tmp_uvdata[i].ncounter); @@ -384,8 +272,9 @@ static void laplacian_relaxation_iteration_uv(BMEditMesh *em, for (i = 0; i < sculptdata->totalUniqueUvs; i++) { float dist; - /* This is supposed to happen only if "Pin Edges" is on, since we have initialization on stroke start - * If ever uv brushes get their own mode we should check for toolsettings option too */ + /* This is supposed to happen only if "Pin Edges" is on, + * since we have initialization on stroke start. + * If ever uv brushes get their own mode we should check for toolsettings option too. */ if ((sculptdata->uv[i].flag & MARK_BOUNDARY)) { continue; } @@ -406,8 +295,9 @@ static void laplacian_relaxation_iteration_uv(BMEditMesh *em, MLoopUV *luv; BMLoop *l; - if (element->separate && element != sculptdata->uv[i].element) + if (element->separate && element != sculptdata->uv[i].element) { break; + } l = element->l; luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); @@ -463,8 +353,9 @@ static void uv_sculpt_stroke_apply(bContext *C, alpha *= invert; for (i = 0; i < sculptdata->totalUniqueUvs; i++) { float dist, diff[2]; - /* This is supposed to happen only if "Lock Borders" is on, since we have initialization on stroke start - * If ever uv brushes get their own mode we should check for toolsettings option too */ + /* This is supposed to happen only if "Lock Borders" is on, + * since we have initialization on stroke start. + * If ever uv brushes get their own mode we should check for toolsettings option too. */ if (sculptdata->uv[i].flag & MARK_BOUNDARY) { continue; } @@ -484,8 +375,9 @@ static void uv_sculpt_stroke_apply(bContext *C, MLoopUV *luv; BMLoop *l; - if (element->separate && element != sculptdata->uv[i].element) + if (element->separate && element != sculptdata->uv[i].element) { break; + } l = element->l; luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); @@ -529,8 +421,9 @@ static void uv_sculpt_stroke_apply(bContext *C, MLoopUV *luv; BMLoop *l; - if (element->separate && element != sculptdata->uv[uvindex].element) + if (element->separate && element != sculptdata->uv[uvindex].element) { break; + } l = element->l; luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); @@ -623,8 +516,9 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm int island_index = 0; /* Holds, for each UvElement in elementMap, a pointer to its unique uv.*/ int *uniqueUv; - data->tool = (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_SMOOTH) ? UV_SCULPT_TOOL_RELAX : - ts->uv_sculpt_tool; + data->tool = (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_SMOOTH) ? + UV_SCULPT_TOOL_RELAX : + ts->uvsculpt->paint.brush->uv_sculpt_tool; data->invert = (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_INVERT) ? 1 : 0; data->uvsculpt = &ts->uvsculpt->paint; @@ -705,8 +599,9 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm if (element->separate) { if (do_island_optimization && (element->island != island_index)) { /* skip this uv if not on the active island */ - for (; element->next && !(element->next->separate); element = element->next) + for (; element->next && !(element->next->separate); element = element->next) { ; + } continue; } @@ -734,8 +629,9 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm char *flag; /* Skip edge if not found(unlikely) or not on valid island */ - if (itmp1 == -1 || itmp2 == -1) + if (itmp1 == -1 || itmp2 == -1) { continue; + } offset1 = uniqueUv[itmp1]; offset2 = uniqueUv[itmp2]; @@ -902,8 +798,9 @@ static int uv_sculpt_stroke_modal(bContext *C, wmOperator *op, const wmEvent *ev uv_sculpt_stroke_apply(C, op, event, obedit); break; case TIMER: - if (event->customdata == data->timer) + if (event->customdata == data->timer) { uv_sculpt_stroke_apply(C, op, event, obedit); + } break; default: return OPERATOR_RUNNING_MODAL; @@ -940,7 +837,7 @@ void SCULPT_OT_uv_sculpt_stroke(wmOperatorType *ot) /* api callbacks */ ot->invoke = uv_sculpt_stroke_invoke; ot->modal = uv_sculpt_stroke_modal; - ot->poll = uv_sculpt_poll; + ot->poll = ED_operator_uvedit_space_image; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/sound/sound_ops.c b/source/blender/editors/sound/sound_ops.c index 31dfe0bd30a..25c05e2d1d0 100644 --- a/source/blender/editors/sound/sound_ops.c +++ b/source/blender/editors/sound/sound_ops.c @@ -94,12 +94,14 @@ static int sound_open_exec(bContext *C, wmOperator *op) RNA_string_get(op->ptr, "filepath", path); sound = BKE_sound_new_file(bmain, path); - if (!op->customdata) + if (!op->customdata) { sound_open_init(C, op); + } if (sound->playback_handle == NULL) { - if (op->customdata) + if (op->customdata) { MEM_freeN(op->customdata); + } BKE_id_free(bmain, sound); BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); return OPERATOR_CANCELLED; @@ -109,8 +111,9 @@ static int sound_open_exec(bContext *C, wmOperator *op) if (info.specs.channels == AUD_CHANNELS_INVALID) { BKE_id_free(bmain, sound); - if (op->customdata) + if (op->customdata) { MEM_freeN(op->customdata); + } BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); return OPERATOR_CANCELLED; } @@ -141,7 +144,7 @@ static int sound_open_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -#else //WITH_AUDASPACE +#else // WITH_AUDASPACE static int sound_open_exec(bContext *UNUSED(C), wmOperator *op) { @@ -154,8 +157,9 @@ static int sound_open_exec(bContext *UNUSED(C), wmOperator *op) static int sound_open_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - if (RNA_struct_property_is_set(op->ptr, "filepath")) + if (RNA_struct_property_is_set(op->ptr, "filepath")) { return sound_open_exec(C, op); + } sound_open_init(C, op); @@ -227,22 +231,28 @@ static int sound_update_animation_flags_cb(Sequence *seq, void *user_data) bool driven; fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "volume", 0, &driven); - if (fcu || driven) + if (fcu || driven) { seq->flag |= SEQ_AUDIO_VOLUME_ANIMATED; - else + } + else { seq->flag &= ~SEQ_AUDIO_VOLUME_ANIMATED; + } fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "pitch", 0, &driven); - if (fcu || driven) + if (fcu || driven) { seq->flag |= SEQ_AUDIO_PITCH_ANIMATED; - else + } + else { seq->flag &= ~SEQ_AUDIO_PITCH_ANIMATED; + } fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "pan", 0, &driven); - if (fcu || driven) + if (fcu || driven) { seq->flag |= SEQ_AUDIO_PAN_ANIMATED; - else + } + else { seq->flag &= ~SEQ_AUDIO_PAN_ANIMATED; + } if (seq->type == SEQ_TYPE_SCENE) { /* TODO(sergey): For now we do manual recursion into the scene strips, @@ -271,10 +281,12 @@ static void sound_update_animation_flags(Scene *scene) SEQ_END; fcu = id_data_find_fcurve(&scene->id, scene, &RNA_Scene, "audio_volume", 0, &driven); - if (fcu || driven) + if (fcu || driven) { scene->audio.flag |= AUDIO_VOLUME_ANIMATED; - else + } + else { scene->audio.flag &= ~AUDIO_VOLUME_ANIMATED; + } } static int sound_update_animation_flags_exec(bContext *C, wmOperator *UNUSED(op)) @@ -376,7 +388,7 @@ static int sound_mixdown_exec(bContext *C, wmOperator *op) BLI_strncpy(filename, path, sizeof(filename)); BLI_path_abs(filename, BKE_main_blendfile_path(bmain)); - if (split) + if (split) { result = AUD_mixdown_per_channel(scene->sound_scene, SFRA * specs.rate / FPS, (EFRA - SFRA + 1) * specs.rate / FPS, @@ -386,7 +398,8 @@ static int sound_mixdown_exec(bContext *C, wmOperator *op) container, codec, bitrate); - else + } + else { result = AUD_mixdown(scene->sound_scene, SFRA * specs.rate / FPS, (EFRA - SFRA + 1) * specs.rate / FPS, @@ -396,6 +409,7 @@ static int sound_mixdown_exec(bContext *C, wmOperator *op) container, codec, bitrate); + } BKE_sound_reset_scene_specs(scene); @@ -468,13 +482,16 @@ static bool sound_mixdown_check(bContext *UNUSED(C), wmOperator *op) prop = RNA_struct_find_property(op->ptr, "filepath"); RNA_property_string_get(op->ptr, prop, filepath); - if (BLI_path_extension_check_array(filepath, snd_ext_sound)) + if (BLI_path_extension_check_array(filepath, snd_ext_sound)) { check = BLI_path_extension_replace(filepath, FILE_MAX, extension); - else + } + else { check = BLI_path_extension_ensure(filepath, FILE_MAX, extension); + } - if (!check) + if (!check) { return check; + } RNA_property_string_set(op->ptr, prop, filepath); return true; @@ -487,8 +504,9 @@ static bool sound_mixdown_check(bContext *UNUSED(C), wmOperator *op) static int sound_mixdown_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - if (RNA_struct_property_is_set(op->ptr, "filepath")) + if (RNA_struct_property_is_set(op->ptr, "filepath")) { return sound_mixdown_exec(C, op); + } return WM_operator_filesel(C, op, event); } @@ -738,8 +756,9 @@ static bool sound_poll(bContext *C) { Editing *ed = CTX_data_scene(C)->ed; - if (!ed || !ed->act_seq || ed->act_seq->type != SEQ_TYPE_SOUND_RAM) + if (!ed || !ed->act_seq || ed->act_seq->type != SEQ_TYPE_SOUND_RAM) { return 0; + } return 1; } @@ -751,13 +770,15 @@ static int sound_pack_exec(bContext *C, wmOperator *op) Editing *ed = CTX_data_scene(C)->ed; bSound *sound; - if (!ed || !ed->act_seq || ed->act_seq->type != SEQ_TYPE_SOUND_RAM) + if (!ed || !ed->act_seq || ed->act_seq->type != SEQ_TYPE_SOUND_RAM) { return OPERATOR_CANCELLED; + } sound = ed->act_seq->sound; - if (!sound || sound->packedfile) + if (!sound || sound->packedfile) { return OPERATOR_CANCELLED; + } sound->packedfile = newPackedFile(op->reports, sound->name, ID_BLEND_PATH(bmain, &sound->id)); BKE_sound_load(bmain, sound); @@ -795,13 +816,15 @@ static int sound_unpack_exec(bContext *C, wmOperator *op) sound = BLI_findstring(&bmain->sounds, sndname, offsetof(ID, name) + 2); } - if (!sound || !sound->packedfile) + if (!sound || !sound->packedfile) { return OPERATOR_CANCELLED; + } - if (G.fileflags & G_FILE_AUTOPACK) + if (G.fileflags & G_FILE_AUTOPACK) { BKE_report(op->reports, RPT_WARNING, "AutoPack is enabled, so image will be packed again on file save"); + } unpackSound(bmain, op->reports, sound, method); @@ -813,21 +836,25 @@ static int sound_unpack_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE Editing *ed = CTX_data_scene(C)->ed; bSound *sound; - if (RNA_struct_property_is_set(op->ptr, "id")) + if (RNA_struct_property_is_set(op->ptr, "id")) { return sound_unpack_exec(C, op); + } - if (!ed || !ed->act_seq || ed->act_seq->type != SEQ_TYPE_SOUND_RAM) + if (!ed || !ed->act_seq || ed->act_seq->type != SEQ_TYPE_SOUND_RAM) { return OPERATOR_CANCELLED; + } sound = ed->act_seq->sound; - if (!sound || !sound->packedfile) + if (!sound || !sound->packedfile) { return OPERATOR_CANCELLED; + } - if (G.fileflags & G_FILE_AUTOPACK) + if (G.fileflags & G_FILE_AUTOPACK) { BKE_report(op->reports, RPT_WARNING, "AutoPack is enabled, so image will be packed again on file save"); + } unpack_menu(C, "SOUND_OT_unpack", sound->id.name + 2, sound->name, "sounds", sound->packedfile); diff --git a/source/blender/editors/space_action/CMakeLists.txt b/source/blender/editors/space_action/CMakeLists.txt index 5251ebb1267..6c43f8b9549 100644 --- a/source/blender/editors/space_action/CMakeLists.txt +++ b/source/blender/editors/space_action/CMakeLists.txt @@ -24,8 +24,8 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_action/action_buttons.c b/source/blender/editors/space_action/action_buttons.c index a30d5f34ed0..c9c20adcab4 100644 --- a/source/blender/editors/space_action/action_buttons.c +++ b/source/blender/editors/space_action/action_buttons.c @@ -92,27 +92,3 @@ void action_buttons_register(ARegionType *UNUSED(art)) BLI_addtail(&art->paneltypes, pt); #endif } - -static int action_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = action_has_buttons_region(sa); - - if (ar) - ED_region_toggle_hidden(C, ar); - - return OPERATOR_FINISHED; -} - -void ACTION_OT_properties(wmOperatorType *ot) -{ - ot->name = "Toggle Sidebar"; - ot->idname = "ACTION_OT_properties"; - ot->description = "Toggle the properties region visibility"; - - ot->exec = action_properties_toggle_exec; - ot->poll = ED_operator_action_active; - - /* flags */ - ot->flag = 0; -} diff --git a/source/blender/editors/space_action/action_data.c b/source/blender/editors/space_action/action_data.c index e9670a0048d..db504272d2f 100644 --- a/source/blender/editors/space_action/action_data.c +++ b/source/blender/editors/space_action/action_data.c @@ -127,10 +127,12 @@ static bAction *action_create_new(bContext *C, bAction *oldact) if (sa->spacetype == SPACE_ACTION) { SpaceAction *saction = (SpaceAction *)sa->spacedata.first; - if (saction->mode == SACTCONT_SHAPEKEY) + if (saction->mode == SACTCONT_SHAPEKEY) { action->idroot = ID_KE; - else + } + else { action->idroot = ID_OB; + } } return action; @@ -170,7 +172,8 @@ static bool action_new_poll(bContext *C) Scene *scene = CTX_data_scene(C); /* Check tweakmode is off (as you don't want to be tampering with the action in that case) */ - /* NOTE: unlike for pushdown, this operator needs to be run when creating an action from nothing... */ + /* NOTE: unlike for pushdown, + * this operator needs to be run when creating an action from nothing... */ if (ED_operator_action_active(C)) { SpaceAction *saction = (SpaceAction *)CTX_wm_space_data(C); Object *ob = CTX_data_active_object(C); @@ -179,15 +182,17 @@ static bool action_new_poll(bContext *C) if (saction->mode == SACTCONT_ACTION) { /* XXX: This assumes that actions are assigned to the active object in this mode */ if (ob) { - if ((ob->adt == NULL) || (ob->adt->flag & ADT_NLA_EDIT_ON) == 0) + if ((ob->adt == NULL) || (ob->adt->flag & ADT_NLA_EDIT_ON) == 0) { return true; + } } } else if (saction->mode == SACTCONT_SHAPEKEY) { Key *key = BKE_key_from_object(ob); if (key) { - if ((key->adt == NULL) || (key->adt->flag & ADT_NLA_EDIT_ON) == 0) + if ((key->adt == NULL) || (key->adt->flag & ADT_NLA_EDIT_ON) == 0) { return true; + } } } } @@ -242,7 +247,10 @@ static int action_new_exec(bContext *C, wmOperator *UNUSED(op)) } } else { - //printf("WARNING: Failed to stash %s. It may already exist in the NLA stack though\n", oldact->id.name); +#if 0 + printf("WARNING: Failed to stash %s. It may already exist in the NLA stack though\n", + oldact->id.name); +#endif } } @@ -296,8 +304,9 @@ static bool action_pushdown_poll(bContext *C) /* NOTE: We check this for the AnimData block in question and not the global flag, * as the global flag may be left dirty by some of the browsing ops here. */ - if (!(adt->flag & ADT_NLA_EDIT_ON)) + if (!(adt->flag & ADT_NLA_EDIT_ON)) { return true; + } } } @@ -425,10 +434,12 @@ static bool action_stash_create_poll(bContext *C) AnimData *adt = ED_actedit_animdata_from_context(C); /* Check tweakmode is off (as you don't want to be tampering with the action in that case) */ - /* NOTE: unlike for pushdown, this operator needs to be run when creating an action from nothing... */ + /* NOTE: unlike for pushdown, + * this operator needs to be run when creating an action from nothing... */ if (adt) { - if (!(adt->flag & ADT_NLA_EDIT_ON)) + if (!(adt->flag & ADT_NLA_EDIT_ON)) { return true; + } } else { /* There may not be any action/animdata yet, so, just fallback to the global setting @@ -472,7 +483,8 @@ static int action_stash_create_exec(bContext *C, wmOperator *op) if (BKE_nla_action_stash(adt)) { bAction *new_action = NULL; - /* create new action not based on the old one (since the "new" operator already does that) */ + /* Create new action not based on the old one + * (since the "new" operator already does that). */ new_action = action_create_new(C, NULL); /* The stash operation will remove the user already, @@ -622,8 +634,9 @@ static bool action_unlink_poll(bContext *C) AnimData *adt = ED_actedit_animdata_from_context(C); /* Only when there's an active action, in the right modes... */ - if (saction->action && adt) + if (saction->action && adt) { return true; + } } /* something failed... */ @@ -644,7 +657,8 @@ static int action_unlink_exec(bContext *C, wmOperator *op) static int action_unlink_invoke(bContext *C, wmOperator *op, const wmEvent *evt) { - /* NOTE: this is hardcoded to match the behavior for the unlink button (in interface_templates.c) */ + /* NOTE: this is hardcoded to match the behavior for the unlink button + * (in interface_templates.c). */ RNA_boolean_set(op->ptr, "force_delete", evt->shift != 0); return action_unlink_exec(C, op); } diff --git a/source/blender/editors/space_action/action_draw.c b/source/blender/editors/space_action/action_draw.c index b2baace1592..9827967f947 100644 --- a/source/blender/editors/space_action/action_draw.c +++ b/source/blender/editors/space_action/action_draw.c @@ -210,8 +210,9 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar) /* determine if any need to draw channel */ if (ale->datatype != ALE_NONE) { /* determine if channel is selected */ - if (acf->has_setting(ac, ale, ACHANNEL_SETTING_SELECT)) + if (acf->has_setting(ac, ale, ACHANNEL_SETTING_SELECT)) { sel = ANIM_channel_setting_get(ac, ale, ACHANNEL_SETTING_SELECT); + } if (ELEM(ac->datatype, ANIMCONT_ACTION, ANIMCONT_DOPESHEET, ANIMCONT_SHAPEKEY)) { switch (ale->type) { @@ -271,9 +272,9 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar) } else if (ac->datatype == ANIMCONT_GPENCIL) { unsigned char *color; + unsigned char gpl_col[4]; if ((show_group_colors) && (ale->type == ANIMTYPE_GPLAYER)) { bGPDlayer *gpl = (bGPDlayer *)ale->data; - unsigned char gpl_col[4]; rgb_float_to_uchar(gpl_col, gpl->color); gpl_col[3] = col1[3]; @@ -407,8 +408,9 @@ void timeline_draw_cache(SpaceAction *saction, Object *ob, Scene *scene) const float cache_draw_height = (4.0f * UI_DPI_FAC * U.pixelsize); float yoffs = 0.f; - if (!(saction->cache_display & TIME_CACHE_DISPLAY) || (!ob)) + if (!(saction->cache_display & TIME_CACHE_DISPLAY) || (!ob)) { return; + } BKE_ptcache_ids_from_object(&pidlist, ob, scene, 0); @@ -421,34 +423,41 @@ void timeline_draw_cache(SpaceAction *saction, Object *ob, Scene *scene) switch (pid->type) { case PTCACHE_TYPE_SOFTBODY: - if (!(saction->cache_display & TIME_CACHE_SOFTBODY)) + if (!(saction->cache_display & TIME_CACHE_SOFTBODY)) { continue; + } break; case PTCACHE_TYPE_PARTICLES: - if (!(saction->cache_display & TIME_CACHE_PARTICLES)) + if (!(saction->cache_display & TIME_CACHE_PARTICLES)) { continue; + } break; case PTCACHE_TYPE_CLOTH: - if (!(saction->cache_display & TIME_CACHE_CLOTH)) + if (!(saction->cache_display & TIME_CACHE_CLOTH)) { continue; + } break; case PTCACHE_TYPE_SMOKE_DOMAIN: case PTCACHE_TYPE_SMOKE_HIGHRES: - if (!(saction->cache_display & TIME_CACHE_SMOKE)) + if (!(saction->cache_display & TIME_CACHE_SMOKE)) { continue; + } break; case PTCACHE_TYPE_DYNAMICPAINT: - if (!(saction->cache_display & TIME_CACHE_DYNAMICPAINT)) + if (!(saction->cache_display & TIME_CACHE_DYNAMICPAINT)) { continue; + } break; case PTCACHE_TYPE_RIGIDBODY: - if (!(saction->cache_display & TIME_CACHE_RIGIDBODY)) + if (!(saction->cache_display & TIME_CACHE_RIGIDBODY)) { continue; + } break; } - if (pid->cache->cached_frames == NULL) + if (pid->cache->cached_frames == NULL) { continue; + } GPU_matrix_push(); GPU_matrix_translate_2f(0.0, (float)V2D_SCROLL_HEIGHT_TEXT + yoffs); diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c index 9ce709e1134..8df773e98d6 100644 --- a/source/blender/editors/space_action/action_edit.c +++ b/source/blender/editors/space_action/action_edit.c @@ -86,18 +86,22 @@ static bool act_markers_make_local_poll(bContext *C) SpaceAction *sact = CTX_wm_space_action(C); /* 1) */ - if (sact == NULL) + if (sact == NULL) { return 0; + } /* 2) */ - if (ELEM(sact->mode, SACTCONT_ACTION, SACTCONT_SHAPEKEY) == 0) + if (ELEM(sact->mode, SACTCONT_ACTION, SACTCONT_SHAPEKEY) == 0) { return 0; - if (sact->action == NULL) + } + if (sact->action == NULL) { return 0; + } /* 3) */ - if (sact->flag & SACTION_POSEMARKERS_SHOW) + if (sact->flag & SACTION_POSEMARKERS_SHOW) { return 0; + } /* 4) */ return ED_markers_get_first_selected(ED_context_get_markers(C)) != NULL; @@ -113,8 +117,9 @@ static int act_markers_make_local_exec(bContext *C, wmOperator *UNUSED(op)) TimeMarker *marker, *markern = NULL; /* sanity checks */ - if (ELEM(NULL, markers, act)) + if (ELEM(NULL, markers, act)) { return OPERATOR_CANCELLED; + } /* migrate markers */ for (marker = markers->first; marker; marker = markern) { @@ -127,7 +132,8 @@ static int act_markers_make_local_exec(bContext *C, wmOperator *UNUSED(op)) } } - /* now enable the "show posemarkers only" setting, so that we can see that something did happen */ + /* Now enable the "show posemarkers only" setting, + * so that we can see that something did happen */ sact->flag |= SACTION_POSEMARKERS_SHOW; /* notifiers - both sets, as this change affects both */ @@ -219,7 +225,8 @@ static bool get_keyframe_extents(bAnimContext *ac, float *min, float *max, const tmax = BKE_nla_tweakedit_remap(adt, tmax, NLATIME_CONVERT_MAP); } - /* try to set cur using these values, if they're more extreme than previously set values */ + /* Try to set cur using these values, + * if they're more extreme than previously set values. */ *min = min_ff(*min, tmin); *max = max_ff(*max, tmax); found = true; @@ -259,12 +266,15 @@ static int actkeys_previewrange_exec(bContext *C, wmOperator *UNUSED(op)) float min, max; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; - if (ac.scene == NULL) + } + if (ac.scene == NULL) { return OPERATOR_CANCELLED; - else + } + else { scene = ac.scene; + } /* set the range directly */ get_keyframe_extents(&ac, &min, &max, false); @@ -363,15 +373,17 @@ static int actkeys_viewall(bContext *C, const bool only_sel) bool found; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } v2d = &ac.ar->v2d; /* set the horizontal range, with an extra offset so that the extreme keys will be in view */ found = get_keyframe_extents(&ac, &min, &max, only_sel); - if (only_sel && (found == false)) + if (only_sel && (found == false)) { return OPERATOR_CANCELLED; + } if (fabsf(max - min) < 1.0f) { /* Exception - center the single keyfrme */ @@ -392,7 +404,8 @@ static int actkeys_viewall(bContext *C, const bool only_sel) /* set vertical range */ if (only_sel == false) { - /* view all -> the summary channel is usually the shows everything, and resides right at the top... */ + /* view all -> the summary channel is usually the shows everything, + * and resides right at the top... */ v2d->cur.ymax = 0.0f; v2d->cur.ymin = (float)-BLI_rcti_size_y(&v2d->mask); } @@ -556,8 +569,9 @@ static int actkeys_copy_exec(bContext *C, wmOperator *op) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* copy keyframes */ if (ac.datatype == ANIMCONT_GPENCIL) { @@ -605,8 +619,9 @@ static int actkeys_paste_exec(bContext *C, wmOperator *op) const bool flipped = RNA_boolean_get(op->ptr, "flipped"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* ac.reports by default will be the global reports list, which won't show warnings */ ac.reports = op->reports; @@ -680,7 +695,8 @@ void ACTION_OT_paste(wmOperatorType *ot) static const EnumPropertyItem prop_actkeys_insertkey_types[] = { {1, "ALL", 0, "All Channels", ""}, {2, "SEL", 0, "Only Selected Channels", ""}, - {3, "GROUP", 0, "In Active Group", ""}, /* XXX not in all cases */ + /* XXX not in all cases. */ + {3, "GROUP", 0, "In Active Group", ""}, {0, NULL, 0, NULL, NULL}, }; @@ -718,11 +734,14 @@ static void insert_action_keys(bAnimContext *ac, short mode) FCurve *fcu = (FCurve *)ale->key_data; float cfra = (float)CFRA; - /* read value from property the F-Curve represents, or from the curve only? - * - ale->id != NULL: Typically, this means that we have enough info to try resolving the path - * - ale->owner != NULL: If this is set, then the path may not be resolvable from the ID alone, - * so it's easier for now to just read the F-Curve directly. - * (TODO: add the full-blown PointerRNA relative parsing case here...) + /* Read value from property the F-Curve represents, or from the curve only? + * - ale->id != NULL: + * Typically, this means that we have enough info to try resolving the path. + * + * - ale->owner != NULL: + * If this is set, then the path may not be resolvable from the ID alone, + * so it's easier for now to just read the F-Curve directly. + * (TODO: add the full-blown PointerRNA relative parsing case here...) */ if (ale->id && !ale->owner) { insert_keyframe(ac->bmain, @@ -742,8 +761,9 @@ static void insert_action_keys(bAnimContext *ac, short mode) AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* adjust current frame for NLA-scaling */ - if (adt) + if (adt) { cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP); + } const float curval = evaluate_fcurve(fcu, cfra); insert_vert_fcurve(fcu, cfra, curval, ts->keyframe_type, 0); @@ -772,16 +792,19 @@ static void insert_gpencil_keys(bAnimContext *ac, short mode) /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS); - if (mode == 2) + if (mode == 2) { filter |= ANIMFILTER_SEL; + } ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* add a copy or a blank frame? */ - if (ts->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST) + if (ts->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST) { add_frame_mode = GP_GETFRAME_ADD_COPY; /* XXX: actframe may not be what we want? */ - else + } + else { add_frame_mode = GP_GETFRAME_ADD_NEW; + } /* insert gp frames */ for (ale = anim_data.first; ale; ale = ale->next) { @@ -801,8 +824,9 @@ static int actkeys_insertkey_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } if (ac.datatype == ANIMCONT_MASK) { BKE_report(op->reports, RPT_ERROR, "Insert Keyframes is not yet implemented for this mode"); @@ -866,14 +890,18 @@ static void duplicate_action_keys(bAnimContext *ac) /* loop through filtered data and delete selected keys */ for (ale = anim_data.first; ale; ale = ale->next) { - if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) + if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) { duplicate_fcurve_keys((FCurve *)ale->key_data); - else if (ale->type == ANIMTYPE_GPLAYER) + } + else if (ale->type == ANIMTYPE_GPLAYER) { ED_gplayer_frames_duplicate((bGPDlayer *)ale->data); - else if (ale->type == ANIMTYPE_MASKLAYER) + } + else if (ale->type == ANIMTYPE_MASKLAYER) { ED_masklayer_frames_duplicate((MaskLayer *)ale->data); - else + } + else { BLI_assert(0); + } ale->update |= ANIM_UPDATE_DEFAULT; } @@ -889,8 +917,9 @@ static int actkeys_duplicate_exec(bContext *C, wmOperator *UNUSED(op)) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* duplicate keyframes */ duplicate_action_keys(&ac); @@ -980,12 +1009,14 @@ static int actkeys_delete_exec(bContext *C, wmOperator *UNUSED(op)) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* delete keyframes */ - if (!delete_action_keys(&ac)) + if (!delete_action_keys(&ac)) { return OPERATOR_CANCELLED; + } /* set notifier that keyframes have changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, NULL); @@ -1042,8 +1073,9 @@ static int actkeys_clean_exec(bContext *C, wmOperator *op) bool clean_chan; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } if (ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) { BKE_report(op->reports, RPT_ERROR, "Not implemented"); @@ -1071,7 +1103,7 @@ void ACTION_OT_clean(wmOperatorType *ot) ot->description = "Simplify F-Curves by removing closely spaced keyframes"; /* api callbacks */ - //ot->invoke = // XXX we need that number popup for this! + // ot->invoke = // XXX we need that number popup for this! ot->exec = actkeys_clean_exec; ot->poll = ED_operator_action_active; @@ -1116,8 +1148,9 @@ static int actkeys_sample_exec(bContext *C, wmOperator *op) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } if (ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) { BKE_report(op->reports, RPT_ERROR, "Not implemented"); @@ -1221,8 +1254,9 @@ static void setexpo_action_keys(bAnimContext *ac, short mode) for (fcm = fcu->modifiers.first; fcm; fcm = fcn) { fcn = fcm->next; - if (fcm->type == FMODIFIER_TYPE_CYCLES) + if (fcm->type == FMODIFIER_TYPE_CYCLES) { remove_fmodifier(&fcu->modifiers, fcm); + } } } } @@ -1242,8 +1276,9 @@ static int actkeys_expo_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } if (ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) { BKE_report(op->reports, RPT_ERROR, "Not implemented"); @@ -1296,8 +1331,9 @@ static void setipo_action_keys(bAnimContext *ac, short mode) ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - /* loop through setting BezTriple interpolation - * Note: we do not supply KeyframeEditData to the looper yet. Currently that's not necessary here... + /* Loop through setting BezTriple interpolation + * Note: we do not supply KeyframeEditData to the looper yet. + * Currently that's not necessary here. */ for (ale = anim_data.first; ale; ale = ale->next) { ANIM_fcurve_keyframes_loop(NULL, ale->key_data, NULL, set_cb, calchandles_fcurve); @@ -1317,8 +1353,9 @@ static int actkeys_ipo_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } if (ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) { BKE_report(op->reports, RPT_ERROR, "Not implemented"); @@ -1375,8 +1412,9 @@ static void sethandles_action_keys(bAnimContext *ac, short mode) ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - /* loop through setting flags for handles - * Note: we do not supply KeyframeEditData to the looper yet. Currently that's not necessary here... + /* Loop through setting flags for handles + * Note: we do not supply KeyframeEditData to the looper yet. + * Currently that's not necessary here. */ for (ale = anim_data.first; ale; ale = ale->next) { FCurve *fcu = (FCurve *)ale->key_data; @@ -1402,8 +1440,9 @@ static int actkeys_handletype_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } if (ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) { BKE_report(op->reports, RPT_ERROR, "Not implemented"); @@ -1456,8 +1495,9 @@ static void setkeytype_action_keys(bAnimContext *ac, short mode) ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - /* loop through setting BezTriple interpolation - * Note: we do not supply KeyframeEditData to the looper yet. Currently that's not necessary here... + /* Loop through setting BezTriple interpolation + * Note: we do not supply KeyframeEditData to the looper yet. + * Currently that's not necessary here. */ for (ale = anim_data.first; ale; ale = ale->next) { ANIM_fcurve_keyframes_loop(NULL, ale->key_data, NULL, set_cb, NULL); @@ -1501,8 +1541,9 @@ static int actkeys_keytype_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } if (ac.datatype == ANIMCONT_MASK) { BKE_report(op->reports, RPT_ERROR, "Not implemented for Masks"); @@ -1553,8 +1594,9 @@ void ACTION_OT_keyframe_type(wmOperatorType *ot) static bool actkeys_framejump_poll(bContext *C) { /* prevent changes during render */ - if (G.is_rendering) + if (G.is_rendering) { return 0; + } return ED_operator_action_active(C); } @@ -1569,8 +1611,9 @@ static int actkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op)) KeyframeEditData ked = {{NULL}}; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* init edit data */ /* loop over action data, averaging values */ @@ -1585,8 +1628,9 @@ static int actkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op)) ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_calc_average, NULL); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } - else + else { ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_calc_average, NULL); + } } ANIM_animdata_freelist(&anim_data); @@ -1710,8 +1754,9 @@ static int actkeys_snap_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get snapping mode */ mode = RNA_enum_get(op->ptr, "type"); @@ -1786,10 +1831,12 @@ static void mirror_action_keys(bAnimContext *ac, short mode) if (mode == ACTKEYS_MIRROR_MARKER) { TimeMarker *marker = ED_markers_get_first_selected(ac->markers); - if (marker) + if (marker) { ked.f1 = (float)marker->frame; - else + } + else { return; + } } /* filter data */ @@ -1837,8 +1884,9 @@ static int actkeys_mirror_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get mirroring mode */ mode = RNA_enum_get(op->ptr, "type"); diff --git a/source/blender/editors/space_action/action_intern.h b/source/blender/editors/space_action/action_intern.h index 5d86cf6faec..eaca7968a34 100644 --- a/source/blender/editors/space_action/action_intern.h +++ b/source/blender/editors/space_action/action_intern.h @@ -40,10 +40,7 @@ struct wmOperatorType; /* **************************************** */ /* space_action.c / action_buttons.c */ -struct ARegion *action_has_buttons_region(struct ScrArea *sa); - void action_buttons_register(struct ARegionType *art); -void ACTION_OT_properties(struct wmOperatorType *ot); /* ***************************************** */ /* action_draw.c */ diff --git a/source/blender/editors/space_action/action_ops.c b/source/blender/editors/space_action/action_ops.c index d5ddf974284..cba86ac5131 100644 --- a/source/blender/editors/space_action/action_ops.c +++ b/source/blender/editors/space_action/action_ops.c @@ -43,9 +43,6 @@ void action_operatortypes(void) { - /* view */ - WM_operatortype_append(ACTION_OT_properties); - /* keyframes */ /* selection */ WM_operatortype_append(ACTION_OT_clickselect); @@ -105,7 +102,7 @@ void ED_operatormacros_action(void) WM_operatortype_macro_define(ot, "ACTION_OT_duplicate"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_transform"); RNA_enum_set(otmacro->ptr, "mode", TFM_TIME_DUPLICATE); - RNA_enum_set(otmacro->ptr, "proportional", PROP_EDIT_OFF); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); } /* ************************** registration - keymaps **********************************/ @@ -118,8 +115,10 @@ void action_keymap(wmKeyConfig *keyconf) WM_keymap_ensure(keyconf, "Dopesheet Generic", SPACE_ACTION, 0); /* channels */ - /* Channels are not directly handled by the Action Editor module, but are inherited from the Animation module. - * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these + /* Channels are not directly handled by the Action Editor module, + * but are inherited from the Animation module. + * All the relevant operations, keymaps, drawing, etc. + * can therefore all be found in that module instead, as these * are all used for the Graph-Editor too. */ diff --git a/source/blender/editors/space_action/action_select.c b/source/blender/editors/space_action/action_select.c index 7499458181e..1614e1c432d 100644 --- a/source/blender/editors/space_action/action_select.c +++ b/source/blender/editors/space_action/action_select.c @@ -155,8 +155,9 @@ static int actkeys_deselectall_exec(bContext *C, wmOperator *op) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* 'standard' behavior - check if selected, then apply relevant selection */ const int action = RNA_enum_get(op->ptr, "action"); @@ -203,11 +204,13 @@ void ACTION_OT_select_all(wmOperatorType *ot) } /* ******************** Box Select Operator **************************** */ -/* This operator currently works in one of three ways: - * -> BKEY - 1) all keyframes within region are selected (ACTKEYS_BORDERSEL_ALLKEYS) - * -> ALT-BKEY - depending on which axis of the region was larger... - * -> 2) x-axis, so select all frames within frame range (ACTKEYS_BORDERSEL_FRAMERANGE) - * -> 3) y-axis, so select all frames within channels that region included (ACTKEYS_BORDERSEL_CHANNELS) +/** + * This operator currently works in one of three ways: + * - BKEY - 1) all keyframes within region are selected #ACTKEYS_BORDERSEL_ALLKEYS. + * - ALT-BKEY - depending on which axis of the region was larger... + * - 2) x-axis, so select all frames within frame range #ACTKEYS_BORDERSEL_FRAMERANGE. + * - 3) y-axis, so select all frames within channels that region included + * #ACTKEYS_BORDERSEL_CHANNELS. */ /* defines for box_select mode */ @@ -229,7 +232,8 @@ static void box_select_action(bAnimContext *ac, const rcti rect, short mode, sho rctf rectf; float ymin = 0, ymax = (float)(-ACHANNEL_HEIGHT_HALF(ac)); - /* convert mouse coordinates to frame ranges and channel coordinates corrected for view pan/zoom */ + /* Convert mouse coordinates to frame ranges and channel + * coordinates corrected for view pan/zoom. */ UI_view2d_region_to_view(v2d, rect.xmin, rect.ymin + 2, &rectf.xmin, &rectf.ymin); UI_view2d_region_to_view(v2d, rect.xmax, rect.ymax - 2, &rectf.xmax, &rectf.ymax); @@ -240,10 +244,12 @@ static void box_select_action(bAnimContext *ac, const rcti rect, short mode, sho /* get beztriple editing/validation funcs */ select_cb = ANIM_editkeyframes_select(selectmode); - if (ELEM(mode, ACTKEYS_BORDERSEL_FRAMERANGE, ACTKEYS_BORDERSEL_ALLKEYS)) + if (ELEM(mode, ACTKEYS_BORDERSEL_FRAMERANGE, ACTKEYS_BORDERSEL_ALLKEYS)) { ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE); - else + } + else { ok_cb = NULL; + } /* init editing data */ memset(&ked, 0, sizeof(KeyframeEditData)); @@ -275,8 +281,7 @@ static void box_select_action(bAnimContext *ac, const rcti rect, short mode, sho /* loop over data selecting */ switch (ale->type) { #if 0 /* XXX: Keyframes are not currently shown here */ - case ANIMTYPE_GPDATABLOCK: - { + case ANIMTYPE_GPDATABLOCK: { bGPdata *gpd = ale->data; bGPDlayer *gpl; for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { @@ -343,18 +348,23 @@ static int actkeys_box_select_exec(bContext *C, wmOperator *op) /* selection 'mode' depends on whether box_select region only matters on one axis */ if (RNA_boolean_get(op->ptr, "axis_range")) { - /* mode depends on which axis of the range is larger to determine which axis to use - * - checking this in region-space is fine, as it's fundamentally still going to be a different rect size - * - the frame-range select option is favored over the channel one (x over y), as frame-range one is often - * used for tweaking timing when "blocking", while channels is not that useful... + /* Mode depends on which axis of the range is larger to determine which axis to use: + * - checking this in region-space is fine, + * as it's fundamentally still going to be a different rect size. + * - the frame-range select option is favored over the channel one (x over y), + * as frame-range one is often used for tweaking timing when "blocking", + * while channels is not that useful... */ - if (BLI_rcti_size_x(&rect) >= BLI_rcti_size_y(&rect)) + if (BLI_rcti_size_x(&rect) >= BLI_rcti_size_y(&rect)) { mode = ACTKEYS_BORDERSEL_FRAMERANGE; - else + } + else { mode = ACTKEYS_BORDERSEL_CHANNELS; + } } - else + else { mode = ACTKEYS_BORDERSEL_ALLKEYS; + } /* apply box_select action */ box_select_action(&ac, rect, mode, selectmode); @@ -410,7 +420,8 @@ static void region_select_action_keys( rctf rectf, scaled_rectf; float ymin = 0, ymax = (float)(-ACHANNEL_HEIGHT_HALF(ac)); - /* convert mouse coordinates to frame ranges and channel coordinates corrected for view pan/zoom */ + /* Convert mouse coordinates to frame ranges and channel + * coordinates corrected for view pan/zoom. */ UI_view2d_region_to_view_rctf(v2d, rectf_view, &rectf); /* filter data */ @@ -478,8 +489,7 @@ static void region_select_action_keys( /* loop over data selecting */ switch (ale->type) { #if 0 /* XXX: Keyframes are not currently shown here */ - case ANIMTYPE_GPDATABLOCK: - { + case ANIMTYPE_GPDATABLOCK: { bGPdata *gpd = ale->data; bGPDlayer *gpl; for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { @@ -531,13 +541,15 @@ static int actkeys_lassoselect_exec(bContext *C, wmOperator *op) rctf rect_fl; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } data_lasso.rectf_view = &rect_fl; data_lasso.mcords = WM_gesture_lasso_path_to_array(C, op, &data_lasso.mcords_tot); - if (data_lasso.mcords == NULL) + if (data_lasso.mcords == NULL) { return OPERATOR_CANCELLED; + } const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); const int selectmode = (sel_op != SEL_OP_SUB) ? SELECT_ADD : SELECT_SUBTRACT; @@ -596,8 +608,9 @@ static int action_circle_select_exec(bContext *C, wmOperator *op) float radius = RNA_int_get(op->ptr, "radius"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } const eSelectOp sel_op = ED_select_op_modal(RNA_enum_get(op->ptr, "mode"), WM_gesture_is_modal_first(op->customdata)); @@ -743,15 +756,17 @@ static void columnselect_action_keys(bAnimContext *ac, short mode) filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - for (ale = anim_data.first; ale; ale = ale->next) + for (ale = anim_data.first; ale; ale = ale->next) { ED_gplayer_make_cfra_list(ale->data, &ked.list, 1); + } } else { filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY*/); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - for (ale = anim_data.first; ale; ale = ale->next) + for (ale = anim_data.first; ale; ale = ale->next) { ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_to_cfraelem, NULL); + } } ANIM_animdata_freelist(&anim_data); break; @@ -779,10 +794,12 @@ static void columnselect_action_keys(bAnimContext *ac, short mode) /* loop through all of the keys and select additional keyframes * based on the keys found to be selected above */ - if (ELEM(ac->datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) + if (ELEM(ac->datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) { filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE); - else + } + else { filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY*/); + } ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); for (ale = anim_data.first; ale; ale = ale->next) { @@ -793,10 +810,12 @@ static void columnselect_action_keys(bAnimContext *ac, short mode) */ for (ce = ked.list.first; ce; ce = ce->next) { /* set frame for validation callback to refer to */ - if (adt) + if (adt) { ked.f1 = BKE_nla_tweakedit_remap(adt, ce->cfra, NLATIME_CONVERT_UNMAP); - else + } + else { ked.f1 = ce->cfra; + } /* select elements with frame number matching cfraelem */ if (ale->type == ANIMTYPE_GPLAYER) { @@ -827,16 +846,19 @@ static int actkeys_columnselect_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* action to take depends on the mode */ mode = RNA_enum_get(op->ptr, "mode"); - if (mode == ACTKEYS_COLUMNSEL_MARKERS_BETWEEN) + if (mode == ACTKEYS_COLUMNSEL_MARKERS_BETWEEN) { markers_selectkeys_between(&ac); - else + } + else { columnselect_action_keys(&ac, mode); + } /* set notifier that keyframe selection have changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); @@ -876,8 +898,9 @@ static int actkeys_select_linked_exec(bContext *C, wmOperator *UNUSED(op)) KeyframeEditFunc sel_cb = ANIM_editkeyframes_select(SELECT_ADD); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* loop through all of the keys and select additional keyframes based on these */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY*/ | @@ -942,8 +965,9 @@ static void select_moreless_action_keys(bAnimContext *ac, short mode) FCurve *fcu = (FCurve *)ale->key_data; /* only continue if F-Curve has keyframes */ - if (fcu->bezt == NULL) + if (fcu->bezt == NULL) { continue; + } /* build up map of whether F-Curve's keyframes should be selected or not */ ked.data = MEM_callocN(fcu->totvert, "selmap actEdit more"); @@ -968,8 +992,9 @@ static int actkeys_select_more_exec(bContext *C, wmOperator *UNUSED(op)) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* perform select changes */ select_moreless_action_keys(&ac, SELMAP_MORE); @@ -1002,8 +1027,9 @@ static int actkeys_select_less_exec(bContext *C, wmOperator *UNUSED(op)) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* perform select changes */ select_moreless_action_keys(&ac, SELMAP_LESS); @@ -1140,18 +1166,22 @@ static int actkeys_select_leftright_exec(bContext *C, wmOperator *op) short selectmode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* select mode is either replace (deselect all, then add) or add/extend */ - if (RNA_boolean_get(op->ptr, "extend")) + if (RNA_boolean_get(op->ptr, "extend")) { selectmode = SELECT_INVERT; - else + } + else { selectmode = SELECT_REPLACE; + } /* if "test" mode is set, we don't have any info to set this with */ - if (leftright == ACTKEYS_LRSEL_TEST) + if (leftright == ACTKEYS_LRSEL_TEST) { return OPERATOR_CANCELLED; + } /* do the selecting now */ actkeys_select_leftright(&ac, leftright, selectmode); @@ -1169,8 +1199,9 @@ static int actkeys_select_leftright_invoke(bContext *C, wmOperator *op, const wm short leftright = RNA_enum_get(op->ptr, "mode"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* handle mode-based testing */ if (leftright == ACTKEYS_LRSEL_TEST) { @@ -1181,10 +1212,12 @@ static int actkeys_select_leftright_invoke(bContext *C, wmOperator *op, const wm /* determine which side of the current frame mouse is on */ x = UI_view2d_region_to_view_x(v2d, event->mval[0]); - if (x < CFRA) + if (x < CFRA) { RNA_enum_set(op->ptr, "mode", ACTKEYS_LRSEL_LEFT); - else + } + else { RNA_enum_set(op->ptr, "mode", ACTKEYS_LRSEL_RIGHT); + } } /* perform selection */ @@ -1316,10 +1349,12 @@ static void actkeys_mselect_column(bAnimContext *ac, short select_mode, float se AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* set frame for validation callback to refer to */ - if (adt) + if (adt) { ked.f1 = BKE_nla_tweakedit_remap(adt, selx, NLATIME_CONVERT_UNMAP); - else + } + else { ked.f1 = selx; + } /* select elements with frame number matching cfra */ if (ale->type == ANIMTYPE_GPLAYER) { @@ -1388,8 +1423,12 @@ static void actkeys_mselect_channel_only(bAnimContext *ac, bAnimListElem *ale, s /* ------------------- */ -static void mouse_action_keys( - bAnimContext *ac, const int mval[2], short select_mode, bool column, bool same_channel) +static void mouse_action_keys(bAnimContext *ac, + const int mval[2], + short select_mode, + const bool deselect_all, + const bool column, + const bool same_channel) { ListBase anim_data = {NULL, NULL}; DLRBT_Tree anim_keys; @@ -1407,16 +1446,17 @@ static void mouse_action_keys( rctf rectf; /* get dopesheet info */ - if (ELEM(ac->datatype, ANIMCONT_DOPESHEET, ANIMCONT_TIMELINE)) + if (ELEM(ac->datatype, ANIMCONT_DOPESHEET, ANIMCONT_TIMELINE)) { ads = ac->data; + } /* use View2D to determine the index of the channel (i.e a row in the list) where keyframe was */ UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y); UI_view2d_listview_view_to_cell( v2d, 0, ACHANNEL_STEP(ac), 0, (float)ACHANNEL_HEIGHT_HALF(ac), x, y, NULL, &channel_index); - /* x-range to check is +/- 7px for standard keyframe under standard dpi/y-scale (in screen/region-space), - * on either side of mouse click (size of keyframe icon) + /* x-range to check is +/- 7px for standard keyframe under standard dpi/y-scale + * (in screen/region-space), on either side of mouse click (size of keyframe icon). */ /* standard channel height (to allow for some slop) */ @@ -1433,14 +1473,7 @@ static void mouse_action_keys( /* try to get channel */ ale = BLI_findlink(&anim_data, channel_index); - if (ale == NULL) { - /* channel not found */ - printf("Error: animation channel (index = %d) not found in mouse_action_keys()\n", - channel_index); - ANIM_animdata_freelist(&anim_data); - return; - } - else { + if (ale != NULL) { /* found match - must return here... */ AnimData *adt = ANIM_nla_mapping_get(ac, ale); ActKeyColumn *ak, *akn = NULL; @@ -1505,25 +1538,30 @@ static void mouse_action_keys( found = true; break; } - else if (ak->cfra < rectf.xmin) + else if (ak->cfra < rectf.xmin) { akn = ak->right; - else + } + else { akn = ak->left; + } } - /* remove active channel from list of channels for separate treatment (since it's needed later on) */ + /* Remove active channel from list of channels for separate treatment + * (since it's needed later on). */ BLI_remlink(&anim_data, ale); ale->next = ale->prev = NULL; /* cleanup temporary lists */ BLI_dlrbTree_free(&anim_keys); - - /* free list of channels, since it's not used anymore */ - ANIM_animdata_freelist(&anim_data); } - /* for replacing selection, firstly need to clear existing selection */ - if (select_mode == SELECT_REPLACE) { + /* free list of channels, since it's not used anymore */ + ANIM_animdata_freelist(&anim_data); + + /* For replacing selection, if we have something to select, we have to clear existing selection. + * The same goes if we found nothing to select, and deselect_all is true + * (deselect on nothing behavior). */ + if ((select_mode == SELECT_REPLACE && found) || (!found && deselect_all)) { /* reset selection mode for next steps */ select_mode = SELECT_ADD; @@ -1536,7 +1574,7 @@ static void mouse_action_keys( ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR); /* Highlight Action-Group or F-Curve? */ - if (ale && ale->data) { + if (ale != NULL && ale->data) { if (ale->type == ANIMTYPE_GROUP) { bActionGroup *agrp = ale->data; @@ -1556,11 +1594,11 @@ static void mouse_action_keys( ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR); /* Highlight GPencil Layer */ - if ((ale && ale->data) && (ale->type == ANIMTYPE_GPLAYER)) { + if (ale != NULL && ale->data != NULL && ale->type == ANIMTYPE_GPLAYER) { bGPDlayer *gpl = ale->data; gpl->flag |= GP_LAYER_SELECT; - //gpencil_layer_setactive(gpd, gpl); + // gpencil_layer_setactive(gpd, gpl); } } else if (ac->datatype == ANIMCONT_MASK) { @@ -1568,17 +1606,17 @@ static void mouse_action_keys( ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR); /* Highlight GPencil Layer */ - if ((ale && ale->data) && (ale->type == ANIMTYPE_MASKLAYER)) { + if (ale != NULL && ale->data != NULL && ale->type == ANIMTYPE_MASKLAYER) { MaskLayer *masklay = ale->data; masklay->flag |= MASK_LAYERFLAG_SELECT; - //gpencil_layer_setactive(gpd, gpl); + // gpencil_layer_setactive(gpd, gpl); } } } /* only select keyframes if we clicked on a valid channel and hit something */ - if (ale) { + if (ale != NULL) { if (found) { /* apply selection to keyframes */ if (column) { @@ -1613,29 +1651,25 @@ static void mouse_action_keys( static int actkeys_clickselect_invoke(bContext *C, wmOperator *op, const wmEvent *event) { bAnimContext ac; - /* ARegion *ar; */ /* UNUSED */ - short selectmode; - bool column, channel; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get useful pointers from animation context data */ /* ar = ac.ar; */ /* UNUSED */ /* select mode is either replace (deselect all, then add) or add/extend */ - if (RNA_boolean_get(op->ptr, "extend")) - selectmode = SELECT_INVERT; - else - selectmode = SELECT_REPLACE; + const short selectmode = RNA_boolean_get(op->ptr, "extend") ? SELECT_INVERT : SELECT_REPLACE; + const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all"); /* column selection */ - column = RNA_boolean_get(op->ptr, "column"); - channel = RNA_boolean_get(op->ptr, "channel"); + const bool column = RNA_boolean_get(op->ptr, "column"); + const bool channel = RNA_boolean_get(op->ptr, "channel"); /* select keyframe(s) based upon mouse position*/ - mouse_action_keys(&ac, event->mval, selectmode, column, channel); + mouse_action_keys(&ac, event->mval, selectmode, deselect_all, column, channel); /* set notifier that keyframe selection (and channels too) have changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); @@ -1670,6 +1704,13 @@ void ACTION_OT_clickselect(wmOperatorType *ot) "Toggle keyframe selection instead of leaving newly selected keyframes only"); // SHIFTKEY RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_boolean(ot->srna, + "deselect_all", + false, + "Deselect On Nothing", + "Deselect all when nothing under the cursor"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_boolean( ot->srna, "column", diff --git a/source/blender/editors/space_action/space_action.c b/source/blender/editors/space_action/space_action.c index bfbca07d530..843abbd16db 100644 --- a/source/blender/editors/space_action/space_action.c +++ b/source/blender/editors/space_action/space_action.c @@ -56,34 +56,6 @@ #include "action_intern.h" /* own include */ #include "GPU_framebuffer.h" -/* ******************** manage regions ********************* */ - -ARegion *action_has_buttons_region(ScrArea *sa) -{ - ARegion *ar, *arnew; - - ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); - if (ar) - return ar; - - /* add subdiv level; after main */ - ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); - - /* is error! */ - if (ar == NULL) - return NULL; - - arnew = MEM_callocN(sizeof(ARegion), "buttons for action"); - - BLI_insertlinkafter(&sa->regionbase, ar, arnew); - arnew->regiontype = RGN_TYPE_UI; - arnew->alignment = RGN_ALIGN_RIGHT; - - arnew->flag = RGN_FLAG_HIDDEN; - - return arnew; -} - /* ******************** default callbacks for action space ***************** */ static SpaceLink *action_new(const ScrArea *sa, const Scene *scene) @@ -194,7 +166,7 @@ static void action_main_region_init(wmWindowManager *wm, ARegion *ar) /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "Dopesheet", SPACE_ACTION, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); } @@ -207,11 +179,9 @@ static void action_main_region_draw(const bContext *C, ARegion *ar) Object *obact = CTX_data_active_object(C); bAnimContext ac; View2D *v2d = &ar->v2d; - View2DGrid *grid; View2DScrollers *scrollers; short marker_flag = 0; short cfra_flag = 0; - short unit = 0; /* clear and setup matrix */ UI_ThemeClearColor(TH_BACK); @@ -220,17 +190,7 @@ static void action_main_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_ortho(v2d); /* time grid */ - unit = (saction->flag & SACTION_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES; - grid = UI_view2d_grid_calc(CTX_data_scene(C), - v2d, - unit, - V2D_GRID_CLAMP, - V2D_ARG_DUMMY, - V2D_ARG_DUMMY, - ar->winx, - ar->winy); - UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL); - UI_view2d_grid_free(grid); + UI_view2d_draw_lines_x__discrete_frames_or_seconds(v2d, scene, saction->flag & SACTION_DRAWTIME); ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); @@ -243,8 +203,9 @@ static void action_main_region_draw(const bContext *C, ARegion *ar) } /* current frame */ - if (saction->flag & SACTION_DRAWTIME) + if (saction->flag & SACTION_DRAWTIME) { cfra_flag |= DRAWCFRA_UNIT_SECONDS; + } ANIM_draw_cfra(C, v2d, cfra_flag); /* markers */ @@ -252,8 +213,9 @@ static void action_main_region_draw(const bContext *C, ARegion *ar) marker_flag = ((ac.markers && (ac.markers != &ac.scene->markers)) ? DRAW_MARKERS_LOCAL : 0) | DRAW_MARKERS_MARGIN; - if (saction->flag & SACTION_SHOW_MARKER_LINES) + if (saction->flag & SACTION_SHOW_MARKER_LINES) { marker_flag |= DRAW_MARKERS_LINES; + } ED_markers_draw(C, marker_flag); /* caches */ @@ -273,11 +235,14 @@ static void action_main_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); /* scrollers */ - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY); - UI_view2d_scrollers_draw(C, v2d, scrollers); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); + /* frame numbers */ + UI_view2d_draw_scale_x__discrete_frames_or_seconds( + ar, v2d, &v2d->hor, scene, saction->flag & SACTION_DRAWTIME); + /* draw current frame number-indicator on top of scrollers */ if ((saction->flag & SACTION_NODRAWCFRANUM) == 0) { UI_view2d_view_orthoSpecial(ar, v2d, 1); @@ -297,7 +262,7 @@ static void action_channel_region_init(wmWindowManager *wm, ARegion *ar) /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "Animation Channels", 0, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); @@ -364,22 +329,26 @@ static void action_channel_region_listener(wmWindow *UNUSED(win), ED_region_tag_redraw(ar); break; case ND_MODIFIER: - if (wmn->action == NA_RENAME) + if (wmn->action == NA_RENAME) { ED_region_tag_redraw(ar); + } break; } break; case NC_GPENCIL: - if (ELEM(wmn->action, NA_RENAME, NA_SELECTED)) + if (ELEM(wmn->action, NA_RENAME, NA_SELECTED)) { ED_region_tag_redraw(ar); + } break; case NC_ID: - if (wmn->action == NA_RENAME) + if (wmn->action == NA_RENAME) { ED_region_tag_redraw(ar); + } break; default: - if (wmn->data == ND_KEYS) + if (wmn->data == ND_KEYS) { ED_region_tag_redraw(ar); + } break; } } @@ -471,8 +440,9 @@ static void action_main_region_listener(wmWindow *UNUSED(win), } break; case NC_ID: - if (wmn->action == NA_RENAME) + if (wmn->action == NA_RENAME) { ED_region_tag_redraw(ar); + } break; case NC_SCREEN: if (ELEM(wmn->data, ND_LAYER)) { @@ -480,8 +450,9 @@ static void action_main_region_listener(wmWindow *UNUSED(win), } break; default: - if (wmn->data == ND_KEYS) + if (wmn->data == ND_KEYS) { ED_region_tag_redraw(ar); + } break; } } @@ -607,8 +578,8 @@ static void action_listener(wmWindow *UNUSED(win), break; case NC_OBJECT: switch (wmn->data) { - case ND_BONE_SELECT: /* selection changed, so force refresh to flush - * (needs flag set to do syncing) */ + case ND_BONE_SELECT: /* Selection changed, so force refresh to flush + * (needs flag set to do syncing). */ case ND_BONE_ACTIVE: saction->runtime.flag |= SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC; ED_area_tag_refresh(sa); @@ -689,8 +660,9 @@ static void action_header_region_listener( switch (wmn->category) { case NC_SCREEN: if (saction->mode == SACTCONT_TIMELINE) { - if (wmn->data == ND_ANIMPLAY) + if (wmn->data == ND_ANIMPLAY) { ED_region_tag_redraw(ar); + } } break; case NC_SCENE: @@ -715,8 +687,9 @@ static void action_header_region_listener( } break; case NC_ID: - if (wmn->action == NA_RENAME) + if (wmn->action == NA_RENAME) { ED_region_tag_redraw(ar); + } break; case NC_ANIMATION: switch (wmn->data) { @@ -728,7 +701,7 @@ static void action_header_region_listener( break; case ND_KEYFRAME: /* new keyframed added -> active action may have changed */ - //saction->flag |= SACTION_TEMP_NEEDCHANSYNC; + // saction->flag |= SACTION_TEMP_NEEDCHANSYNC; ED_region_tag_redraw(ar); break; } @@ -782,8 +755,9 @@ static void action_region_listener(wmWindow *UNUSED(win), } break; default: - if (wmn->data == ND_KEYS) + if (wmn->data == ND_KEYS) { ED_region_tag_redraw(ar); + } break; } } @@ -792,15 +766,15 @@ static void action_refresh(const bContext *C, ScrArea *sa) { SpaceAction *saction = (SpaceAction *)sa->spacedata.first; - /* update the state of the animchannels in response to changes from the data they represent - * NOTE: the temp flag is used to indicate when this needs to be done, and will be cleared once handled - */ + /* Update the state of the animchannels in response to changes from the data they represent + * NOTE: the temp flag is used to indicate when this needs to be done, + * and will be cleared once handled. */ if (saction->runtime.flag & SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC) { ARegion *ar; /* Perform syncing of channel state incl. selection - * Active action setting also occurs here (as part of anim channel filtering in anim_filter.c) - */ + * Active action setting also occurs here + * (as part of anim channel filtering in anim_filter.c). */ ANIM_sync_animchannels_to_data(C); saction->runtime.flag &= ~SACTION_RUNTIME_FLAG_NEED_CHAN_SYNC; @@ -809,8 +783,9 @@ static void action_refresh(const bContext *C, ScrArea *sa) * or else they don't update [#28962] */ ED_area_tag_redraw(sa); - for (ar = sa->regionbase.first; ar; ar = ar->next) + for (ar = sa->regionbase.first; ar; ar = ar->next) { ED_region_tag_redraw(ar); + } } /* region updates? */ diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c index 89758bd35da..95775f80b50 100644 --- a/source/blender/editors/space_api/spacetypes.c +++ b/source/blender/editors/space_api/spacetypes.c @@ -179,8 +179,9 @@ void ED_spacemacros_init(void) /* register dropboxes (can use macros) */ spacetypes = BKE_spacetypes_list(); for (type = spacetypes->first; type; type = type->next) { - if (type->dropboxes) + if (type->dropboxes) { type->dropboxes(); + } } } @@ -216,11 +217,13 @@ void ED_spacetypes_keymap(wmKeyConfig *keyconf) spacetypes = BKE_spacetypes_list(); for (stype = spacetypes->first; stype; stype = stype->next) { - if (stype->keymap) + if (stype->keymap) { stype->keymap(keyconf); + } for (atype = stype->regiontypes.first; atype; atype = atype->next) { - if (atype->keymap) + if (atype->keymap) { atype->keymap(keyconf); + } } } } diff --git a/source/blender/editors/space_buttons/CMakeLists.txt b/source/blender/editors/space_buttons/CMakeLists.txt index ce08b62e8ef..25ff6bbd098 100644 --- a/source/blender/editors/space_buttons/CMakeLists.txt +++ b/source/blender/editors/space_buttons/CMakeLists.txt @@ -24,8 +24,8 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c index 1b1c3bf6d13..f9244049d54 100644 --- a/source/blender/editors/space_buttons/space_buttons.c +++ b/source/blender/editors/space_buttons/space_buttons.c @@ -203,14 +203,14 @@ static void buttons_main_region_layout_properties(const bContext *C, static void buttons_main_region_layout_tool(const bContext *C, ARegion *ar) { - const WorkSpace *workspace = CTX_wm_workspace(C); const enum eContextObjectMode mode = CTX_data_mode_enum(C); const char *contexts_base[5] = {NULL}; contexts_base[0] = ".active_tool"; const char **contexts = &contexts_base[1]; - if (workspace->tools_space_type == SPACE_VIEW3D) { + /* Hard coded to 3D view. */ + { switch (mode) { case CTX_MODE_EDIT_MESH: ARRAY_SET_ITEMS(contexts, ".mesh_edit"); @@ -267,22 +267,6 @@ static void buttons_main_region_layout_tool(const bContext *C, ARegion *ar) break; } } - else if (workspace->tools_space_type == SPACE_IMAGE) { - switch (workspace->tools_mode) { - case SI_MODE_VIEW: - break; - case SI_MODE_PAINT: - ARRAY_SET_ITEMS(contexts, ".paint_common_2d", ".imagepaint_2d"); - break; - case SI_MODE_MASK: - break; - case SI_MODE_UV: - if (mode == CTX_MODE_EDIT_MESH) { - ARRAY_SET_ITEMS(contexts, ".uv_sculpt"); - } - break; - } - } /* for grease pencil we don't use tool system yet, so we need check outside * workspace->tools_space_type because this value is not available diff --git a/source/blender/editors/space_clip/CMakeLists.txt b/source/blender/editors/space_clip/CMakeLists.txt index ed98dcdc159..2ea4bc97d18 100644 --- a/source/blender/editors/space_clip/CMakeLists.txt +++ b/source/blender/editors/space_clip/CMakeLists.txt @@ -24,13 +24,13 @@ set(INC ../../blenlib ../../blentranslation ../../depsgraph - ../../imbuf ../../gpu + ../../imbuf ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_clip/clip_buttons.c b/source/blender/editors/space_clip/clip_buttons.c index 6f950ec5bc4..c985d61a8b8 100644 --- a/source/blender/editors/space_clip/clip_buttons.c +++ b/source/blender/editors/space_clip/clip_buttons.c @@ -110,8 +110,9 @@ void uiTemplateMovieClip( uiLayout *row, *split; uiBlock *block; - if (!ptr->data) + if (!ptr->data) { return; + } prop = RNA_struct_find_property(ptr, propname); if (!prop) { @@ -133,9 +134,10 @@ void uiTemplateMovieClip( uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr); - if (!compact) + if (!compact) { uiTemplateID( layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + } if (clip) { uiLayout *col; @@ -166,8 +168,9 @@ void uiTemplateTrack(uiLayout *layout, PointerRNA *ptr, const char *propname) uiLayout *col; MovieClipScopes *scopes; - if (!ptr->data) + if (!ptr->data) { return; + } prop = RNA_struct_find_property(ptr, propname); if (!prop) { @@ -274,8 +277,9 @@ static void marker_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg)) MarkerUpdateCb *cb = (MarkerUpdateCb *)arg_cb; MovieTrackingMarker *marker; - if (!cb->compact) + if (!cb->compact) { return; + } marker = BKE_tracking_marker_ensure(cb->track, cb->framenr); @@ -381,8 +385,9 @@ static void marker_block_handler(bContext *C, void *arg_cb, int event) sub_v2_v2v2(delta, offset, cb->track->offset); copy_v2_v2(cb->track->offset, offset); - for (i = 0; i < cb->track->markersnr; i++) + for (i = 0; i < cb->track->markersnr; i++) { sub_v2_v2(cb->track->markers[i].pos, delta); + } /* to update position of "parented" objects */ DEG_id_tag_update(&cb->clip->id, 0); @@ -391,8 +396,9 @@ static void marker_block_handler(bContext *C, void *arg_cb, int event) ok = true; } - if (ok) + if (ok) { WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, cb->clip); + } } void uiTemplateMarker(uiLayout *layout, @@ -414,8 +420,9 @@ void uiTemplateMarker(uiLayout *layout, const char *tip; float pat_min[2], pat_max[2]; - if (!ptr->data) + if (!ptr->data) { return; + } prop = RNA_struct_find_property(ptr, propname); if (!prop) { @@ -451,10 +458,12 @@ void uiTemplateMarker(uiLayout *layout, if (compact) { block = uiLayoutGetBlock(layout); - if (cb->marker_flag & MARKER_DISABLED) + if (cb->marker_flag & MARKER_DISABLED) { tip = TIP_("Marker is disabled at current frame"); - else + } + else { tip = TIP_("Marker is enabled at current frame"); + } bt = uiDefIconButBitI(block, UI_BTYPE_TOGGLE_N, @@ -525,10 +534,12 @@ void uiTemplateMarker(uiLayout *layout, UI_block_func_handle_set(block, marker_block_handler, cb); UI_block_funcN_set(block, marker_update_cb, cb, NULL); - if (cb->marker_flag & MARKER_DISABLED) + if (cb->marker_flag & MARKER_DISABLED) { tip = TIP_("Marker is disabled at current frame"); - else + } + else { tip = TIP_("Marker is enabled at current frame"); + } uiDefButBitI(block, UI_BTYPE_CHECKBOX_N, @@ -773,8 +784,9 @@ void uiTemplateMovieclipInformation(uiLayout *layout, ImBuf *ibuf; size_t ofs = 0; - if (!ptr->data) + if (!ptr->data) { return; + } prop = RNA_struct_find_property(ptr, propname); if (!prop) { @@ -805,19 +817,24 @@ void uiTemplateMovieclipInformation(uiLayout *layout, if (ibuf) { if (ibuf->rect_float) { - if (ibuf->channels != 4) + if (ibuf->channels != 4) { ofs += BLI_snprintf( str + ofs, sizeof(str) - ofs, IFACE_(", %d float channel(s)"), ibuf->channels); - else if (ibuf->planes == R_IMF_PLANES_RGBA) + } + else if (ibuf->planes == R_IMF_PLANES_RGBA) { ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", RGBA float"), sizeof(str) - ofs); - else + } + else { ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", RGB float"), sizeof(str) - ofs); + } } else { - if (ibuf->planes == R_IMF_PLANES_RGBA) + if (ibuf->planes == R_IMF_PLANES_RGBA) { ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", RGBA byte"), sizeof(str) - ofs); - else + } + else { ofs += BLI_strncpy_rlen(str + ofs, IFACE_(", RGB byte"), sizeof(str) - ofs); + } } if (clip->anim != NULL) { @@ -837,10 +854,12 @@ void uiTemplateMovieclipInformation(uiLayout *layout, /* Display current frame number. */ framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, user->framenr); - if (framenr <= clip->len) + if (framenr <= clip->len) { BLI_snprintf(str, sizeof(str), IFACE_("Frame: %d / %d"), framenr, clip->len); - else + } + else { BLI_snprintf(str, sizeof(str), IFACE_("Frame: - / %d"), clip->len); + } uiItemL(col, str, ICON_NONE); /* Display current file name if it's a sequence clip. */ diff --git a/source/blender/editors/space_clip/clip_dopesheet_draw.c b/source/blender/editors/space_clip/clip_dopesheet_draw.c index 8ac0870f7f1..0f6e7947482 100644 --- a/source/blender/editors/space_clip/clip_dopesheet_draw.c +++ b/source/blender/editors/space_clip/clip_dopesheet_draw.c @@ -59,10 +59,12 @@ static void track_channel_color(MovieTrackingTrack *track, float default_color[3 interp_v3_v3v3(color, track->color, bg, 0.5); } else { - if (default_color) + if (default_color) { copy_v3_v3(color, default_color); - else + } + else { UI_GetThemeColor3fv(TH_HEADER, color); + } } } @@ -297,8 +299,9 @@ void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar) uiStyle *style = UI_style_get(); int fontid = style->widget.uifont_id; - if (!clip) + if (!clip) { return; + } MovieTracking *tracking = &clip->tracking; MovieTrackingDopesheet *dopesheet = &tracking->dopesheet; diff --git a/source/blender/editors/space_clip/clip_dopesheet_ops.c b/source/blender/editors/space_clip/clip_dopesheet_ops.c index e7f0f8c3fcc..785ced96b13 100644 --- a/source/blender/editors/space_clip/clip_dopesheet_ops.c +++ b/source/blender/editors/space_clip/clip_dopesheet_ops.c @@ -66,8 +66,9 @@ static bool dopesheet_select_channel_poll(bContext *C) { SpaceClip *sc = CTX_wm_space_clip(C); - if (sc && sc->clip) + if (sc && sc->clip) { return sc->view == SC_VIEW_DOPESHEET; + } return false; } @@ -93,10 +94,12 @@ static int dopesheet_select_channel_exec(bContext *C, wmOperator *op) MovieTrackingTrack *track = channel->track; if (current_channel_index == channel_index) { - if (extend) + if (extend) { track->flag ^= TRACK_DOPE_SEL; - else + } + else { track->flag |= TRACK_DOPE_SEL; + } if (track->flag & TRACK_DOPE_SEL) { tracking->act_track = track; @@ -106,8 +109,9 @@ static int dopesheet_select_channel_exec(bContext *C, wmOperator *op) BKE_tracking_track_deselect(track, TRACK_AREA_ALL); } } - else if (!extend) + else if (!extend) { track->flag &= ~TRACK_DOPE_SEL; + } current_channel_index++; } diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index a3aa4f4bed5..99f9a91775e 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -178,12 +178,14 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc while (a < markersnr) { int marker_framenr = generic_track_get_marker_framenr(act_track, act_plane_track, a); - if (marker_framenr >= i) + if (marker_framenr >= i) { break; + } if (a < markersnr - 1 && - generic_track_get_marker_framenr(act_track, act_plane_track, a + 1) > i) + generic_track_get_marker_framenr(act_track, act_plane_track, a + 1) > i) { break; + } a++; } @@ -284,8 +286,9 @@ static void draw_movieclip_notes(SpaceClip *sc, ARegion *ar) full_redraw = true; } else { - if (sc->flag & SC_LOCK_SELECTION) + if (sc->flag & SC_LOCK_SELECTION) { strcpy(str, "Locked"); + } } if (str[0]) { @@ -341,7 +344,7 @@ static void draw_movieclip_buffer(const bContext *C, filter = GL_NEAREST; } - glaDrawImBuf_glsl_ctx(C, ibuf, x, y, filter, zoomx * width / ibuf->x, zoomy * height / ibuf->y); + ED_draw_imbuf_ctx(C, ibuf, x, y, filter, zoomx * width / ibuf->x, zoomy * height / ibuf->y); if (ibuf->planes == 32) { GPU_blend(false); @@ -411,14 +414,16 @@ static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackin int tiny = sc->flag & SC_SHOW_TINY_MARKER, framenr, start_frame; MovieTrackingMarker *marker; - if (count == 0) + if (count == 0) { return; + } start_frame = framenr = ED_space_clip_get_clip_frame_number(sc); marker = BKE_tracking_marker_get(track, framenr); - if (marker->framenr != framenr || marker->flag & MARKER_DISABLED) + if (marker->framenr != framenr || marker->flag & MARKER_DISABLED) { return; + } if (count < MAX_STATIC_PATH) { path = path_static; @@ -432,15 +437,17 @@ static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackin while (i >= framenr - count) { marker = BKE_tracking_marker_get(track, i); - if (!marker || marker->flag & MARKER_DISABLED) + if (!marker || marker->flag & MARKER_DISABLED) { break; + } if (marker->framenr == i) { add_v2_v2v2(path[--a], marker->pos, track->offset); ED_clip_point_undistorted_pos(sc, path[a], path[a]); - if (marker->framenr == start_frame) + if (marker->framenr == start_frame) { curindex = a; + } } else { break; @@ -454,18 +461,21 @@ static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackin while (i <= framenr + count) { marker = BKE_tracking_marker_get(track, i); - if (!marker || marker->flag & MARKER_DISABLED) + if (!marker || marker->flag & MARKER_DISABLED) { break; + } if (marker->framenr == i) { - if (marker->framenr == start_frame) + if (marker->framenr == start_frame) { curindex = b; + } add_v2_v2v2(path[b++], marker->pos, track->offset); ED_clip_point_undistorted_pos(sc, path[b - 1], path[b - 1]); } - else + else { break; + } i++; } @@ -658,20 +668,24 @@ static void draw_marker_outline(SpaceClip *sc, static void track_colors(MovieTrackingTrack *track, int act, float col[3], float scol[3]) { if (track->flag & TRACK_CUSTOMCOLOR) { - if (act) + if (act) { UI_GetThemeColor3fv(TH_ACT_MARKER, scol); - else + } + else { copy_v3_v3(scol, track->color); + } mul_v3_v3fl(col, track->color, 0.5f); } else { UI_GetThemeColor3fv(TH_MARKER, col); - if (act) + if (act) { UI_GetThemeColor3fv(TH_ACT_MARKER, scol); - else + } + else { UI_GetThemeColor3fv(TH_SEL_MARKER, scol); + } } } @@ -923,11 +937,13 @@ static void draw_marker_slide_zones(SpaceClip *sc, int tiny = sc->flag & SC_SHOW_TINY_MARKER; float col[3], scol[3], px[2], side; - if ((tiny && outline) || (marker->flag & MARKER_DISABLED)) + if ((tiny && outline) || (marker->flag & MARKER_DISABLED)) { return; + } - if (!TRACK_VIEW_SELECTED(sc, track) || track->flag & TRACK_LOCKED) + if (!TRACK_VIEW_SELECTED(sc, track) || track->flag & TRACK_LOCKED) { return; + } track_colors(track, act, col, scol); @@ -1020,8 +1036,9 @@ static void draw_marker_texts(SpaceClip *sc, uiStyle *style = U.uistyles.first; int fontid = style->widget.uifont_id; - if (!TRACK_VIEW_SELECTED(sc, track)) + if (!TRACK_VIEW_SELECTED(sc, track)) { return; + } BLF_size(fontid, 11.0f * U.pixelsize, U.dpi); fontsize = BLF_height_max(fontid); @@ -1062,19 +1079,25 @@ static void draw_marker_texts(SpaceClip *sc, pos[0] = pos[0] * zoomx; pos[1] = pos[1] * zoomy - fontsize; - if (marker->flag & MARKER_DISABLED) + if (marker->flag & MARKER_DISABLED) { strcpy(state, "disabled"); - else if (marker->framenr != ED_space_clip_get_clip_frame_number(sc)) + } + else if (marker->framenr != ED_space_clip_get_clip_frame_number(sc)) { strcpy(state, "estimated"); - else if (marker->flag & MARKER_TRACKED) + } + else if (marker->flag & MARKER_TRACKED) { strcpy(state, "tracked"); - else + } + else { strcpy(state, "keyframed"); + } - if (state[0]) + if (state[0]) { BLI_snprintf(str, sizeof(str), "%s: %s", track->name, state); - else + } + else { BLI_strncpy(str, track->name, sizeof(str)); + } BLF_position(fontid, pos[0], pos[1], 0.0f); BLF_draw(fontid, str, sizeof(str)); @@ -1479,8 +1502,9 @@ static void draw_tracking_tracks(SpaceClip *sc, if ((track->flag & TRACK_HIDDEN) == 0) { marker = BKE_tracking_marker_get(track, framenr); - if (MARKER_VISIBLE(sc, track, marker)) + if (MARKER_VISIBLE(sc, track, marker)) { count++; + } } track = track->next; @@ -1499,8 +1523,9 @@ static void draw_tracking_tracks(SpaceClip *sc, if (MARKER_VISIBLE(sc, track, marker)) { ED_clip_point_undistorted_pos(sc, marker->pos, fp); - if (track == act_track) + if (track == act_track) { active_pos = fp; + } fp += 2; } @@ -1514,8 +1539,9 @@ static void draw_tracking_tracks(SpaceClip *sc, if (sc->flag & SC_SHOW_TRACK_PATH) { track = tracksbase->first; while (track) { - if ((track->flag & TRACK_HIDDEN) == 0) + if ((track->flag & TRACK_HIDDEN) == 0) { draw_track_path(sc, clip, track); + } track = track->next; } @@ -1541,8 +1567,9 @@ static void draw_tracking_tracks(SpaceClip *sc, draw_marker_slide_zones(sc, track, marker, cur_pos, 1, 0, 0, width, height, position); draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 0, 0, width, height, position); - if (fp) + if (fp) { fp += 2; + } } } @@ -1566,8 +1593,9 @@ static void draw_tracking_tracks(SpaceClip *sc, draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 1, 0, width, height, position); } - if (fp) + if (fp) { fp += 2; + } } } @@ -1664,8 +1692,9 @@ static void draw_tracking_tracks(SpaceClip *sc, draw_marker_texts(sc, track, marker, cur_pos, act, width, height, zoomx, zoomy); - if (fp) + if (fp) { fp += 2; + } } } @@ -1675,8 +1704,9 @@ static void draw_tracking_tracks(SpaceClip *sc, GPU_matrix_pop(); - if (marker_pos) + if (marker_pos) { MEM_freeN(marker_pos); + } } static void draw_distortion( @@ -1692,11 +1722,13 @@ static void draw_distortion( float dx = (float)width / n, dy = (float)height / n * aspy; float offsx = 0.0f, offsy = 0.0f; - if (!tracking->camera.focal) + if (!tracking->camera.focal) { return; + } - if ((sc->flag & SC_SHOW_GRID) == 0 && (sc->flag & SC_MANUAL_CALIBRATION) == 0) + if ((sc->flag & SC_SHOW_GRID) == 0 && (sc->flag & SC_MANUAL_CALIBRATION) == 0) { return; + } UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y); @@ -1717,10 +1749,12 @@ static void draw_distortion( float min[2], max[2]; for (a = 0; a < 4; a++) { - if (a < 2) + if (a < 2) { val[a][a % 2] = FLT_MAX; - else + } + else { val[a][a % 2] = -FLT_MAX; + } } zero_v2(pos); @@ -1732,10 +1766,12 @@ static void draw_distortion( for (a = 0; a < 4; a++) { int ok; - if (a < 2) + if (a < 2) { ok = tpos[a % 2] < val[a][a % 2]; - else + } + else { ok = tpos[a % 2] > val[a][a % 2]; + } if (ok) { copy_v2_v2(val[a], tpos); @@ -1912,10 +1948,12 @@ void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar) ibuf = ED_space_clip_get_stable_buffer(sc, sc->loc, &sc->scale, &sc->angle); } - if (ibuf != NULL && width != ibuf->x) + if (ibuf != NULL && width != ibuf->x) { mul_v2_v2fl(translation, sc->loc, (float)width / ibuf->x); - else + } + else { copy_v2_v2(translation, sc->loc); + } BKE_tracking_stabilization_data_to_mat4( width, height, aspect, translation, sc->scale, sc->angle, sc->stabmat); @@ -1970,8 +2008,9 @@ void clip_draw_grease_pencil(bContext *C, int onlyv2d) SpaceClip *sc = CTX_wm_space_clip(C); MovieClip *clip = ED_space_clip_get_clip(sc); - if (!clip) + if (!clip) { return; + } if (onlyv2d) { bool is_track_source = sc->gpencil_src == SC_GPENCIL_SRC_TRACK; diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index 8351f79aac7..b0b6aa47df1 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -72,8 +72,9 @@ bool ED_space_clip_poll(bContext *C) { SpaceClip *sc = CTX_wm_space_clip(C); - if (sc && sc->clip) + if (sc && sc->clip) { return true; + } return false; } @@ -93,8 +94,9 @@ bool ED_space_clip_tracking_poll(bContext *C) { SpaceClip *sc = CTX_wm_space_clip(C); - if (sc && sc->clip) + if (sc && sc->clip) { return ED_space_clip_check_show_trackedit(sc); + } return false; } @@ -159,10 +161,12 @@ void ED_space_clip_get_aspect(SpaceClip *sc, float *aspx, float *aspy) { MovieClip *clip = ED_space_clip_get_clip(sc); - if (clip) + if (clip) { BKE_movieclip_get_aspect(clip, aspx, aspy); - else + } + else { *aspx = *aspy = 1.0f; + } if (*aspx < *aspy) { *aspy = *aspy / *aspx; @@ -224,11 +228,13 @@ ImBuf *ED_space_clip_get_buffer(SpaceClip *sc) ibuf = BKE_movieclip_get_postprocessed_ibuf(sc->clip, &sc->user, sc->postproc_flag); - if (ibuf && (ibuf->rect || ibuf->rect_float)) + if (ibuf && (ibuf->rect || ibuf->rect_float)) { return ibuf; + } - if (ibuf) + if (ibuf) { IMB_freeImBuf(ibuf); + } } return NULL; @@ -242,11 +248,13 @@ ImBuf *ED_space_clip_get_stable_buffer(SpaceClip *sc, float loc[2], float *scale ibuf = BKE_movieclip_get_stable_ibuf( sc->clip, &sc->user, loc, scale, angle, sc->postproc_flag); - if (ibuf && (ibuf->rect || ibuf->rect_float)) + if (ibuf && (ibuf->rect || ibuf->rect_float)) { return ibuf; + } - if (ibuf) + if (ibuf) { IMB_freeImBuf(ibuf); + } } return NULL; @@ -395,11 +403,13 @@ bool ED_clip_view_selection(const bContext *C, ARegion *ar, bool fit) ED_space_clip_get_size(sc, &frame_width, &frame_height); - if ((frame_width == 0) || (frame_height == 0) || (sc->clip == NULL)) + if ((frame_width == 0) || (frame_height == 0) || (sc->clip == NULL)) { return false; + } - if (!selected_boundbox(C, min, max)) + if (!selected_boundbox(C, min, max)) { return false; + } /* center view */ clip_view_center_to_point( @@ -423,8 +433,9 @@ bool ED_clip_view_selection(const bContext *C, ARegion *ar, bool fit) newzoom = 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)); - if (fit || sc->zoom > newzoom) + if (fit || sc->zoom > newzoom) { sc->zoom = newzoom; + } } return true; @@ -489,8 +500,9 @@ void ED_clip_select_all(SpaceClip *sc, int action, bool *r_has_selection) } } - if (TRACK_VIEW_SELECTED(sc, track)) + if (TRACK_VIEW_SELECTED(sc, track)) { has_selection = true; + } } for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { @@ -635,8 +647,9 @@ void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieCl MovieClip *old_clip; bool old_clip_visible = false; - if (!screen && C) + if (!screen && C) { screen = CTX_wm_screen(C); + } old_clip = sc->clip; sc->clip = clip; @@ -654,8 +667,9 @@ void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieCl if (cur_sc != sc) { if (cur_sc->view == SC_VIEW_CLIP) { - if (cur_sc->clip == old_clip) + if (cur_sc->clip == old_clip) { old_clip_visible = true; + } } else { if (cur_sc->clip == old_clip || cur_sc->clip == NULL) { @@ -673,8 +687,9 @@ void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieCl BKE_movieclip_clear_cache(old_clip); } - if (C) + if (C) { WM_event_add_notifier(C, NC_MOVIECLIP | NA_SELECTED, sc->clip); + } } /* ******** masking editing functions ******** */ @@ -785,16 +800,18 @@ static int prefetch_find_uncached_frame(MovieClip *clip, for (current_frame = from_frame; current_frame <= end_frame; current_frame++) { user.framenr = current_frame; - if (!BKE_movieclip_has_cached_frame(clip, &user)) + if (!BKE_movieclip_has_cached_frame(clip, &user)) { break; + } } } else { for (current_frame = from_frame; current_frame >= end_frame; current_frame--) { user.framenr = current_frame; - if (!BKE_movieclip_has_cached_frame(clip, &user)) + if (!BKE_movieclip_has_cached_frame(clip, &user)) { break; + } } } @@ -956,8 +973,9 @@ static bool prefetch_movie_frame( MovieClipUser user = {0}; ImBuf *ibuf; - if (check_prefetch_break() || *stop) + if (check_prefetch_break() || *stop) { return false; + } user.framenr = frame; user.render_size = render_size; @@ -1002,8 +1020,9 @@ static void do_prefetch_movie(MovieClip *clip, /* read frames starting from current frame up to scene end frame */ for (frame = current_frame; frame <= end_frame; frame++) { - if (!prefetch_movie_frame(clip, frame, render_size, render_flag, stop)) + if (!prefetch_movie_frame(clip, frame, render_size, render_flag, stop)) { return; + } frames_processed++; @@ -1013,8 +1032,9 @@ static void do_prefetch_movie(MovieClip *clip, /* read frames starting from current frame up to scene start frame */ for (frame = current_frame; frame >= start_frame; frame--) { - if (!prefetch_movie_frame(clip, frame, render_size, render_flag, stop)) + if (!prefetch_movie_frame(clip, frame, render_size, render_flag, stop)) { return; + } frames_processed++; @@ -1113,8 +1133,9 @@ static bool prefetch_check_early_out(const bContext *C) first_uncached_frame = prefetch_find_uncached_frame( clip, sc->user.framenr, start_frame, sc->user.render_size, sc->user.render_flag, -1); - if (first_uncached_frame < start_frame) + if (first_uncached_frame < start_frame) { return true; + } } return false; @@ -1126,8 +1147,9 @@ void clip_start_prefetch_job(const bContext *C) PrefetchJob *pj; SpaceClip *sc = CTX_wm_space_clip(C); - if (prefetch_check_early_out(C)) + if (prefetch_check_early_out(C)) { return; + } wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), diff --git a/source/blender/editors/space_clip/clip_graph_draw.c b/source/blender/editors/space_clip/clip_graph_draw.c index c7602907954..ef5de1acee3 100644 --- a/source/blender/editors/space_clip/clip_graph_draw.c +++ b/source/blender/editors/space_clip/clip_graph_draw.c @@ -111,8 +111,9 @@ static void tracking_segment_knot_cb(void *userdata, TrackMotionCurveUserData *data = (TrackMotionCurveUserData *)userdata; int sel = 0, sel_flag; - if (track != data->act_track) + if (track != data->act_track) { return; + } sel_flag = coord == 0 ? MARKER_GRAPH_SEL_X : MARKER_GRAPH_SEL_Y; sel = (marker->flag & sel_flag) ? 1 : 0; @@ -140,8 +141,9 @@ static void draw_tracks_motion_curves(View2D *v2d, SpaceClip *sc, unsigned int p BKE_movieclip_get_size(clip, &sc->user, &width, &height); - if (!width || !height) + if (!width || !height) { return; + } /* non-selected knot handles */ userdata.hsize = UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE); @@ -337,14 +339,10 @@ void clip_draw_graph(SpaceClip *sc, ARegion *ar, Scene *scene) { MovieClip *clip = ED_space_clip_get_clip(sc); View2D *v2d = &ar->v2d; - View2DGrid *grid; - short unitx = V2D_UNIT_FRAMESCALE, unity = V2D_UNIT_VALUES; /* grid */ - grid = UI_view2d_grid_calc( - scene, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, ar->winx, ar->winy); - UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL); - UI_view2d_grid_free(grid); + UI_view2d_draw_lines_x__values(v2d); + UI_view2d_draw_lines_y__values(v2d); if (clip) { uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); diff --git a/source/blender/editors/space_clip/clip_graph_ops.c b/source/blender/editors/space_clip/clip_graph_ops.c index 7a61aced8b5..a3722433e33 100644 --- a/source/blender/editors/space_clip/clip_graph_ops.c +++ b/source/blender/editors/space_clip/clip_graph_ops.c @@ -200,16 +200,20 @@ static bool mouse_select_knot(bContext *C, float co[2], bool extend) } if (userdata.coord == 0) { - if (extend && (userdata.marker->flag & MARKER_GRAPH_SEL_X) != 0) + if (extend && (userdata.marker->flag & MARKER_GRAPH_SEL_X) != 0) { userdata.marker->flag &= ~MARKER_GRAPH_SEL_X; - else + } + else { userdata.marker->flag |= MARKER_GRAPH_SEL_X; + } } else { - if (extend && (userdata.marker->flag & MARKER_GRAPH_SEL_Y) != 0) + if (extend && (userdata.marker->flag & MARKER_GRAPH_SEL_Y) != 0) { userdata.marker->flag &= ~MARKER_GRAPH_SEL_Y; - else + } + else { userdata.marker->flag |= MARKER_GRAPH_SEL_Y; + } } return true; @@ -281,8 +285,9 @@ static int mouse_select(bContext *C, float co[2], bool extend) sel = mouse_select_curve(C, co, extend); } - if (sel) + if (sel) { WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL); + } return OPERATOR_FINISHED; } @@ -360,10 +365,12 @@ static void box_select_cb(void *userdata, if (BLI_rctf_isect_pt(&data->rect, scene_framenr, val)) { int flag = 0; - if (coord == 0) + if (coord == 0) { flag = MARKER_GRAPH_SEL_X; - else + } + else { flag = MARKER_GRAPH_SEL_Y; + } if (data->select) { marker->flag |= flag; @@ -444,8 +451,9 @@ static int graph_select_all_markers_exec(bContext *C, wmOperator *op) int action = RNA_enum_get(op->ptr, "action"); int a; - if (!act_track) + if (!act_track) { return OPERATOR_CANCELLED; + } if (action == SEL_TOGGLE) { action = SEL_SELECT; @@ -507,8 +515,9 @@ static int delete_curve_exec(bContext *C, wmOperator *UNUSED(op)) MovieTracking *tracking = &clip->tracking; MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking); - if (!act_track) + if (!act_track) { return OPERATOR_CANCELLED; + } clip_delete_track(C, clip, act_track); @@ -546,10 +555,12 @@ static int delete_knot_exec(bContext *C, wmOperator *UNUSED(op)) while (a < act_track->markersnr) { MovieTrackingMarker *marker = &act_track->markers[a]; - if (marker->flag & MARKER_GRAPH_SEL) + if (marker->flag & MARKER_GRAPH_SEL) { clip_delete_marker(C, clip, act_track, marker); - else + } + else { a++; + } } } @@ -586,11 +597,13 @@ static void view_all_cb(void *userdata, { ViewAllUserData *data = (ViewAllUserData *)userdata; - if (val < data->min) + if (val < data->min) { data->min = val; + } - if (val > data->max) + if (val > data->max) { data->max = val; + } } static int view_all_exec(bContext *C, wmOperator *UNUSED(op)) @@ -700,19 +713,23 @@ static int graph_disable_markers_exec(bContext *C, wmOperator *op) int action = RNA_enum_get(op->ptr, "action"); int a; - if (!act_track || (act_track->flag & TRACK_LOCKED)) + if (!act_track || (act_track->flag & TRACK_LOCKED)) { return OPERATOR_CANCELLED; + } for (a = 0; a < act_track->markersnr; a++) { marker = &act_track->markers[a]; if (marker->flag & MARKER_GRAPH_SEL) { - if (action == 0) + if (action == 0) { marker->flag |= MARKER_DISABLED; - else if (action == 1) + } + else if (action == 1) { marker->flag &= ~MARKER_DISABLED; - else + } + else { marker->flag ^= MARKER_DISABLED; + } } } diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h index 8ecf596fac7..70dc1caf36f 100644 --- a/source/blender/editors/space_clip/clip_intern.h +++ b/source/blender/editors/space_clip/clip_intern.h @@ -110,8 +110,6 @@ void CLIP_OT_cursor_set(struct wmOperatorType *ot); /* clip_toolbar.c */ struct ARegion *ED_clip_has_properties_region(struct ScrArea *sa); -void CLIP_OT_tools(struct wmOperatorType *ot); -void CLIP_OT_properties(struct wmOperatorType *ot); /* clip_utils.c */ void clip_graph_tracking_values_iterate_track( diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index 3cebb53d31e..3f971c4444a 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -97,12 +97,15 @@ static void sclip_zoom_set(const bContext *C, float zoom, float location[2]) width *= sc->zoom; height *= sc->zoom; - if ((width < 4) && (height < 4) && sc->zoom < oldzoom) + if ((width < 4) && (height < 4) && sc->zoom < oldzoom) { sc->zoom = oldzoom; - else if (BLI_rcti_size_x(&ar->winrct) <= sc->zoom) + } + else if (BLI_rcti_size_x(&ar->winrct) <= sc->zoom) { sc->zoom = oldzoom; - else if (BLI_rcti_size_y(&ar->winrct) <= sc->zoom) + } + else if (BLI_rcti_size_y(&ar->winrct) <= sc->zoom) { sc->zoom = oldzoom; + } } if ((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && location) { @@ -216,8 +219,9 @@ static int open_exec(bContext *C, wmOperator *op) clip = BKE_movieclip_file_add_exists(bmain, str); if (!clip) { - if (op->customdata) + if (op->customdata) { MEM_freeN(op->customdata); + } BKE_reportf(op->reports, RPT_ERROR, @@ -228,8 +232,9 @@ static int open_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - if (!op->customdata) + if (!op->customdata) { open_init(C, op); + } /* hook into UI */ pprop = op->customdata; @@ -261,8 +266,9 @@ static int open_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event) char path[FILE_MAX]; MovieClip *clip = NULL; - if (sc) + if (sc) { clip = ED_space_clip_get_clip(sc); + } if (clip) { BLI_strncpy(path, clip->name, sizeof(path)); @@ -274,11 +280,13 @@ static int open_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event) BLI_strncpy(path, U.textudir, sizeof(path)); } - if (RNA_struct_property_is_set(op->ptr, "files")) + if (RNA_struct_property_is_set(op->ptr, "files")) { return open_exec(C, op); + } - if (!RNA_struct_property_is_set(op->ptr, "relative_path")) + if (!RNA_struct_property_is_set(op->ptr, "relative_path")) { RNA_boolean_set(op->ptr, "relative_path", (U.flag & USER_RELPATHS) != 0); + } open_init(C, op); @@ -318,8 +326,9 @@ static int reload_exec(bContext *C, wmOperator *UNUSED(op)) { MovieClip *clip = CTX_data_edit_movieclip(C); - if (!clip) + if (!clip) { return OPERATOR_CANCELLED; + } WM_jobs_kill_type(CTX_wm_manager(C), NULL, WM_JOB_TYPE_CLIP_PREFETCH); BKE_movieclip_reload(CTX_data_main(C), clip); @@ -360,10 +369,12 @@ static void view_pan_init(bContext *C, wmOperator *op, const wmEvent *event) vpd->x = event->x; vpd->y = event->y; - if (sc->flag & SC_LOCK_SELECTION) + if (sc->flag & SC_LOCK_SELECTION) { vpd->vec = &sc->xlockof; - else + } + else { vpd->vec = &sc->xof; + } copy_v2_v2(&vpd->xof, vpd->vec); copy_v2_v2(&vpd->xorig, &vpd->xof); @@ -569,8 +580,9 @@ static int view_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) delta = event->prevx - event->x + event->prevy - event->y; - if (U.uiflag & USER_ZOOM_INVERT) + if (U.uiflag & USER_ZOOM_INVERT) { delta *= -1; + } factor = 1.0f + delta / 300.0f; RNA_float_set(op->ptr, "factor", factor); @@ -879,8 +891,9 @@ static int view_all_exec(bContext *C, wmOperator *op) /* find the zoom value that will fit the image in the image space */ sclip_zoom_set(C, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL); } - else + else { sclip_zoom_set(C, 1.0f, NULL); + } } sc->xof = sc->yof = 0.0f; @@ -941,8 +954,9 @@ void CLIP_OT_view_selected(wmOperatorType *ot) static bool change_frame_poll(bContext *C) { /* prevent changes during render */ - if (G.is_rendering) + if (G.is_rendering) { return 0; + } return ED_space_clip_poll(C); } @@ -995,8 +1009,9 @@ static int change_frame_invoke(bContext *C, wmOperator *op, const wmEvent *event ARegion *ar = CTX_wm_region(C); if (ar->regiontype == RGN_TYPE_WINDOW) { - if (event->mval[1] > 16) + if (event->mval[1] > 16) { return OPERATOR_PASS_THROUGH; + } } RNA_int_set(op->ptr, "frame", frame_from_event(C, event)); @@ -1022,8 +1037,9 @@ static int change_frame_modal(bContext *C, wmOperator *op, const wmEvent *event) case LEFTMOUSE: case RIGHTMOUSE: - if (event->val == KM_RELEASE) + if (event->val == KM_RELEASE) { return OPERATOR_FINISHED; + } break; } @@ -1079,17 +1095,21 @@ static int proxy_bitflag_to_array(int size_flag, int build_sizes[4], int undisto MCLIP_PROXY_UNDISTORTED_SIZE_100}}; int size_nr = undistort ? 1 : 0; - if (size_flag & size_flags[size_nr][0]) + if (size_flag & size_flags[size_nr][0]) { build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_25; + } - if (size_flag & size_flags[size_nr][1]) + if (size_flag & size_flags[size_nr][1]) { build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_50; + } - if (size_flag & size_flags[size_nr][2]) + if (size_flag & size_flags[size_nr][2]) { build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_75; + } - if (size_flag & size_flags[size_nr][3]) + if (size_flag & size_flags[size_nr][3]) { build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_100; + } return build_count; } @@ -1110,12 +1130,14 @@ static void do_movie_proxy(void *pjv, struct MovieDistortion *distortion = NULL; int cfra, sfra = SFRA, efra = EFRA; - if (pj->index_context) + if (pj->index_context) { IMB_anim_index_rebuild(pj->index_context, stop, do_update, progress); + } if (!build_undistort_count) { - if (*stop) + if (*stop) { pj->stop = 1; + } return; } @@ -1138,18 +1160,21 @@ static void do_movie_proxy(void *pjv, BKE_movieclip_build_proxy_frame( clip, pj->clip_flag, distortion, cfra, build_undistort_sizes, build_undistort_count, 1); - if (*stop || G.is_break) + if (*stop || G.is_break) { break; + } *do_update = true; *progress = ((float)cfra - sfra) / (efra - sfra); } - if (distortion) + if (distortion) { BKE_tracking_distortion_free(distortion); + } - if (*stop) + if (*stop) { pj->stop = 1; + } } /* ***** @@ -1371,11 +1396,13 @@ static void proxy_endjob(void *pjv) { ProxyJob *pj = pjv; - if (pj->clip->anim) + if (pj->clip->anim) { IMB_close_anim_proxies(pj->clip->anim); + } - if (pj->index_context) + if (pj->index_context) { IMB_anim_index_rebuild_finish(pj->index_context, pj->stop); + } if (pj->clip->source == MCLIP_SRC_MOVIE) { /* Timecode might have changed, so do a full reload to deal with this. */ @@ -1398,8 +1425,9 @@ static int clip_rebuild_proxy_exec(bContext *C, wmOperator *UNUSED(op)) SpaceClip *sc = CTX_wm_space_clip(C); MovieClip *clip = ED_space_clip_get_clip(sc); - if ((clip->flag & MCLIP_USE_PROXY) == 0) + if ((clip->flag & MCLIP_USE_PROXY) == 0) { return OPERATOR_CANCELLED; + } wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), @@ -1491,8 +1519,9 @@ void CLIP_OT_mode_set(wmOperatorType *ot) static int clip_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) { - if (event->type != NDOF_MOTION) + if (event->type != NDOF_MOTION) { return OPERATOR_CANCELLED; + } else { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); @@ -1534,8 +1563,9 @@ void CLIP_OT_view_ndof(wmOperatorType *ot) static int clip_prefetch_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) { /* no running blender, remove handler and pass through */ - if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_wm_area(C), WM_JOB_TYPE_CLIP_PREFETCH)) + if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_wm_area(C), WM_JOB_TYPE_CLIP_PREFETCH)) { return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; + } /* running render */ switch (event->type) { @@ -1577,8 +1607,9 @@ static int clip_set_scene_frames_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene = CTX_data_scene(C); int clip_length; - if (ELEM(NULL, scene, clip)) + if (ELEM(NULL, scene, clip)) { return OPERATOR_CANCELLED; + } clip_length = BKE_movieclip_get_duration(clip); diff --git a/source/blender/editors/space_clip/clip_toolbar.c b/source/blender/editors/space_clip/clip_toolbar.c index acb05e7d542..fb0362fffd3 100644 --- a/source/blender/editors/space_clip/clip_toolbar.c +++ b/source/blender/editors/space_clip/clip_toolbar.c @@ -58,15 +58,17 @@ ARegion *ED_clip_has_properties_region(ScrArea *sa) ARegion *ar, *arnew; ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); - if (ar) + if (ar) { return ar; + } /* add subdiv level; after header */ ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); /* is error! */ - if (ar == NULL) + if (ar == NULL) { return NULL; + } arnew = MEM_callocN(sizeof(ARegion), "clip properties region"); @@ -78,95 +80,3 @@ ARegion *ED_clip_has_properties_region(ScrArea *sa) return arnew; } - -static bool properties_poll(bContext *C) -{ - return (CTX_wm_space_clip(C) != NULL); -} - -static int properties_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = ED_clip_has_properties_region(sa); - - if (ar && ar->alignment != RGN_ALIGN_NONE) - ED_region_toggle_hidden(C, ar); - - return OPERATOR_FINISHED; -} - -void CLIP_OT_properties(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Toggle Sidebar"; - ot->description = "Toggle the properties region visibility"; - ot->idname = "CLIP_OT_properties"; - - /* api callbacks */ - ot->exec = properties_exec; - ot->poll = properties_poll; -} - -/************************** tools ******************************/ - -static ARegion *clip_has_tools_region(ScrArea *sa) -{ - ARegion *ar, *artool = NULL, *arhead; - - for (ar = sa->regionbase.first; ar; ar = ar->next) { - if (ar->regiontype == RGN_TYPE_TOOLS) - artool = ar; - } - - /* tool region hide/unhide also hides props */ - if (artool) { - return artool; - } - - if (artool == NULL) { - /* add subdiv level; after header */ - arhead = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); - - /* is error! */ - if (arhead == NULL) - return NULL; - - artool = MEM_callocN(sizeof(ARegion), "clip tools region"); - - BLI_insertlinkafter(&sa->regionbase, arhead, artool); - artool->regiontype = RGN_TYPE_TOOLS; - artool->alignment = RGN_ALIGN_LEFT; - - artool->flag = RGN_FLAG_HIDDEN; - } - - return artool; -} - -static bool tools_poll(bContext *C) -{ - return (CTX_wm_space_clip(C) != NULL); -} - -static int tools_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = clip_has_tools_region(sa); - - if (ar && ar->alignment != RGN_ALIGN_NONE) - ED_region_toggle_hidden(C, ar); - - return OPERATOR_FINISHED; -} - -void CLIP_OT_tools(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Toggle Toolbar"; - ot->description = "Toggle clip tools panel"; - ot->idname = "CLIP_OT_tools"; - - /* api callbacks */ - ot->exec = tools_exec; - ot->poll = tools_poll; -} diff --git a/source/blender/editors/space_clip/clip_utils.c b/source/blender/editors/space_clip/clip_utils.c index 37a28e6189a..3dfe529f8e8 100644 --- a/source/blender/editors/space_clip/clip_utils.c +++ b/source/blender/editors/space_clip/clip_utils.c @@ -81,8 +81,9 @@ void clip_graph_tracking_values_iterate_track( if (marker->flag & MARKER_DISABLED) { if (open) { - if (segment_end) + if (segment_end) { segment_end(userdata, coord); + } open = false; } @@ -119,8 +120,9 @@ void clip_graph_tracking_values_iterate_track( } if (open) { - if (segment_end) + if (segment_end) { segment_end(userdata, coord); + } } } } @@ -145,11 +147,13 @@ void clip_graph_tracking_values_iterate( MovieTrackingTrack *track; for (track = tracksbase->first; track; track = track->next) { - if (!include_hidden && (track->flag & TRACK_HIDDEN) != 0) + if (!include_hidden && (track->flag & TRACK_HIDDEN) != 0) { continue; + } - if (selected_only && !TRACK_SELECTED(track)) + if (selected_only && !TRACK_SELECTED(track)) { continue; + } clip_graph_tracking_values_iterate_track( sc, track, userdata, func, segment_start, segment_end); @@ -170,20 +174,24 @@ void clip_graph_tracking_iterate(SpaceClip *sc, for (track = tracksbase->first; track; track = track->next) { int i; - if (!include_hidden && (track->flag & TRACK_HIDDEN) != 0) + if (!include_hidden && (track->flag & TRACK_HIDDEN) != 0) { continue; + } - if (selected_only && !TRACK_SELECTED(track)) + if (selected_only && !TRACK_SELECTED(track)) { continue; + } for (i = 0; i < track->markersnr; i++) { MovieTrackingMarker *marker = &track->markers[i]; - if (marker->flag & MARKER_DISABLED) + if (marker->flag & MARKER_DISABLED) { continue; + } - if (func) + if (func) { func(userdata, marker); + } } } } diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index 7c62af80a0f..542f99e49ee 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -136,12 +136,14 @@ static void reinit_preview_region(const bContext *C, ARegion *ar) SpaceClip *sc = CTX_wm_space_clip(C); if (sc->view == SC_VIEW_DOPESHEET) { - if ((ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL) == 0) + if ((ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL) == 0) { init_preview_region(scene, sa, sc, ar); + } } else { - if (ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL) + if (ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL) { init_preview_region(scene, sa, sc, ar); + } } } @@ -150,15 +152,17 @@ static ARegion *ED_clip_has_preview_region(const bContext *C, ScrArea *sa) ARegion *ar, *arnew; ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW); - if (ar) + if (ar) { return ar; + } /* add subdiv level; after header */ ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); /* is error! */ - if (ar == NULL) + if (ar == NULL) { return NULL; + } arnew = MEM_callocN(sizeof(ARegion), "clip preview region"); @@ -173,15 +177,17 @@ static ARegion *ED_clip_has_channels_region(ScrArea *sa) ARegion *ar, *arnew; ar = BKE_area_find_region_type(sa, RGN_TYPE_CHANNELS); - if (ar) + if (ar) { return ar; + } /* add subdiv level; after header */ ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW); /* is error! */ - if (ar == NULL) + if (ar == NULL) { return NULL; + } arnew = MEM_callocN(sizeof(ARegion), "clip channels region"); @@ -200,13 +206,15 @@ static void clip_scopes_tag_refresh(ScrArea *sa) SpaceClip *sc = (SpaceClip *)sa->spacedata.first; ARegion *ar; - if (sc->mode != SC_MODE_TRACKING) + if (sc->mode != SC_MODE_TRACKING) { return; + } /* only while properties are visible */ for (ar = sa->regionbase.first; ar; ar = ar->next) { - if (ar->regiontype == RGN_TYPE_UI && ar->flag & RGN_FLAG_HIDDEN) + if (ar->regiontype == RGN_TYPE_UI && ar->flag & RGN_FLAG_HIDDEN) { return; + } } sc->scopes.ok = false; @@ -296,11 +304,13 @@ static void clip_free(SpaceLink *sl) sc->clip = NULL; - if (sc->scopes.track_preview) + if (sc->scopes.track_preview) { IMB_freeImBuf(sc->scopes.track_preview); + } - if (sc->scopes.track_search) + if (sc->scopes.track_search) { IMB_freeImBuf(sc->scopes.track_search); + } } /* spacetype; init callback */ @@ -434,10 +444,6 @@ static void clip_operatortypes(void) WM_operatortype_append(CLIP_OT_set_scene_frames); WM_operatortype_append(CLIP_OT_cursor_set); - /* ** clip_toolbar.c ** */ - WM_operatortype_append(CLIP_OT_tools); - WM_operatortype_append(CLIP_OT_properties); - /* ** tracking_ops.c ** */ /* navigation */ @@ -569,13 +575,15 @@ static int clip_context(const bContext *C, const char *member, bContextDataResul return true; } else if (CTX_data_equals(member, "edit_movieclip")) { - if (sc->clip) + if (sc->clip) { CTX_data_id_pointer_set(result, &sc->clip->id); + } return true; } else if (CTX_data_equals(member, "edit_mask")) { - if (sc->mask_info.mask) + if (sc->mask_info.mask) { CTX_data_id_pointer_set(result, &sc->mask_info.mask->id); + } return true; } @@ -851,14 +859,14 @@ static void clip_main_region_init(wmWindowManager *wm, ARegion *ar) /* mask polls mode */ keymap = WM_keymap_ensure(wm->defaultconf, "Mask Editing", 0, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "Clip", SPACE_CLIP, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "Clip Editor", SPACE_CLIP, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } static void clip_main_region_draw(const bContext *C, ARegion *ar) @@ -872,8 +880,9 @@ static void clip_main_region_draw(const bContext *C, ARegion *ar) /* if tracking is in progress, we should synchronize framenr from clipuser * so latest tracked frame would be shown */ - if (clip && clip->tracking_context) + if (clip && clip->tracking_context) { BKE_autotrack_context_sync_user(clip->tracking_context, &sc->user); + } if (sc->flag & SC_LOCK_SELECTION) { ImBuf *tmpibuf = NULL; @@ -887,8 +896,9 @@ static void clip_main_region_draw(const bContext *C, ARegion *ar) sc->yof += sc->ylockof; } - if (tmpibuf) + if (tmpibuf) { IMB_freeImBuf(tmpibuf); + } } /* clear and setup matrix */ @@ -972,10 +982,12 @@ static void clip_main_region_listener(wmWindow *UNUSED(win), /* context changes */ switch (wmn->category) { case NC_GPENCIL: - if (wmn->action == NA_EDITED) + if (wmn->action == NA_EDITED) { ED_region_tag_redraw(ar); - else if (wmn->data & ND_GPENCIL_EDITMODE) + } + else if (wmn->data & ND_GPENCIL_EDITMODE) { ED_region_tag_redraw(ar); + } break; } } @@ -990,13 +1002,13 @@ static void clip_preview_region_init(wmWindowManager *wm, ARegion *ar) /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "Clip", SPACE_CLIP, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "Clip Graph Editor", SPACE_CLIP, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "Clip Dopesheet Editor", SPACE_CLIP, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } static void graph_region_draw(const bContext *C, ARegion *ar) @@ -1005,11 +1017,11 @@ static void graph_region_draw(const bContext *C, ARegion *ar) View2DScrollers *scrollers; SpaceClip *sc = CTX_wm_space_clip(C); Scene *scene = CTX_data_scene(C); - short unitx, unity; short cfra_flag = 0; - if (sc->flag & SC_LOCK_TIMECURSOR) + if (sc->flag & SC_LOCK_TIMECURSOR) { ED_clip_graph_center_current_frame(scene, ar); + } /* clear and setup matrix */ UI_ThemeClearColor(TH_BACK); @@ -1021,24 +1033,28 @@ static void graph_region_draw(const bContext *C, ARegion *ar) clip_draw_graph(sc, ar, scene); /* current frame indicator line */ - if (sc->flag & SC_SHOW_SECONDS) + if (sc->flag & SC_SHOW_SECONDS) { cfra_flag |= DRAWCFRA_UNIT_SECONDS; + } ANIM_draw_cfra(C, v2d, cfra_flag); /* reset view matrix */ UI_view2d_view_restore(C); /* scrollers */ - unitx = (sc->flag & SC_SHOW_SECONDS) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES; - unity = V2D_UNIT_VALUES; - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP); - UI_view2d_scrollers_draw(C, v2d, scrollers); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); + /* scale indicators */ + UI_view2d_draw_scale_x__discrete_frames_or_seconds( + ar, v2d, &v2d->hor, scene, sc->flag & SC_SHOW_SECONDS); + UI_view2d_draw_scale_y__values(ar, v2d, &v2d->vert); + /* current frame indicator */ - if (sc->flag & SC_SHOW_SECONDS) + if (sc->flag & SC_SHOW_SECONDS) { cfra_flag |= DRAWCFRA_UNIT_SECONDS; + } UI_view2d_view_orthoSpecial(ar, v2d, 1); ANIM_draw_cfra_number(C, v2d, cfra_flag); } @@ -1049,12 +1065,12 @@ static void dopesheet_region_draw(const bContext *C, ARegion *ar) SpaceClip *sc = CTX_wm_space_clip(C); MovieClip *clip = ED_space_clip_get_clip(sc); View2D *v2d = &ar->v2d; - View2DGrid *grid; View2DScrollers *scrollers; - short unit = 0, cfra_flag = 0; + short cfra_flag = 0; - if (clip) + if (clip) { BKE_tracking_dopesheet_update(&clip->tracking); + } /* clear and setup matrix */ UI_ThemeClearColor(TH_BACK); @@ -1063,29 +1079,29 @@ static void dopesheet_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_ortho(v2d); /* time grid */ - unit = (sc->flag & SC_SHOW_SECONDS) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES; - grid = UI_view2d_grid_calc( - scene, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy); - UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL); - UI_view2d_grid_free(grid); + UI_view2d_draw_lines_x__discrete_frames_or_seconds(v2d, scene, sc->flag & SC_SHOW_SECONDS); /* data... */ clip_draw_dopesheet_main(sc, ar, scene); /* current frame indicator line */ - if (sc->flag & SC_SHOW_SECONDS) + if (sc->flag & SC_SHOW_SECONDS) { cfra_flag |= DRAWCFRA_UNIT_SECONDS; + } ANIM_draw_cfra(C, v2d, cfra_flag); /* reset view matrix */ UI_view2d_view_restore(C); /* scrollers */ - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY); - UI_view2d_scrollers_draw(C, v2d, scrollers); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); + /* frame numbers */ + UI_view2d_draw_scale_x__discrete_frames_or_seconds( + ar, v2d, &v2d->hor, scene, sc->flag & SC_SHOW_SECONDS); + /* current frame number indicator */ UI_view2d_view_orthoSpecial(ar, v2d, 1); ANIM_draw_cfra_number(C, v2d, cfra_flag); @@ -1095,10 +1111,12 @@ static void clip_preview_region_draw(const bContext *C, ARegion *ar) { SpaceClip *sc = CTX_wm_space_clip(C); - if (sc->view == SC_VIEW_GRAPH) + if (sc->view == SC_VIEW_GRAPH) { graph_region_draw(C, ar); - else if (sc->view == SC_VIEW_DOPESHEET) + } + else if (sc->view == SC_VIEW_DOPESHEET) { dopesheet_region_draw(C, ar); + } } static void clip_preview_region_listener(wmWindow *UNUSED(win), @@ -1121,7 +1139,7 @@ static void clip_channels_region_init(wmWindowManager *wm, ARegion *ar) UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy); keymap = WM_keymap_ensure(wm->defaultconf, "Clip Dopesheet Editor", SPACE_CLIP, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } static void clip_channels_region_draw(const bContext *C, ARegion *ar) @@ -1130,8 +1148,9 @@ static void clip_channels_region_draw(const bContext *C, ARegion *ar) MovieClip *clip = ED_space_clip_get_clip(sc); View2D *v2d = &ar->v2d; - if (clip) + if (clip) { BKE_tracking_dopesheet_update(&clip->tracking); + } /* clear and setup matrix */ UI_ThemeClearColor(TH_BACK); @@ -1219,20 +1238,24 @@ static void clip_props_region_listener(wmWindow *UNUSED(win), /* context changes */ switch (wmn->category) { case NC_WM: - if (wmn->data == ND_HISTORY) + if (wmn->data == ND_HISTORY) { ED_region_tag_redraw(ar); + } break; case NC_SCENE: - if (wmn->data == ND_MODE) + if (wmn->data == ND_MODE) { ED_region_tag_redraw(ar); + } break; case NC_SPACE: - if (wmn->data == ND_SPACE_CLIP) + if (wmn->data == ND_SPACE_CLIP) { ED_region_tag_redraw(ar); + } break; case NC_GPENCIL: - if (wmn->action == NA_EDITED) + if (wmn->action == NA_EDITED) { ED_region_tag_redraw(ar); + } break; } } @@ -1268,12 +1291,14 @@ static void clip_properties_region_listener(wmWindow *UNUSED(win), /* context changes */ switch (wmn->category) { case NC_GPENCIL: - if (ELEM(wmn->data, ND_DATA, ND_GPENCIL_EDITMODE)) + if (ELEM(wmn->data, ND_DATA, ND_GPENCIL_EDITMODE)) { ED_region_tag_redraw(ar); + } break; case NC_BRUSH: - if (wmn->action == NA_EDITED) + if (wmn->action == NA_EDITED) { ED_region_tag_redraw(ar); + } break; } } diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index ce1ade80823..18d48b426e0 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -512,8 +512,9 @@ static bool slide_check_corners(float (*corners)[2]) float cross = 0.0f; float p[2] = {0.0f, 0.0f}; - if (!isect_point_quad_v2(p, corners[0], corners[1], corners[2], corners[3])) + if (!isect_point_quad_v2(p, corners[0], corners[1], corners[2], corners[3])) { return false; + } for (i = 0; i < 4; i++) { float v1[2], v2[2], cur_cross; @@ -562,8 +563,9 @@ MovieTrackingTrack *tracking_marker_check_slide( ED_space_clip_get_size(sc, &width, &height); - if (width == 0 || height == 0) + if (width == 0 || height == 0) { return NULL; + } ED_clip_mouse_pos(sc, ar, event->mval, co); diff --git a/source/blender/editors/space_clip/tracking_ops_detect.c b/source/blender/editors/space_clip/tracking_ops_detect.c index ead150bba7f..a9c97258def 100644 --- a/source/blender/editors/space_clip/tracking_ops_detect.c +++ b/source/blender/editors/space_clip/tracking_ops_detect.c @@ -90,7 +90,7 @@ static int detect_features_exec(bContext *C, wmOperator *op) } /* Deselect existing tracks. */ - ed_tracking_delect_all_tracks(tracksbase); + ed_tracking_deselect_all_tracks(tracksbase); /* Run detector. */ BKE_tracking_detect_harris(tracking, tracksbase, diff --git a/source/blender/editors/space_clip/tracking_ops_intern.h b/source/blender/editors/space_clip/tracking_ops_intern.h index 8d2d61f050e..c29a485e234 100644 --- a/source/blender/editors/space_clip/tracking_ops_intern.h +++ b/source/blender/editors/space_clip/tracking_ops_intern.h @@ -38,7 +38,7 @@ void clip_tracking_hide_cursor(struct bContext *C); /* tracking_select.h */ -void ed_tracking_delect_all_tracks(struct ListBase *tracks_base); -void ed_tracking_delect_all_plane_tracks(struct ListBase *plane_tracks_base); +void ed_tracking_deselect_all_tracks(struct ListBase *tracks_base); +void ed_tracking_deselect_all_plane_tracks(struct ListBase *plane_tracks_base); #endif /* __TRACKING_OPS_INTERN_H__ */ diff --git a/source/blender/editors/space_clip/tracking_ops_orient.c b/source/blender/editors/space_clip/tracking_ops_orient.c index e13598b0322..61991993b10 100644 --- a/source/blender/editors/space_clip/tracking_ops_orient.c +++ b/source/blender/editors/space_clip/tracking_ops_orient.c @@ -399,10 +399,12 @@ static int set_plane_exec(bContext *C, wmOperator *op) int tot = 0; float vec[3][3], mat[4][4], obmat[4][4], newmat[4][4], orig[3] = {0.0f, 0.0f, 0.0f}; int plane = RNA_enum_get(op->ptr, "plane"); - float rot[4][4] = {{0.0f, 0.0f, -1.0f, 0.0f}, - {0.0f, 1.0f, 0.0f, 0.0f}, - {1.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 1.0f}}; /* 90 degrees Y-axis rotation matrix */ + float rot[4][4] = { + {0.0f, 0.0f, -1.0f, 0.0f}, + {0.0f, 1.0f, 0.0f, 0.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 1.0f}, + }; /* 90 degrees Y-axis rotation matrix */ if (count_selected_bundles(C) != 3) { BKE_report(op->reports, RPT_ERROR, "Three tracks with bundles are needed to orient the floor"); @@ -677,8 +679,9 @@ static int do_set_scale(bContext *C, wmOperator *op, bool scale_solution, bool a DEG_id_tag_update(&clip->id, 0); - if (object) + if (object) { DEG_id_tag_update(&object->id, ID_RECALC_TRANSFORM); + } WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip); WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); @@ -698,8 +701,9 @@ static int set_scale_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(e SpaceClip *sc = CTX_wm_space_clip(C); MovieClip *clip = ED_space_clip_get_clip(sc); - if (!RNA_struct_property_is_set(op->ptr, "distance")) + if (!RNA_struct_property_is_set(op->ptr, "distance")) { RNA_float_set(op->ptr, "distance", clip->tracking.settings.dist); + } return set_scale_exec(C, op); } diff --git a/source/blender/editors/space_clip/tracking_ops_plane.c b/source/blender/editors/space_clip/tracking_ops_plane.c index 238410da5e1..fc6a9ee1478 100644 --- a/source/blender/editors/space_clip/tracking_ops_plane.c +++ b/source/blender/editors/space_clip/tracking_ops_plane.c @@ -293,19 +293,19 @@ static int slide_plane_marker_modal(bContext *C, wmOperator *op, const wmEvent * data->corner[1] = data->previous_corner[1] + dy; /* - prev_edge - (Corner 3, current) <----------------------- (Corner 2, previous) - | ^ - | | - | | - | | - next_edge | | next_diag_edge - | | - | | - | | - v | - (Corner 0, next) -----------------------> (Corner 1, diagonal) - prev_diag_edge + * prev_edge + * (Corner 3, current) <----------------------- (Corner 2, previous) + * | ^ + * | | + * | | + * | | + * next_edge | | next_diag_edge + * | | + * | | + * | | + * v | + * (Corner 0, next) -----------------------> (Corner 1, diagonal) + * prev_diag_edge */ next_corner_index = (data->corner_index + 1) % 4; diff --git a/source/blender/editors/space_clip/tracking_ops_solve.c b/source/blender/editors/space_clip/tracking_ops_solve.c index ca57b3ea57f..4490655393e 100644 --- a/source/blender/editors/space_clip/tracking_ops_solve.c +++ b/source/blender/editors/space_clip/tracking_ops_solve.c @@ -239,8 +239,9 @@ static int solve_camera_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE static int solve_camera_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) { /* No running solver, remove handler and pass through. */ - if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_wm_area(C), WM_JOB_TYPE_ANY)) + if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_wm_area(C), WM_JOB_TYPE_ANY)) { return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; + } /* Running solver. */ switch (event->type) { diff --git a/source/blender/editors/space_clip/tracking_ops_track.c b/source/blender/editors/space_clip/tracking_ops_track.c index d985e82fd1a..e7880331331 100644 --- a/source/blender/editors/space_clip/tracking_ops_track.c +++ b/source/blender/editors/space_clip/tracking_ops_track.c @@ -55,7 +55,7 @@ typedef struct TrackMarkersJob { int backwards; /* Backwards tracking flag */ MovieClip *clip; /* Clip which is tracking */ float delay; /* Delay in milliseconds to allow - * tracking at fixed FPS */ + * tracking at fixed FPS */ struct Main *main; struct Scene *scene; diff --git a/source/blender/editors/space_clip/tracking_select.c b/source/blender/editors/space_clip/tracking_select.c index 24282ce0e96..2b70aec02bb 100644 --- a/source/blender/editors/space_clip/tracking_select.c +++ b/source/blender/editors/space_clip/tracking_select.c @@ -58,11 +58,13 @@ static float dist_to_crns(float co[2], float pos[2], float crns[4][2]); static int mouse_on_side( float co[2], float x1, float y1, float x2, float y2, float epsx, float epsy) { - if (x1 > x2) + if (x1 > x2) { SWAP(float, x1, x2); + } - if (y1 > y2) + if (y1 > y2) { SWAP(float, y1, y2); + } return (co[0] >= x1 - epsx && co[0] <= x2 + epsx) && (co[1] >= y1 - epsy && co[1] <= y2 + epsy); } @@ -115,14 +117,17 @@ static int track_mouse_area(const bContext *C, float co[2], MovieTrackingTrack * epsy = max_ff(epsy, 2.0f / height); if (sc->flag & SC_SHOW_MARKER_SEARCH) { - if (mouse_on_rect(co, marker->pos, marker->search_min, marker->search_max, epsx, epsy)) + if (mouse_on_rect(co, marker->pos, marker->search_min, marker->search_max, epsx, epsy)) { return TRACK_AREA_SEARCH; + } } if ((marker->flag & MARKER_DISABLED) == 0) { - if (sc->flag & SC_SHOW_MARKER_PATTERN) - if (mouse_on_crns(co, marker->pos, marker->pattern_corners, epsx, epsy)) + if (sc->flag & SC_SHOW_MARKER_PATTERN) { + if (mouse_on_crns(co, marker->pos, marker->pattern_corners, epsx, epsy)) { return TRACK_AREA_PAT; + } + } epsx = 12.0f / width; epsy = 12.0f / height; @@ -204,12 +209,14 @@ static MovieTrackingTrack *find_nearest_track(SpaceClip *sc, (co[1] - marker->pos[1] - cur->offset[1]) * (co[1] - marker->pos[1] - cur->offset[1])); /* distance to pattern boundbox */ - if (sc->flag & SC_SHOW_MARKER_PATTERN) + if (sc->flag & SC_SHOW_MARKER_PATTERN) { d2 = dist_to_crns(co, marker->pos, marker->pattern_corners); + } /* distance to search boundbox */ - if (sc->flag & SC_SHOW_MARKER_SEARCH && TRACK_VIEW_SELECTED(sc, cur)) + if (sc->flag & SC_SHOW_MARKER_SEARCH && TRACK_VIEW_SELECTED(sc, cur)) { d3 = dist_to_rect(co, marker->pos, marker->search_min, marker->search_max); + } /* choose minimal distance. useful for cases of overlapped markers. */ dist = min_fff(d1, d2, d3); @@ -256,7 +263,7 @@ static MovieTrackingPlaneTrack *find_nearest_plane_track(SpaceClip *sc, return plane_track; } -void ed_tracking_delect_all_tracks(ListBase *tracks_base) +void ed_tracking_deselect_all_tracks(ListBase *tracks_base) { MovieTrackingTrack *track; for (track = tracks_base->first; track != NULL; track = track->next) { @@ -264,7 +271,7 @@ void ed_tracking_delect_all_tracks(ListBase *tracks_base) } } -void ed_tracking_delect_all_plane_tracks(ListBase *plane_tracks_base) +void ed_tracking_deselect_all_plane_tracks(ListBase *plane_tracks_base) { MovieTrackingPlaneTrack *plane_track; for (plane_track = plane_tracks_base->first; plane_track != NULL; @@ -273,7 +280,7 @@ void ed_tracking_delect_all_plane_tracks(ListBase *plane_tracks_base) } } -static int mouse_select(bContext *C, float co[2], int extend) +static int mouse_select(bContext *C, float co[2], const bool extend, const bool deselect_all) { SpaceClip *sc = CTX_wm_space_clip(C); MovieClip *clip = ED_space_clip_get_clip(sc); @@ -288,6 +295,15 @@ static int mouse_select(bContext *C, float co[2], int extend) track = find_nearest_track(sc, tracksbase, co, &distance_to_track); plane_track = find_nearest_plane_track(sc, plane_tracks_base, co, &distance_to_plane_track); + /* Do not select beyond some reasonable distance, that is useless and + * prevents the 'deselect on nothing' behavior. */ + if (distance_to_track > 0.05f) { + track = NULL; + } + if (distance_to_plane_track > 0.05f) { + plane_track = NULL; + } + /* Between track and plane we choose closest to the mouse for selection here. */ if (track && plane_track) { if (distance_to_track < distance_to_plane_track) { @@ -298,15 +314,16 @@ static int mouse_select(bContext *C, float co[2], int extend) } } - if (!extend) { - ed_tracking_delect_all_plane_tracks(plane_tracks_base); - } - if (track) { + if (!extend) { + ed_tracking_deselect_all_plane_tracks(plane_tracks_base); + } + int area = track_mouse_area(C, co, track); - if (!extend || !TRACK_VIEW_SELECTED(sc, track)) + if (!extend || !TRACK_VIEW_SELECTED(sc, track)) { area = TRACK_AREA_ALL; + } if (extend && TRACK_AREA_SELECTED(track, area)) { if (track == act_track) { @@ -318,8 +335,9 @@ static int mouse_select(bContext *C, float co[2], int extend) } } else { - if (area == TRACK_AREA_POINT) + if (area == TRACK_AREA_POINT) { area = TRACK_AREA_ALL; + } BKE_tracking_track_select(tracksbase, track, area, extend); clip->tracking.act_track = track; @@ -328,7 +346,7 @@ static int mouse_select(bContext *C, float co[2], int extend) } else if (plane_track) { if (!extend) { - ed_tracking_delect_all_tracks(tracksbase); + ed_tracking_deselect_all_tracks(tracksbase); } if (PLANE_TRACK_VIEW_SELECTED(plane_track)) { @@ -343,6 +361,10 @@ static int mouse_select(bContext *C, float co[2], int extend) clip->tracking.act_track = NULL; clip->tracking.act_plane_track = plane_track; } + else if (deselect_all) { + ed_tracking_deselect_all_tracks(tracksbase); + ed_tracking_deselect_all_plane_tracks(plane_tracks_base); + } if (!extend) { sc->xlockof = 0.0f; @@ -371,12 +393,12 @@ static bool select_poll(bContext *C) static int select_exec(bContext *C, wmOperator *op) { float co[2]; - int extend; RNA_float_get_array(op->ptr, "location", co); - extend = RNA_boolean_get(op->ptr, "extend"); + const bool extend = RNA_boolean_get(op->ptr, "extend"); + const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all"); - return mouse_select(C, co, extend); + return mouse_select(C, co, extend, deselect_all); } static int select_invoke(bContext *C, wmOperator *op, const wmEvent *event) @@ -424,11 +446,19 @@ void CLIP_OT_select(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; /* properties */ + PropertyRNA *prop; RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection rather than clearing the existing selection"); + prop = RNA_def_boolean(ot->srna, + "deselect_all", + false, + "Deselect On Nothing", + "Deselect all when nothing under the cursor"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + RNA_def_float_vector( ot->srna, "location", @@ -584,10 +614,12 @@ static int do_lasso_select_marker(bContext *C, if (BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) && BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], V2D_IS_CLIPPED)) { - if (select) + if (select) { BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT); - else + } + else { BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT); + } } changed = true; @@ -820,8 +852,9 @@ static int select_all_exec(bContext *C, wmOperator *op) ED_clip_select_all(sc, action, &has_selection); - if (!has_selection) + if (!has_selection) { sc->flag &= ~SC_LOCK_SELECTION; + } BKE_tracking_dopesheet_tag_update(tracking); @@ -888,8 +921,9 @@ static int select_grouped_exec(bContext *C, wmOperator *op) if (act_track) { ok = (track->flag & TRACK_CUSTOMCOLOR) == (act_track->flag & TRACK_CUSTOMCOLOR); - if (ok && track->flag & TRACK_CUSTOMCOLOR) + if (ok && track->flag & TRACK_CUSTOMCOLOR) { ok = equals_v3v3(track->color, act_track->color); + } } } else if (group == 6) { /* failed */ @@ -898,10 +932,12 @@ static int select_grouped_exec(bContext *C, wmOperator *op) if (ok) { track->flag |= SELECT; - if (sc->flag & SC_SHOW_MARKER_PATTERN) + if (sc->flag & SC_SHOW_MARKER_PATTERN) { track->pat_flag |= SELECT; - if (sc->flag & SC_SHOW_MARKER_SEARCH) + } + if (sc->flag & SC_SHOW_MARKER_SEARCH) { track->search_flag |= SELECT; + } } track = track->next; diff --git a/source/blender/editors/space_console/CMakeLists.txt b/source/blender/editors/space_console/CMakeLists.txt index 5070b6fcf65..33934832ccc 100644 --- a/source/blender/editors/space_console/CMakeLists.txt +++ b/source/blender/editors/space_console/CMakeLists.txt @@ -24,8 +24,8 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c index a17c1b675e6..1fc218c9461 100644 --- a/source/blender/editors/space_console/console_ops.c +++ b/source/blender/editors/space_console/console_ops.c @@ -144,14 +144,12 @@ static void console_lb_debug__internal(ListBase *lb) for (cl = lb->first; cl; cl = cl->next) printf("<%s> ", cl->line); printf("\n"); - } static void console_history_debug(const bContext *C) { SpaceConsole *sc = CTX_wm_space_console(C); - console_lb_debug__internal(&sc->history); } #endif diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c index 2cf8f6c46b9..999255aef88 100644 --- a/source/blender/editors/space_console/space_console.c +++ b/source/blender/editors/space_console/space_console.c @@ -77,7 +77,7 @@ static SpaceLink *console_new(const ScrArea *UNUSED(area), const Scene *UNUSED(s ar->v2d.minzoom = ar->v2d.maxzoom = 1.0f; /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */ - //ar->v2d.keepzoom = (V2D_KEEPASPECT|V2D_LIMITZOOM); + // ar->v2d.keepzoom = (V2D_KEEPASPECT|V2D_LIMITZOOM); return (SpaceLink *)sconsole; } @@ -136,7 +136,7 @@ static void console_main_region_init(wmWindowManager *wm, ARegion *ar) /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "Console", SPACE_CONSOLE, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); /* add drop boxes */ lb = WM_dropboxmap_find("Console", SPACE_CONSOLE, RGN_TYPE_WINDOW); @@ -231,9 +231,8 @@ static void console_main_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); /* scrollers */ - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_GRID_CLAMP); - UI_view2d_scrollers_draw(C, v2d, scrollers); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); } diff --git a/source/blender/editors/space_file/CMakeLists.txt b/source/blender/editors/space_file/CMakeLists.txt index 6bf975b98e0..33f57b9c235 100644 --- a/source/blender/editors/space_file/CMakeLists.txt +++ b/source/blender/editors/space_file/CMakeLists.txt @@ -22,15 +22,15 @@ set(INC ../../blenlib ../../blenloader ../../blentranslation - ../../imbuf ../../gpu + ../../imbuf ../../makesdna ../../makesrna ../../render/extern/include ../../windowmanager ../../../../intern/atomic - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 87560436d52..bb8680682d2 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -193,8 +193,9 @@ void file_draw_buttons(const bContext *C, ARegion *ar) /* TODO, directory editing is non-functional while a library is loaded * until this is properly supported just disable it. */ - if (sfile->files && filelist_lib(sfile->files)) + if (sfile->files && filelist_lib(sfile->files)) { UI_but_flag_enable(but, UI_BUT_DISABLED); + } if ((params->flag & FILE_DIRSEL_ONLY) == 0) { but = uiDefBut( @@ -660,8 +661,9 @@ void file_draw_list(const bContext *C, ARegion *ar) } offset = ED_fileselect_layout_offset(layout, (int)ar->v2d.cur.xmin, (int)-ar->v2d.cur.ymax); - if (offset < 0) + if (offset < 0) { offset = 0; + } numfiles_layout = ED_fileselect_layout_numfiles(layout, ar); @@ -689,7 +691,8 @@ void file_draw_list(const bContext *C, ARegion *ar) filelist_cache_previews_update(files); - /* Handle preview timer here, since it's filelist_file_cache_block() and filelist_cache_previews_update() + /* Handle preview timer here, + * since it's filelist_file_cache_block() and filelist_cache_previews_update() * which controls previews task. */ { const bool previews_running = filelist_cache_previews_running(files); diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 073b6d0f487..674735f3e1d 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -119,8 +119,9 @@ static void clamp_to_filelist(int numfiles, FileSelection *sel) } /* fix if last file invalid */ - if ((sel->first > 0) && (sel->last < 0)) + if ((sel->first > 0) && (sel->last < 0)) { sel->last = numfiles - 1; + } /* clamp */ if ((sel->first >= numfiles)) { @@ -148,8 +149,9 @@ static FileSelection file_selection_get(bContext *C, const rcti *rect, bool fill int f; /* Try to find a smaller-index selected item. */ for (f = sel.last; f >= 0; f--) { - if (filelist_entry_select_index_get(sfile->files, f, CHECK_ALL)) + if (filelist_entry_select_index_get(sfile->files, f, CHECK_ALL)) { break; + } } if (f >= 0) { sel.first = f + 1; @@ -157,8 +159,9 @@ static FileSelection file_selection_get(bContext *C, const rcti *rect, bool fill /* If none found, try to find a higher-index selected item. */ else { for (f = sel.first; f < numfiles; f++) { - if (filelist_entry_select_index_get(sfile->files, f, CHECK_ALL)) + if (filelist_entry_select_index_get(sfile->files, f, CHECK_ALL)) { break; + } } if (f < numfiles) { sel.last = f - 1; @@ -298,8 +301,9 @@ static FileSelect file_select( sfile->files, &sel, select, FILE_SEL_SELECTED, check_type); /* Don't act on multiple selected files */ - if (sel.first != sel.last) + if (sel.first != sel.last) { select = 0; + } /* Do we have a valid selection and are we actually selecting */ if ((sel.last >= 0) && (select != FILE_SEL_REMOVE)) { @@ -482,14 +486,16 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) const bool fill = RNA_boolean_get(op->ptr, "fill"); const bool do_diropen = RNA_boolean_get(op->ptr, "open"); - if (ar->regiontype != RGN_TYPE_WINDOW) + if (ar->regiontype != RGN_TYPE_WINDOW) { return OPERATOR_CANCELLED; + } rect.xmin = rect.xmax = event->mval[0]; rect.ymin = rect.ymax = event->mval[1]; - if (!BLI_rcti_isect_pt(&ar->v2d.mask, rect.xmin, rect.ymin)) + if (!BLI_rcti_isect_pt(&ar->v2d.mask, rect.xmin, rect.ymin)) { return OPERATOR_CANCELLED; + } if (sfile && sfile->params) { int idx = sfile->params->highlight_file; @@ -512,10 +518,12 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) sfile->files, 0, FILE_SEL_REMOVE, FILE_SEL_SELECTED, CHECK_ALL); } - if (FILE_SELECT_DIR == ret) + if (FILE_SELECT_DIR == ret) { WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); - else if (FILE_SELECT_FILE == ret) + } + else if (FILE_SELECT_FILE == ret) { WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); + } WM_event_add_mousemove(C); /* for directory changes */ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); @@ -1149,8 +1157,9 @@ int file_highlight_set(SpaceFile *sfile, ARegion *ar, int mx, int my) FileSelectParams *params; int numfiles, origfile; - if (sfile == NULL || sfile->files == NULL) + if (sfile == NULL || sfile->files == NULL) { return 0; + } numfiles = filelist_files_ensure(sfile->files); params = ED_fileselect_get_params(sfile); @@ -1169,13 +1178,16 @@ int file_highlight_set(SpaceFile *sfile, ARegion *ar, int mx, int my) highlight_file = ED_fileselect_layout_offset( sfile->layout, (int)(v2d->tot.xmin + fx), (int)(v2d->tot.ymax - fy)); - if ((highlight_file >= 0) && (highlight_file < numfiles)) + if ((highlight_file >= 0) && (highlight_file < numfiles)) { params->highlight_file = highlight_file; - else + } + else { params->highlight_file = -1; + } } - else + else { params->highlight_file = -1; + } return (params->highlight_file != origfile); } @@ -1185,8 +1197,9 @@ static int file_highlight_invoke(bContext *C, wmOperator *UNUSED(op), const wmEv ARegion *ar = CTX_wm_region(C); SpaceFile *sfile = CTX_wm_space_file(C); - if (!file_highlight_set(sfile, ar, event->x, event->y)) + if (!file_highlight_set(sfile, ar, event->x, event->y)) { return OPERATOR_PASS_THROUGH; + } ED_area_tag_redraw(CTX_wm_area(C)); @@ -1223,8 +1236,9 @@ static bool file_operator_poll(bContext *C) bool poll = ED_operator_file_active(C); SpaceFile *sfile = CTX_wm_space_file(C); - if (!sfile || !sfile->op) + if (!sfile || !sfile->op) { poll = 0; + } return poll; } @@ -1447,8 +1461,7 @@ int file_exec(bContext *C, wmOperator *exec_op) else if (sfile->op) { wmOperator *op = sfile->op; - /* when used as a macro, for doubleclick, - * to prevent closing when doubleclicking on .. item */ + /* When used as a macro, for double-click, to prevent closing when double-clicking on item. */ if (RNA_boolean_get(exec_op->ptr, "need_active")) { const int numfiles = filelist_files_ensure(sfile->files); int i, active = 0; @@ -1459,8 +1472,9 @@ int file_exec(bContext *C, wmOperator *exec_op) break; } } - if (active == 0) + if (active == 0) { return OPERATOR_CANCELLED; + } } sfile->op = NULL; @@ -1575,8 +1589,9 @@ int file_previous_exec(bContext *C, wmOperator *UNUSED(unused)) SpaceFile *sfile = CTX_wm_space_file(C); if (sfile->params) { - if (!sfile->folders_next) + if (!sfile->folders_next) { sfile->folders_next = folderlist_new(); + } folderlist_pushdir(sfile->folders_next, sfile->params->dir); folderlist_popdir(sfile->folders_prev, sfile->params->dir); @@ -1605,8 +1620,9 @@ int file_next_exec(bContext *C, wmOperator *UNUSED(unused)) { SpaceFile *sfile = CTX_wm_space_file(C); if (sfile->params) { - if (!sfile->folders_next) + if (!sfile->folders_next) { sfile->folders_next = folderlist_new(); + } folderlist_pushdir(sfile->folders_prev, sfile->params->dir); folderlist_popdir(sfile->folders_next, sfile->params->dir); @@ -1633,13 +1649,15 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w int i; /* escape if not our timer */ - if (sfile->smoothscroll_timer == NULL || sfile->smoothscroll_timer != event->customdata) + if (sfile->smoothscroll_timer == NULL || sfile->smoothscroll_timer != event->customdata) { return OPERATOR_PASS_THROUGH; + } numfiles = filelist_files_ensure(sfile->files); /* Due to async nature of file listing, we may execute this code before `file_refresh()` - * editing entry is available in our listing, so we also have to handle switching to rename mode here. */ + * editing entry is available in our listing, + * so we also have to handle switching to rename mode here. */ FileSelectParams *params = ED_fileselect_get_params(sfile); if ((params->rename_flag & (FILE_PARAMS_RENAME_PENDING | FILE_PARAMS_RENAME_POSTSCROLL_PENDING)) != 0) { @@ -1657,8 +1675,8 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w /* if we are not editing, we are done */ if (edit_idx == -1) { - /* Do not invalidate timer if filerename is still pending, we might still be building the filelist - * and yet have to find edited entry... */ + /* Do not invalidate timer if filerename is still pending, + * we might still be building the filelist and yet have to find edited entry. */ if (params->rename_flag == 0) { WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer); sfile->smoothscroll_timer = NULL; @@ -1682,19 +1700,21 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w if (sfile->scroll_offset == 0) { if (sfile->layout->flag & FILE_LAYOUT_HOR) { sfile->scroll_offset = (edit_idx / sfile->layout->rows) * sfile->layout->rows; - if (sfile->scroll_offset <= offset) + if (sfile->scroll_offset <= offset) { sfile->scroll_offset -= sfile->layout->rows; + } } else { sfile->scroll_offset = (edit_idx / sfile->layout->columns) * sfile->layout->columns; - if (sfile->scroll_offset <= offset) + if (sfile->scroll_offset <= offset) { sfile->scroll_offset -= sfile->layout->columns; + } } } numfiles_layout = ED_fileselect_layout_numfiles(sfile->layout, ar); - /* Using margins helps avoiding scrolling to stop when target item is barely visible on one side of the screen - * (i.e. it centers a bit more the target). */ + /* Using margins helps avoiding scrolling to stop when target item + * is barely visible on one side of the screen (i.e. it centers a bit more the target). */ int numfiles_layout_margin = max_ii(0, numfiles_layout / 3); /* check if we have reached our final scroll position */ @@ -1702,7 +1722,8 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w (sfile->scroll_offset < offset + numfiles_layout - numfiles_layout_margin)) { WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer); sfile->smoothscroll_timer = NULL; - /* Postscroll (after rename has been validated by user) is done, rename process is totally finisehd, cleanup. */ + /* Post-scroll (after rename has been validated by user) is done, + * rename process is totally finished, cleanup. */ if ((params->rename_flag & FILE_PARAMS_RENAME_POSTSCROLL_ACTIVE) != 0) { params->renamefile[0] = '\0'; params->rename_flag = 0; @@ -1791,8 +1812,10 @@ void FILE_OT_filepath_drop(wmOperatorType *ot) RNA_def_string_file_path(ot->srna, "filepath", "Path", FILE_MAX, "", ""); } -/* create a new, non-existing folder name, returns 1 if successful, 0 if name couldn't be created. - * The actual name is returned in 'name', 'folder' contains the complete path, including the new folder name. +/** + * Create a new, non-existing folder name, returns 1 if successful, 0 if name couldn't be created. + * The actual name is returned in 'name', 'folder' contains the complete path, + * including the new folder name. */ static int new_folder_path(const char *parent, char *folder, char *name) { @@ -2026,8 +2049,9 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN #if defined(WIN32) else if (!can_create_dir(sfile->params->dir)) { const char *lastdir = folderlist_peeklastdir(sfile->folders_prev); - if (lastdir) + if (lastdir) { BLI_strncpy(sfile->params->dir, lastdir, sizeof(sfile->params->dir)); + } } #endif else { @@ -2046,8 +2070,9 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN RNA_string_set(&ptr, "directory", sfile->params->dir); RNA_boolean_set(&ptr, "open", true); - if (lastdir) + if (lastdir) { BLI_strncpy(sfile->params->dir, lastdir, sizeof(sfile->params->dir)); + } WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr); WM_operator_properties_free(&ptr); @@ -2149,15 +2174,17 @@ ARegion *file_tools_region(ScrArea *sa) { ARegion *ar, *arnew; - if ((ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS)) != NULL) + if ((ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS)) != NULL) { return ar; + } /* add subdiv level; after header */ ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); /* is error! */ - if (ar == NULL) + if (ar == NULL) { return NULL; + } arnew = MEM_callocN(sizeof(ARegion), "tools for file"); BLI_insertlinkafter(&sa->regionbase, ar, arnew); @@ -2177,8 +2204,9 @@ static int file_bookmark_toggle_exec(bContext *C, wmOperator *UNUSED(unused)) ScrArea *sa = CTX_wm_area(C); ARegion *ar = file_tools_region(sa); - if (ar) + if (ar) { ED_region_toggle_hidden(C, ar); + } return OPERATOR_FINISHED; } @@ -2220,8 +2248,9 @@ static void filenum_newname(char *name, size_t name_size, int add) } pic += add; - if (pic < 0) + if (pic < 0) { pic = 0; + } BLI_stringenc(name_temp, head, tail, digits, pic); BLI_strncpy(name, name_temp, name_size); } @@ -2270,7 +2299,8 @@ static int file_rename_exec(bContext *C, wmOperator *UNUSED(op)) filelist_entry_select_index_set( sfile->files, idx, FILE_SEL_ADD, FILE_SEL_EDITING, CHECK_ALL); BLI_strncpy(sfile->params->renamefile, file->relpath, FILE_MAXFILE); - /* We can skip the pending state, as we can directly set FILE_SEL_EDITING on the expected entry here. */ + /* We can skip the pending state, + * as we can directly set FILE_SEL_EDITING on the expected entry here. */ sfile->params->rename_flag = FILE_PARAMS_RENAME_ACTIVE; } ED_area_tag_redraw(sa); @@ -2335,8 +2365,9 @@ static bool file_delete_poll(bContext *C) int i; int num_selected = 0; - if (filelist_islibrary(sfile->files, dir, NULL)) + if (filelist_islibrary(sfile->files, dir, NULL)) { poll = 0; + } for (i = 0; i < numfiles; i++) { if (filelist_entry_select_index_get(sfile->files, i, CHECK_FILES)) { num_selected++; @@ -2346,8 +2377,9 @@ static bool file_delete_poll(bContext *C) poll = 0; } } - else + else { poll = 0; + } return poll; } diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 31a59f06079..564dd0ec81d 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -139,8 +139,9 @@ const char *folderlist_peeklastdir(ListBase *folderlist) { struct FolderList *folder; - if (!folderlist->last) + if (!folderlist->last) { return NULL; + } folder = folderlist->last; return folder->foldername; @@ -151,14 +152,16 @@ int folderlist_clear_next(struct SpaceFile *sfile) struct FolderList *folder; /* if there is no folder_next there is nothing we can clear */ - if (!sfile->folders_next) + if (!sfile->folders_next) { return 0; + } /* if previous_folder, next_folder or refresh_folder operators are executed * it doesn't clear folder_next */ folder = sfile->folders_prev->last; - if ((!folder) || (BLI_path_cmp(folder->foldername, sfile->params->dir) == 0)) + if ((!folder) || (BLI_path_cmp(folder->foldername, sfile->params->dir) == 0)) { return 0; + } /* eventually clear flist->folders_next */ return 1; @@ -169,8 +172,9 @@ void folderlist_free(ListBase *folderlist) { if (folderlist) { FolderList *folder; - for (folder = folderlist->first; folder; folder = folder->next) + for (folder = folderlist->first; folder; folder = folder->next) { MEM_freeN(folder->foldername); + } BLI_freelistN(folderlist); } } @@ -293,9 +297,11 @@ typedef struct FileList { struct FileListEntryCache filelist_cache; - /* We need to keep those info outside of actual filelist items, because those are no more persistent + /* We need to keep those info outside of actual filelist items, + * because those are no more persistent * (only generated on demand, and freed as soon as possible). - * Persistent part (mere list of paths + stat info) is kept as small as possible, and filebrowser-agnostic. + * Persistent part (mere list of paths + stat info) + * is kept as small as possible, and filebrowser-agnostic. */ GHash *selection_state; @@ -304,7 +310,8 @@ typedef struct FileList { struct BlendHandle *libfiledata; - /* Set given path as root directory, if last bool is true may change given string in place to a valid value. + /* Set given path as root directory, + * if last bool is true may change given string in place to a valid value. * Returns True if valid dir. */ bool (*checkdirf)(struct FileList *, char *, const bool); @@ -397,14 +404,18 @@ static int compare_direntry_generic(const FileListInternEntry *entry1, } /* make sure "." and ".." are always first */ - if (FILENAME_IS_CURRENT(entry1->relpath)) + if (FILENAME_IS_CURRENT(entry1->relpath)) { return -1; - if (FILENAME_IS_CURRENT(entry2->relpath)) + } + if (FILENAME_IS_CURRENT(entry2->relpath)) { return 1; - if (FILENAME_IS_PARENT(entry1->relpath)) + } + if (FILENAME_IS_PARENT(entry1->relpath)) { return -1; - if (FILENAME_IS_PARENT(entry2->relpath)) + } + if (FILENAME_IS_PARENT(entry2->relpath)) { return 1; + } return 0; } @@ -440,10 +451,12 @@ static int compare_date(void *UNUSED(user_data), const void *a1, const void *a2) time1 = (int64_t)entry1->st.st_mtime; time2 = (int64_t)entry2->st.st_mtime; - if (time1 < time2) + if (time1 < time2) { return 1; - if (time1 > time2) + } + if (time1 > time2) { return -1; + } name1 = entry1->name; name2 = entry2->name; @@ -465,10 +478,12 @@ static int compare_size(void *UNUSED(user_data), const void *a1, const void *a2) size1 = entry1->st.st_size; size2 = entry2->st.st_size; - if (size1 < size2) + if (size1 < size2) { return 1; - if (size1 > size2) + } + if (size1 > size2) { return -1; + } name1 = entry1->name; name2 = entry2->name; @@ -487,31 +502,41 @@ static int compare_extension(void *UNUSED(user_data), const void *a1, const void return ret; } - if ((entry1->typeflag & FILE_TYPE_BLENDERLIB) && !(entry2->typeflag & FILE_TYPE_BLENDERLIB)) + if ((entry1->typeflag & FILE_TYPE_BLENDERLIB) && !(entry2->typeflag & FILE_TYPE_BLENDERLIB)) { return -1; - if (!(entry1->typeflag & FILE_TYPE_BLENDERLIB) && (entry2->typeflag & FILE_TYPE_BLENDERLIB)) + } + if (!(entry1->typeflag & FILE_TYPE_BLENDERLIB) && (entry2->typeflag & FILE_TYPE_BLENDERLIB)) { return 1; + } if ((entry1->typeflag & FILE_TYPE_BLENDERLIB) && (entry2->typeflag & FILE_TYPE_BLENDERLIB)) { - if ((entry1->typeflag & FILE_TYPE_DIR) && !(entry2->typeflag & FILE_TYPE_DIR)) + if ((entry1->typeflag & FILE_TYPE_DIR) && !(entry2->typeflag & FILE_TYPE_DIR)) { return 1; - if (!(entry1->typeflag & FILE_TYPE_DIR) && (entry2->typeflag & FILE_TYPE_DIR)) + } + if (!(entry1->typeflag & FILE_TYPE_DIR) && (entry2->typeflag & FILE_TYPE_DIR)) { return -1; - if (entry1->blentype < entry2->blentype) + } + if (entry1->blentype < entry2->blentype) { return -1; - if (entry1->blentype > entry2->blentype) + } + if (entry1->blentype > entry2->blentype) { return 1; + } } else { const char *sufix1, *sufix2; - if (!(sufix1 = strstr(entry1->relpath, ".blend.gz"))) + if (!(sufix1 = strstr(entry1->relpath, ".blend.gz"))) { sufix1 = strrchr(entry1->relpath, '.'); - if (!(sufix2 = strstr(entry2->relpath, ".blend.gz"))) + } + if (!(sufix2 = strstr(entry2->relpath, ".blend.gz"))) { sufix2 = strrchr(entry2->relpath, '.'); - if (!sufix1) + } + if (!sufix1) { sufix1 = ""; - if (!sufix2) + } + if (!sufix2) { sufix2 = ""; + } if ((ret = BLI_strcasecmp(sufix1, sufix2))) { return ret; @@ -951,28 +976,39 @@ static int filelist_geticon_ex(const int typeflag, } } - if (typeflag & FILE_TYPE_BLENDER) + if (typeflag & FILE_TYPE_BLENDER) { return ICON_FILE_BLEND; - else if (typeflag & FILE_TYPE_BLENDER_BACKUP) + } + else if (typeflag & FILE_TYPE_BLENDER_BACKUP) { return ICON_FILE_BACKUP; - else if (typeflag & FILE_TYPE_IMAGE) + } + else if (typeflag & FILE_TYPE_IMAGE) { return ICON_FILE_IMAGE; - else if (typeflag & FILE_TYPE_MOVIE) + } + else if (typeflag & FILE_TYPE_MOVIE) { return ICON_FILE_MOVIE; - else if (typeflag & FILE_TYPE_PYSCRIPT) + } + else if (typeflag & FILE_TYPE_PYSCRIPT) { return ICON_FILE_SCRIPT; - else if (typeflag & FILE_TYPE_SOUND) + } + else if (typeflag & FILE_TYPE_SOUND) { return ICON_FILE_SOUND; - else if (typeflag & FILE_TYPE_FTFONT) + } + else if (typeflag & FILE_TYPE_FTFONT) { return ICON_FILE_FONT; - else if (typeflag & FILE_TYPE_BTX) + } + else if (typeflag & FILE_TYPE_BTX) { return ICON_FILE_BLANK; - else if (typeflag & FILE_TYPE_COLLADA) + } + else if (typeflag & FILE_TYPE_COLLADA) { return ICON_FILE_BLANK; - else if (typeflag & FILE_TYPE_ALEMBIC) + } + else if (typeflag & FILE_TYPE_ALEMBIC) { return ICON_FILE_BLANK; - else if (typeflag & FILE_TYPE_TEXT) + } + else if (typeflag & FILE_TYPE_TEXT) { return ICON_FILE_TEXT; + } else if (typeflag & FILE_TYPE_BLENDERLIB) { const int ret = UI_idcode_icon_get(blentype); if (ret != ICON_NONE) { @@ -1177,8 +1213,8 @@ static void filelist_cache_preview_freef(TaskPool *__restrict UNUSED(pool), { FileListEntryPreview *preview = taskdata; - /* If preview->flag is empty, it means that preview has already been generated and added to done queue, - * we do not own it anymore. */ + /* If preview->flag is empty, it means that preview has already been generated and + * added to done queue, we do not own it anymore. */ if (preview->flags) { if (preview->img) { IMB_freeImBuf(preview->img); @@ -1207,7 +1243,7 @@ static void filelist_cache_previews_clear(FileListEntryCache *cache) BLI_task_pool_cancel(cache->previews_pool); while ((preview = BLI_thread_queue_pop_timeout(cache->previews_done, 0))) { - // printf("%s: DONE %d - %s - %p\n", __func__, preview->index, preview->path, preview->img); + // printf("%s: DONE %d - %s - %p\n", __func__, preview->index, preview->path, preview->img); if (preview->img) { IMB_freeImBuf(preview->img); } @@ -1421,8 +1457,9 @@ void filelist_free(struct FileList *filelist) void filelist_freelib(struct FileList *filelist) { - if (filelist->libfiledata) + if (filelist->libfiledata) { BLO_blendhandle_close(filelist->libfiledata); + } filelist->libfiledata = NULL; } @@ -1514,8 +1551,10 @@ bool filelist_pending(struct FileList *filelist) } /** - * Limited version of full update done by space_file's file_refresh(), to be used by operators and such. - * Ensures given filelist is ready to be used (i.e. it is filtered and sorted), unless it is tagged for a full refresh. + * Limited version of full update done by space_file's file_refresh(), + * to be used by operators and such. + * Ensures given filelist is ready to be used (i.e. it is filtered and sorted), + * unless it is tagged for a full refresh. */ int filelist_files_ensure(FileList *filelist) { @@ -1717,7 +1756,11 @@ static void filelist_file_cache_block_release(struct FileList *filelist, for (i = 0; i < size; i++, cursor++) { FileDirEntry *entry = cache->block_entries[cursor]; - // printf("%s: release cacheidx %d (%%p %%s)\n", __func__, cursor/*, cache->block_entries[cursor], cache->block_entries[cursor]->relpath*/); +#if 0 + printf("%s: release cacheidx %d (%%p %%s)\n", + __func__, + cursor /*, cache->block_entries[cursor], cache->block_entries[cursor]->relpath*/); +#endif BLI_ghash_remove(cache->uuids, entry->uuid, NULL, NULL); filelist_file_release_entry(filelist, entry); #ifndef NDEBUG @@ -1828,8 +1871,12 @@ bool filelist_file_cache_block(struct FileList *filelist, const int index) int size2 = 0; int idx1, idx2 = 0; - // printf("\tcache releasing: [%d:%d] (%d)\n", - // cache->block_end_index - size1, cache->block_end_index, cache->block_cursor); +#if 0 + printf("\tcache releasing: [%d:%d] (%d)\n", + cache->block_end_index - size1, + cache->block_end_index, + cache->block_cursor); +#endif idx1 = (cache->block_cursor + end_index - cache->block_start_index) % cache_size; if (idx1 + size1 > cache_size) { @@ -1988,8 +2035,8 @@ bool filelist_cache_previews_update(FileList *filelist) // printf("%s: %d - %s - %p\n", __func__, preview->index, preview->path, preview->img); if (preview->img) { - /* Due to asynchronous process, a preview for a given image may be generated several times, i.e. - * entry->image may already be set at this point. */ + /* Due to asynchronous process, a preview for a given image may be generated several times, + * i.e. entry->image may already be set at this point. */ if (entry && !entry->image) { entry->image = preview->img; changed = true; @@ -2031,14 +2078,16 @@ static bool file_is_blend_backup(const char *str) else { const char *loc; - if (a > b + 1) + if (a > b + 1) { b++; + } /* allow .blend1 .blend2 .blend32 */ loc = BLI_strcasestr(str + a - b, ".blend"); - if (loc) + if (loc) { retval = 1; + } } return (retval); @@ -2261,8 +2310,9 @@ static int groupname_to_code(const char *group) BLI_strncpy(buf, group, sizeof(buf)); lslash = (char *)BLI_last_slash(buf); - if (lslash) + if (lslash) { lslash[0] = '\0'; + } return buf[0] ? BKE_idcode_from_name(buf) : 0; } @@ -2275,7 +2325,8 @@ static unsigned int groupname_to_filter_id(const char *group) } /** - * From here, we are in 'Job Context', i.e. have to be careful about sharing stuff between background working thread + * From here, we are in 'Job Context', + * i.e. have to be careful about sharing stuff between background working thread. * and main one (used by UI among other things). */ typedef struct TodoDir { @@ -2420,11 +2471,13 @@ static void filelist_readjob_main_rec(Main *bmain, FileList *filelist) BLI_assert(filelist->filelist.entries == NULL); - if (filelist->filelist.root[0] == '/') filelist->filelist.root[0] = '\0'; + if (filelist->filelist.root[0] == '/') + filelist->filelist.root[0] = '\0'; if (filelist->filelist.root[0]) { idcode = groupname_to_code(filelist->filelist.root); - if (idcode == 0) filelist->filelist.root[0] = '\0'; + if (idcode == 0) + filelist->filelist.root[0] = '\0'; } if (filelist->dir[0] == 0) { @@ -2472,7 +2525,8 @@ static void filelist_readjob_main_rec(Main *bmain, FileList *filelist) idcode = groupname_to_code(filelist->filelist.root); lb = which_libbase(bmain, idcode); - if (lb == NULL) return; + if (lb == NULL) + return; filelist->filelist.nbr_entries = 0; for (id = lb->first; id; id = id->next) { @@ -2516,26 +2570,42 @@ static void filelist_readjob_main_rec(Main *bmain, FileList *filelist) # if 0 /* XXX TODO show the selection status of the objects */ if (!filelist->has_func) { /* F4 DATA BROWSE */ if (idcode == ID_OB) { - if ( ((Object *)id)->flag & SELECT) files->entry->selflag |= FILE_SEL_SELECTED; + if ( ((Object *)id)->flag & SELECT) { + files->entry->selflag |= FILE_SEL_SELECTED; + } } else if (idcode == ID_SCE) { - if ( ((Scene *)id)->r.scemode & R_BG_RENDER) files->entry->selflag |= FILE_SEL_SELECTED; + if ( ((Scene *)id)->r.scemode & R_BG_RENDER) { + files->entry->selflag |= FILE_SEL_SELECTED; + } } } # endif -// files->entry->nr = totbl + 1; + // files->entry->nr = totbl + 1; files->entry->poin = id; fake = id->flag & LIB_FAKEUSER; - if (idcode == ID_MA || idcode == ID_TE || idcode == ID_LA || idcode == ID_WO || idcode == ID_IM) { + if (idcode == ID_MA || idcode == ID_TE || idcode == ID_LA || idcode == ID_WO || + idcode == ID_IM) { files->typeflag |= FILE_TYPE_IMAGE; } -// if (id->lib && fake) BLI_snprintf(files->extra, sizeof(files->entry->extra), "LF %d", id->us); -// else if (id->lib) BLI_snprintf(files->extra, sizeof(files->entry->extra), "L %d", id->us); -// else if (fake) BLI_snprintf(files->extra, sizeof(files->entry->extra), "F %d", id->us); -// else BLI_snprintf(files->extra, sizeof(files->entry->extra), " %d", id->us); +# if 0 + if (id->lib && fake) { + BLI_snprintf(files->extra, sizeof(files->entry->extra), "LF %d", id->us); + } + else if (id->lib) { + BLI_snprintf(files->extra, sizeof(files->entry->extra), "L %d", id->us); + } + else if (fake) { + BLI_snprintf(files->extra, sizeof(files->entry->extra), "F %d", id->us); + } + else { + BLI_snprintf(files->extra, sizeof(files->entry->extra), " %d", id->us); + } +# endif if (id->lib) { - if (totlib == 0) firstlib = files; + if (totlib == 0) + firstlib = files; totlib++; } @@ -2634,7 +2704,7 @@ static void filelist_readjob_do(const bool do_lib, /* Only thing we change in direntry here, so we need to free it first. */ MEM_freeN(entry->relpath); entry->relpath = BLI_strdup(dir + 2); /* + 2 to remove '//' - * added by BLI_path_rel to rel_subdir */ + * added by BLI_path_rel to rel_subdir. */ entry->name = BLI_strdup(fileentry_uiname(root, entry->relpath, entry->typeflag, dir)); /* Here we decide whether current filedirentry is to be listed too, or not. */ diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 24689d52110..e5f19f0164d 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -161,32 +161,45 @@ short ED_fileselect_set_params(SpaceFile *sfile) } params->filter = 0; - if ((prop = RNA_struct_find_property(op->ptr, "filter_blender"))) + if ((prop = RNA_struct_find_property(op->ptr, "filter_blender"))) { params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDER : 0; - if ((prop = RNA_struct_find_property(op->ptr, "filter_blenlib"))) + } + if ((prop = RNA_struct_find_property(op->ptr, "filter_blenlib"))) { params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDERLIB : 0; - if ((prop = RNA_struct_find_property(op->ptr, "filter_backup"))) + } + if ((prop = RNA_struct_find_property(op->ptr, "filter_backup"))) { params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDER_BACKUP : 0; - if ((prop = RNA_struct_find_property(op->ptr, "filter_image"))) + } + if ((prop = RNA_struct_find_property(op->ptr, "filter_image"))) { params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_IMAGE : 0; - if ((prop = RNA_struct_find_property(op->ptr, "filter_movie"))) + } + if ((prop = RNA_struct_find_property(op->ptr, "filter_movie"))) { params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_MOVIE : 0; - if ((prop = RNA_struct_find_property(op->ptr, "filter_python"))) + } + if ((prop = RNA_struct_find_property(op->ptr, "filter_python"))) { params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_PYSCRIPT : 0; - if ((prop = RNA_struct_find_property(op->ptr, "filter_font"))) + } + if ((prop = RNA_struct_find_property(op->ptr, "filter_font"))) { params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_FTFONT : 0; - if ((prop = RNA_struct_find_property(op->ptr, "filter_sound"))) + } + if ((prop = RNA_struct_find_property(op->ptr, "filter_sound"))) { params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_SOUND : 0; - if ((prop = RNA_struct_find_property(op->ptr, "filter_text"))) + } + if ((prop = RNA_struct_find_property(op->ptr, "filter_text"))) { params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_TEXT : 0; - if ((prop = RNA_struct_find_property(op->ptr, "filter_folder"))) + } + if ((prop = RNA_struct_find_property(op->ptr, "filter_folder"))) { params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_FOLDER : 0; - if ((prop = RNA_struct_find_property(op->ptr, "filter_btx"))) + } + if ((prop = RNA_struct_find_property(op->ptr, "filter_btx"))) { params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BTX : 0; - if ((prop = RNA_struct_find_property(op->ptr, "filter_collada"))) + } + if ((prop = RNA_struct_find_property(op->ptr, "filter_collada"))) { params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_COLLADA : 0; - if ((prop = RNA_struct_find_property(op->ptr, "filter_alembic"))) + } + if ((prop = RNA_struct_find_property(op->ptr, "filter_alembic"))) { params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_ALEMBIC : 0; + } if ((prop = RNA_struct_find_property(op->ptr, "filter_glob"))) { /* Protection against pyscripts not setting proper size limit... */ char *tmp = RNA_property_string_get_alloc( @@ -290,8 +303,9 @@ short ED_fileselect_set_params(SpaceFile *sfile) params->active_file = -1; /* initialize the list with previous folders */ - if (!sfile->folders_prev) + if (!sfile->folders_prev) { sfile->folders_prev = folderlist_new(); + } if (!sfile->params->dir[0]) { if (blendfile_path[0] != '\0') { @@ -375,8 +389,9 @@ FileSelection ED_fileselect_layout_offset_rect(FileLayout *layout, const rcti *r FileSelection sel; sel.first = sel.last = -1; - if (layout == NULL) + if (layout == NULL) { return sel; + } colmin = (rect->xmin) / (layout->tile_w + 2 * layout->tile_border_x); rowmin = (rect->ymin) / (layout->tile_h + 2 * layout->tile_border_y); @@ -395,19 +410,23 @@ FileSelection ED_fileselect_layout_offset_rect(FileLayout *layout, const rcti *r sel.first = -1; } else { - if (layout->flag & FILE_LAYOUT_HOR) + if (layout->flag & FILE_LAYOUT_HOR) { sel.first = layout->rows * colmin + rowmin; - else + } + else { sel.first = colmin + layout->columns * rowmin; + } } if ((colmax > layout->columns - 1) || (rowmax > layout->rows - 1)) { sel.last = -1; } else { - if (layout->flag & FILE_LAYOUT_HOR) + if (layout->flag & FILE_LAYOUT_HOR) { sel.last = layout->rows * colmax + rowmax; - else + } + else { sel.last = colmax + layout->columns * rowmax; + } } return sel; @@ -418,21 +437,26 @@ int ED_fileselect_layout_offset(FileLayout *layout, int x, int y) int offsetx, offsety; int active_file; - if (layout == NULL) + if (layout == NULL) { return -1; + } offsetx = (x) / (layout->tile_w + 2 * layout->tile_border_x); offsety = (y) / (layout->tile_h + 2 * layout->tile_border_y); - if (offsetx > layout->columns - 1) + if (offsetx > layout->columns - 1) { return -1; - if (offsety > layout->rows - 1) + } + if (offsety > layout->rows - 1) { return -1; + } - if (layout->flag & FILE_LAYOUT_HOR) + if (layout->flag & FILE_LAYOUT_HOR) { active_file = layout->rows * offsetx + offsety; - else + } + else { active_file = offsetx + layout->columns * offsety; + } return active_file; } @@ -536,8 +560,9 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *ar) layout->tile_h = layout->prv_h + 2 * layout->prv_border_y + textheight; layout->width = (int)(BLI_rctf_size_x(&v2d->cur) - 2 * layout->tile_border_x); layout->columns = layout->width / (layout->tile_w + 2 * layout->tile_border_x); - if (layout->columns > 0) + if (layout->columns > 0) { layout->rows = numfiles / layout->columns + 1; // XXX dirty, modulo is zero + } else { layout->columns = 1; layout->rows = numfiles + 1; // XXX dirty, modulo is zero @@ -577,8 +602,9 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *ar) (int)layout->column_widths[COLUMN_SIZE] + column_space; } layout->tile_w = maxlen; - if (layout->rows > 0) + if (layout->rows > 0) { layout->columns = numfiles / layout->rows + 1; // XXX dirty, modulo is zero + } else { layout->rows = 1; layout->columns = numfiles + 1; // XXX dirty, modulo is zero @@ -619,8 +645,9 @@ void ED_file_change_dir(bContext *C) } filelist_setdir(sfile->files, sfile->params->dir); - if (folderlist_clear_next(sfile)) + if (folderlist_clear_next(sfile)) { folderlist_free(sfile->folders_next); + } folderlist_pushdir(sfile->folders_prev, sfile->params->dir); @@ -739,8 +766,9 @@ void ED_fileselect_clear(wmWindowManager *wm, ScrArea *sa, SpaceFile *sfile) void ED_fileselect_exit(wmWindowManager *wm, ScrArea *sa, SpaceFile *sfile) { - if (!sfile) + if (!sfile) { return; + } if (sfile->op) { WM_event_fileselect_event(wm, sfile->op, EVT_FILESELECT_EXTERNAL_CANCEL); sfile->op = NULL; @@ -757,8 +785,8 @@ void ED_fileselect_exit(wmWindowManager *wm, ScrArea *sa, SpaceFile *sfile) } } -/** Helper used by both main update code, and smoothscroll timer, to try to enable rename editing from - * params->renamefile name. */ +/** Helper used by both main update code, and smoothscroll timer, + * to try to enable rename editing from #FileSelectParams.renamefile name. */ void file_params_renamefile_activate(SpaceFile *sfile, FileSelectParams *params) { BLI_assert(params->rename_flag != 0); diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c index f14148abe86..38423a87447 100644 --- a/source/blender/editors/space_file/fsmenu.c +++ b/source/blender/editors/space_file/fsmenu.c @@ -39,7 +39,7 @@ /* Need to include windows.h so _WIN32_IE is defined. */ # include <windows.h> /* For SHGetSpecialFolderPath, has to be done before BLI_winstuff - * because 'near' is disabled through BLI_windstuff. */ + * because 'near' is disabled through BLI_windstuff. */ # include <shlobj.h> # include "BLI_winstuff.h" #endif @@ -219,9 +219,8 @@ void fsmenu_entry_refresh_valid(struct FSMenuEntry *fsentry) if (fsentry->path && fsentry->path[0]) { #ifdef WIN32 /* XXX Special case, always consider those as valid. - * Thanks to Windows, which can spend five seconds to perform a mere stat() call on those paths... - * See T43684. - */ + * Thanks to Windows, which can spend five seconds to perform a mere stat() call on those paths + * See T43684. */ const char *exceptions[] = {"A:\\", "B:\\", NULL}; const size_t exceptions_len[] = {strlen(exceptions[0]), strlen(exceptions[1]), 0}; int i; @@ -297,8 +296,8 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu, fsm_iter->save = (flag & FS_INSERT_SAVE) != 0; if ((category == FS_CATEGORY_RECENT) && (!name || !name[0])) { - /* Special handling when adding new recent entry - check if dir exists in some other categories, - * and try to use name from there if so. */ + /* Special handling when adding new recent entry - check if dir exists in + * some other categories, and try to use name from there if so. */ FSMenuCategory cats[] = { FS_CATEGORY_SYSTEM, FS_CATEGORY_SYSTEM_BOOKMARKS, FS_CATEGORY_BOOKMARKS}; int i = ARRAY_SIZE(cats); @@ -352,8 +351,9 @@ void fsmenu_remove_entry(struct FSMenu *fsmenu, FSMenuCategory category, int idx fsm_head = ED_fsmenu_get_category(fsmenu, category); - for (fsm_iter = fsm_head; fsm_iter && idx; fsm_prev = fsm_iter, fsm_iter = fsm_iter->next) + for (fsm_iter = fsm_head; fsm_iter && idx; fsm_prev = fsm_iter, fsm_iter = fsm_iter->next) { idx--; + } if (fsm_iter) { /* you should only be able to remove entries that were @@ -383,8 +383,9 @@ void fsmenu_write_file(struct FSMenu *fsmenu, const char *filename) int nwritten = 0; FILE *fp = BLI_fopen(filename, "w"); - if (!fp) + if (!fp) { return; + } fprintf(fp, "[Bookmarks]\n"); for (fsm_iter = ED_fsmenu_get_category(fsmenu, FS_CATEGORY_BOOKMARKS); fsm_iter; @@ -420,8 +421,9 @@ void fsmenu_read_bookmarks(struct FSMenu *fsmenu, const char *filename) FILE *fp; fp = BLI_fopen(filename, "r"); - if (!fp) + if (!fp) { return; + } name[0] = '\0'; @@ -519,11 +521,12 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) #else # ifdef __APPLE__ { - /* Get mounted volumes better method OSX 10.6 and higher, see: */ - /*https://developer.apple.com/library/mac/#documentation/CoreFOundation/Reference/CFURLRef/Reference/reference.html*/ + /* Get mounted volumes better method OSX 10.6 and higher, see: + * https://developer.apple.com/library/mac/#documentation/CoreFOundation/Reference/CFURLRef/Reference/reference.html + */ - /* we get all volumes sorted including network and do not relay - * on user-defined finder visibility, less confusing */ + /* We get all volumes sorted including network and do not relay + * on user-defined finder visibility, less confusing. */ CFURLRef cfURL = NULL; CFURLEnumeratorResult result = kCFURLEnumeratorSuccess; @@ -534,8 +537,9 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) char defPath[FILE_MAX]; result = CFURLEnumeratorGetNextURL(volEnum, &cfURL, NULL); - if (result != kCFURLEnumeratorSuccess) + if (result != kCFURLEnumeratorSuccess) { continue; + } CFURLGetFileSystemRepresentation(cfURL, false, (UInt8 *)defPath, FILE_MAX); @@ -565,14 +569,16 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) kLSSharedFileListDoNotMountVolumes, &cfURL, NULL); - if (err != noErr || !cfURL) + if (err != noErr || !cfURL) { continue; + } CFStringRef pathString = CFURLCopyFileSystemPath(cfURL, kCFURLPOSIXPathStyle); if (pathString == NULL || - !CFStringGetCString(pathString, line, sizeof(line), kCFStringEncodingUTF8)) + !CFStringGetCString(pathString, line, sizeof(line), kCFStringEncodingUTF8)) { continue; + } /* Add end slash for consistency with other platforms */ BLI_add_slash(line); @@ -678,8 +684,9 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) # endif /* fallback */ - if (!found) + if (!found) { fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, "/", NULL, FS_INSERT_SORTED); + } } } # endif diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 53bcf7068f4..9fb07042104 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -155,8 +155,9 @@ static void file_init(wmWindowManager *UNUSED(wm), ScrArea *sa) */ fsmenu_refresh_bookmarks_status(ED_fsmenu_get()); - if (sfile->layout) + if (sfile->layout) { sfile->layout->dirty = true; + } } static void file_exit(wmWindowManager *wm, ScrArea *sa) @@ -188,11 +189,13 @@ static SpaceLink *file_duplicate(SpaceLink *sl) filelist_setdir(sfilen->files, sfilen->params->dir); } - if (sfileo->folders_prev) + if (sfileo->folders_prev) { sfilen->folders_prev = folderlist_duplicate(sfileo->folders_prev); + } - if (sfileo->folders_next) + if (sfileo->folders_next) { sfilen->folders_next = folderlist_duplicate(sfileo->folders_next); + } if (sfileo->layout) { sfilen->layout = MEM_dupallocN(sfileo->layout); @@ -313,10 +316,10 @@ static void file_main_region_init(wmWindowManager *wm, ARegion *ar) /* own keymaps */ keymap = WM_keymap_ensure(wm->defaultconf, "File Browser", SPACE_FILE, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "File Browser Main", SPACE_FILE, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } static void file_main_region_listener(wmWindow *UNUSED(win), @@ -389,8 +392,9 @@ static void file_main_region_draw(const bContext *C, ARegion *ar) float col[3]; /* Needed, because filelist is not initialized on loading */ - if (!sfile->files || filelist_empty(sfile->files)) + if (!sfile->files || filelist_empty(sfile->files)) { file_refresh(C, NULL); + } /* clear and setup matrix */ UI_GetThemeColor3fv(TH_BACK, col); @@ -437,9 +441,8 @@ static void file_main_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); /* scrollers */ - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY); - UI_view2d_scrollers_draw(C, v2d, scrollers); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); } @@ -494,7 +497,7 @@ static void file_tools_region_init(wmWindowManager *wm, ARegion *ar) /* own keymaps */ keymap = WM_keymap_ensure(wm->defaultconf, "File Browser", SPACE_FILE, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } static void file_tools_region_draw(const bContext *C, ARegion *ar) @@ -524,7 +527,7 @@ static void file_header_region_init(wmWindowManager *wm, ARegion *ar) ED_region_header_init(ar); keymap = WM_keymap_ensure(wm->defaultconf, "File Browser", SPACE_FILE, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } static void file_header_region_draw(const bContext *C, ARegion *ar) @@ -541,10 +544,10 @@ static void file_ui_region_init(wmWindowManager *wm, ARegion *ar) /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "File Browser", SPACE_FILE, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "File Browser Buttons", SPACE_FILE, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } static void file_ui_region_draw(const bContext *C, ARegion *ar) diff --git a/source/blender/editors/space_graph/CMakeLists.txt b/source/blender/editors/space_graph/CMakeLists.txt index cf5ffdb2be5..f4d31886e3f 100644 --- a/source/blender/editors/space_graph/CMakeLists.txt +++ b/source/blender/editors/space_graph/CMakeLists.txt @@ -25,8 +25,8 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c index ac77095cbe2..3b1e70b8db7 100644 --- a/source/blender/editors/space_graph/graph_buttons.c +++ b/source/blender/editors/space_graph/graph_buttons.c @@ -76,23 +76,30 @@ static int graph_panel_context(const bContext *C, bAnimListElem **ale, FCurve ** bAnimContext ac; bAnimListElem *elem = NULL; - /* for now, only draw if we could init the anim-context info (necessary for all animation-related tools) - * to work correctly is able to be correctly retrieved. There's no point showing empty panels? + /* For now, only draw if we could init the anim-context info + * (necessary for all animation-related tools) + * to work correctly is able to be correctly retrieved. + * There's no point showing empty panels? */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return 0; + } /* try to find 'active' F-Curve */ elem = get_active_fcurve_channel(&ac); - if (elem == NULL) + if (elem == NULL) { return 0; + } - if (fcu) + if (fcu) { *fcu = (FCurve *)elem->data; - if (ale) + } + if (ale) { *ale = elem; - else + } + else { MEM_freeN(elem); + } return 1; } @@ -128,10 +135,12 @@ static void graph_panel_view(const bContext *C, Panel *pa) sub = uiLayoutColumn(col, true); uiLayoutSetActive(sub, RNA_boolean_get(&spaceptr, "show_cursor")); row = uiLayoutSplit(sub, 0.7f, true); - if (sipo->mode == SIPO_MODE_DRIVERS) + if (sipo->mode == SIPO_MODE_DRIVERS) { uiItemR(row, &spaceptr, "cursor_position_x", 0, IFACE_("Cursor X"), ICON_NONE); - else + } + else { uiItemR(row, &sceneptr, "frame_current", 0, IFACE_("Cursor X"), ICON_NONE); + } uiItemEnumO(row, "GRAPH_OT_snap", IFACE_("To Keys"), 0, "type", GRAPHKEYS_SNAP_CFRA); row = uiLayoutSplit(sub, 0.7f, true); @@ -151,8 +160,9 @@ static void graph_panel_properties(const bContext *C, Panel *pa) char name[256]; int icon = 0; - if (!graph_panel_context(C, &ale, &fcu)) + if (!graph_panel_context(C, &ale, &fcu)) { return; + } /* F-Curve pointer */ RNA_pointer_create(ale->id, &RNA_FCurve, fcu, &fcu_ptr); @@ -177,8 +187,9 @@ static void graph_panel_properties(const bContext *C, Panel *pa) } /* icon */ - if (ale->type == ANIMTYPE_NLACURVE) + if (ale->type == ANIMTYPE_NLACURVE) { icon = ICON_NLA; + } } uiItemL(col, name, icon); @@ -219,8 +230,9 @@ static short get_active_fcurve_keyframe_edit(FCurve *fcu, BezTriple **bezt, BezT *bezt = *prevbezt = NULL; /* sanity checks */ - if ((fcu->bezt == NULL) || (fcu->totvert == 0)) + if ((fcu->bezt == NULL) || (fcu->totvert == 0)) { return 0; + } /* find first selected keyframe for now, and call it the active one * - this is a reasonable assumption, given that whenever anyone @@ -330,8 +342,9 @@ static void graph_panel_key_properties(const bContext *C, Panel *pa) uiLayout *col; uiBlock *block; - if (!graph_panel_context(C, &ale, &fcu)) + if (!graph_panel_context(C, &ale, &fcu)) { return; + } block = uiLayoutGetBlock(layout); /* UI_block_func_handle_set(block, do_graph_region_buttons, NULL); */ @@ -365,8 +378,9 @@ static void graph_panel_key_properties(const bContext *C, Panel *pa) } /* easing type */ - if (bezt->ipo > BEZT_IPO_BEZ) + if (bezt->ipo > BEZT_IPO_BEZ) { uiItemR(col, &bezt_ptr, "easing", 0, NULL, 0); + } /* easing extra */ switch (bezt->ipo) { @@ -565,8 +579,9 @@ static void graph_panel_key_properties(const bContext *C, Panel *pa) IFACE_("F-Curve doesn't have any keyframes as it only contains sampled points"), ICON_NONE); } - else + else { uiItemL(layout, IFACE_("No active keyframe on F-Curve"), ICON_NONE); + } } MEM_freeN(ale); @@ -693,8 +708,9 @@ static bool graph_panel_drivers_poll(const bContext *C, PanelType *UNUSED(pt)) { SpaceGraph *sipo = CTX_wm_space_graph(C); - if (sipo->mode != SIPO_MODE_DRIVERS) + if (sipo->mode != SIPO_MODE_DRIVERS) { return 0; + } return graph_panel_context(C, NULL, NULL); } @@ -869,7 +885,8 @@ static void graph_draw_driven_property_panel(uiLayout *layout, ID *id, FCurve *f uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_LEFT); /* -> user friendly 'name' for datablock that owns F-Curve */ - /* XXX: Actually, we may need the datablock icons only... (e.g. right now will show bone for bone props) */ + /* XXX: Actually, we may need the datablock icons only... + * (e.g. right now will show bone for bone props). */ uiItemL(row, id->name + 2, icon); /* -> user friendly 'name' for F-Curve/driver target */ @@ -915,7 +932,8 @@ static void graph_draw_driver_settings_panel(uiLayout *layout, uiItemS(layout); uiItemS(layout); - /* show expression box if doing scripted drivers, and/or error messages when invalid drivers exist */ + /* show expression box if doing scripted drivers, + * and/or error messages when invalid drivers exist */ if (driver->type == DRIVER_TYPE_PYTHON) { bool bpy_data_expr_error = (strstr(driver->expression, "bpy.data.") != NULL); bool bpy_ctx_expr_error = (strstr(driver->expression, "bpy.context.") != NULL); @@ -965,8 +983,9 @@ static void graph_draw_driver_settings_panel(uiLayout *layout, col = uiLayoutColumn(layout, true); block = uiLayoutGetBlock(col); - if (driver->flag & DRIVER_FLAG_INVALID) + if (driver->flag & DRIVER_FLAG_INVALID) { uiItemL(col, IFACE_("ERROR: Invalid target channel(s)"), ICON_ERROR); + } /* Warnings about a lack of variables * NOTE: The lack of variables is generally a bad thing, since it indicates @@ -1190,14 +1209,16 @@ static void graph_draw_driver_settings_panel(uiLayout *layout, /* ----------------------------------------------------------------- */ -/* panel to show property driven by the driver (in Drivers Editor) - duplicates Active FCurve, but useful for clarity */ +/* Panel to show property driven by the driver (in Drivers Editor) - duplicates Active FCurve, + * but useful for clarity. */ static void graph_panel_driven_property(const bContext *C, Panel *pa) { bAnimListElem *ale; FCurve *fcu; - if (!graph_panel_context(C, &ale, &fcu)) + if (!graph_panel_context(C, &ale, &fcu)) { return; + } graph_draw_driven_property_panel(pa->layout, ale->id, fcu); @@ -1212,8 +1233,9 @@ static void graph_panel_drivers(const bContext *C, Panel *pa) FCurve *fcu; /* Get settings from context */ - if (!graph_panel_context(C, &ale, &fcu)) + if (!graph_panel_context(C, &ale, &fcu)) { return; + } graph_draw_driver_settings_panel(pa->layout, ale->id, fcu, false); @@ -1223,7 +1245,8 @@ static void graph_panel_drivers(const bContext *C, Panel *pa) /* ----------------------------------------------------------------- */ -/* poll to make this not show up in the graph editor, as this is only to be used as a popup elsewhere */ +/* Poll to make this not show up in the graph editor, + * as this is only to be used as a popup elsewhere. */ static bool graph_panel_drivers_popover_poll(const bContext *C, PanelType *UNUSED(pt)) { return ED_operator_graphedit_active((bContext *)C) == false; @@ -1255,7 +1278,7 @@ static void graph_panel_drivers_popover(const bContext *C, Panel *pa) uiLayoutSetContextFromBut(layout, but); /* Populate Panel - With a combination of the contents of the Driven and Driver panels */ - if (fcu) { + if (fcu && fcu->driver) { ID *id = ptr.id.data; /* Driven Property Settings */ @@ -1300,8 +1323,9 @@ static void graph_panel_modifiers(const bContext *C, Panel *pa) uiBlock *block; bool active; - if (!graph_panel_context(C, &ale, &fcu)) + if (!graph_panel_context(C, &ale, &fcu)) { return; + } block = uiLayoutGetBlock(pa->layout); UI_block_func_handle_set(block, do_graph_region_modifier_buttons, NULL); @@ -1405,27 +1429,3 @@ void graph_buttons_register(ARegionType *art) pt->draw = graph_panel_view; BLI_addtail(&art->paneltypes, pt); } - -static int graph_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = graph_has_buttons_region(sa); - - if (ar) - ED_region_toggle_hidden(C, ar); - - return OPERATOR_FINISHED; -} - -void GRAPH_OT_properties(wmOperatorType *ot) -{ - ot->name = "Toggle Sidebar"; - ot->idname = "GRAPH_OT_properties"; - ot->description = "Toggle the properties region visibility"; - - ot->exec = graph_properties_toggle_exec; - ot->poll = ED_operator_graphedit_active; - - /* flags */ - ot->flag = 0; -} diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index 5bfe1c1aadd..dfc59a79c49 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -175,8 +175,9 @@ static void draw_fcurve_selected_keyframe_vertices( BezTriple *bezt = fcu->bezt; for (int i = 0; i < fcu->totvert; i++, bezt++) { - /* as an optimization step, only draw those in view - * - we apply a correction factor to ensure that points don't pop in/out due to slight twitches of view size + /* As an optimization step, only draw those in view + * - We apply a correction factor to ensure that points + * don't pop in/out due to slight twitches of view size. */ if (IN_RANGE(bezt->vec[1][0], (v2d->cur.xmin - fac), (v2d->cur.xmax + fac))) { if (edit) { @@ -184,8 +185,9 @@ static void draw_fcurve_selected_keyframe_vertices( * - only draw those with correct selection state for the current drawing color * - */ - if ((bezt->f2 & SELECT) == sel) + if ((bezt->f2 & SELECT) == sel) { immVertex2fv(pos, bezt->vec[1]); + } } else { /* no check for selection here, as curve is not editable... */ @@ -281,9 +283,10 @@ static void draw_fcurve_vertices(ARegion *ar, FCurve *fcu, bool do_handles, bool View2D *v2d = &ar->v2d; /* only draw points if curve is visible - * - draw unselected points before selected points as separate passes + * - Draw unselected points before selected points as separate passes * to make sure in the case of overlapping points that the selected is always visible - * - draw handles before keyframes, so that keyframes will overlap handles (keyframes are more important for users) + * - Draw handles before keyframes, so that keyframes will overlap handles + * (keyframes are more important for users). */ uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); @@ -315,13 +318,13 @@ static bool draw_fcurve_handles_check(SpaceGraph *sipo, FCurve *fcu) /* keyframes aren't editable */ (fcu->flag & FCURVE_PROTECTED) || #if 0 /* handles can still be selected and handle types set, better draw - campbell */ - /* editing the handles here will cause weird/incorrect interpolation issues */ - (fcu->flag & FCURVE_INT_VALUES) || + /* editing the handles here will cause weird/incorrect interpolation issues */ + (fcu->flag & FCURVE_INT_VALUES) || #endif /* group that curve belongs to is not editable */ ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) || - /* do not show handles if there is only 1 keyframe, - * otherwise they all clump together in an ugly ball */ + /* Do not show handles if there is only 1 keyframe, + * otherwise they all clump together in an ugly ball. */ (fcu->totvert <= 1)) { return false; } @@ -358,8 +361,9 @@ static void draw_fcurve_handles(SpaceGraph *sipo, FCurve *fcu) * check that keyframe is selected */ if (sipo->flag & SIPO_SELVHANDLESONLY) { - if (BEZT_ISSEL_ANY(bezt) == 0) + if (BEZT_ISSEL_ANY(bezt) == 0) { continue; + } } /* draw handle with appropriate set of colors if selection is ok */ @@ -462,8 +466,9 @@ static void draw_fcurve_samples(SpaceGraph *sipo, ARegion *ar, FCurve *fcu) /* draw */ if (first && last) { /* anti-aliased lines for more consistent appearance */ - if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) + if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) { GPU_line_smooth(true); + } GPU_blend(true); uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); @@ -477,30 +482,31 @@ static void draw_fcurve_samples(SpaceGraph *sipo, ARegion *ar, FCurve *fcu) immUnbindProgram(); GPU_blend(false); - if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) + if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) { GPU_line_smooth(false); + } } } /* Curve ---------------- */ -/* helper func - just draw the F-Curve by sampling the visible region (for drawing curves with modifiers) */ +/* Helper func - just draw the F-Curve by sampling the visible region + * (for drawing curves with modifiers). */ static void draw_fcurve_curve( - bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2d, View2DGrid *grid, unsigned int pos) + bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2d, unsigned int pos) { SpaceGraph *sipo = (SpaceGraph *)ac->sl; float samplefreq; float stime, etime; float unitFac, offset; - float dx, dy; short mapping_flag = ANIM_get_normalization_flags(ac); int i, n; - /* when opening a blend file on a different sized screen or while dragging the toolbar this can happen - * best just bail out in this case */ - UI_view2d_grid_size(grid, &dx, &dy); - if (dx <= 0.0f) + /* when opening a blend file on a different sized screen or while dragging the toolbar this can + * happen best just bail out in this case. */ + if (UI_view2d_scale_get_x(v2d) <= 0.0f) { return; + } /* disable any drivers */ FCurve fcurve_for_draw = *fcu_; @@ -521,10 +527,11 @@ static void draw_fcurve_curve( * loop (i.e. too close to 0), then clamp it to a determined "safe" value. The value * chosen here is just the coarsest value which still looks reasonable... */ - /* grid->dx represents the number of 'frames' between gridlines, - * but we divide by U.v2d_min_gridsize to get pixels-steps */ - /* TODO: perhaps we should have 1.0 frames as upper limit so that curves don't get too distorted? */ - samplefreq = dx / (U.v2d_min_gridsize * U.pixelsize); + + /* TODO: perhaps we should have 1.0 frames + * as upper limit so that curves don't get too distorted? */ + float pixels_per_sample = 1.5f; + samplefreq = pixels_per_sample / UI_view2d_scale_get_x(v2d); if (sipo->flag & SIPO_BEAUTYDRAW_OFF) { /* Low Precision = coarse lower-bound clamping @@ -536,13 +543,15 @@ static void draw_fcurve_curve( * This one still amounts to 10 sample-frames for each 1-frame interval * which should be quite a decent approximation in many situations. */ - if (samplefreq < 0.1f) + if (samplefreq < 0.1f) { samplefreq = 0.1f; + } } else { /* "Higher Precision" but slower - especially on larger windows (e.g. T40372) */ - if (samplefreq < 0.00001f) + if (samplefreq < 0.00001f) { samplefreq = 0.00001f; + } } /* the start/end times are simply the horizontal extents of the 'cur' rect */ @@ -609,8 +618,9 @@ static void draw_fcurve_curve_samples( else { /* extrapolate linear doesn't use the handle, use the next points center instead */ fac = (prevfpt->vec[0] - fpt->vec[0]) / (prevfpt->vec[0] - v[0]); - if (fac) + if (fac) { fac = 1.0f / fac; + } v[1] = prevfpt->vec[1] - fac * (prevfpt->vec[1] - fpt->vec[1]); } @@ -643,8 +653,9 @@ static void draw_fcurve_curve_samples( /* extrapolate linear doesn't use the handle, use the previous points center instead */ fpt = prevfpt - 1; fac = (prevfpt->vec[0] - fpt->vec[0]) / (prevfpt->vec[0] - v[0]); - if (fac) + if (fac) { fac = 1.0f / fac; + } v[1] = prevfpt->vec[1] - fac * (prevfpt->vec[1] - fpt->vec[1]); } @@ -712,15 +723,17 @@ static void draw_fcurve_curve_bezts( else if (prevbezt->ipo == BEZT_IPO_LIN) { /* extrapolate linear dosnt use the handle, use the next points center instead */ fac = (prevbezt->vec[1][0] - bezt->vec[1][0]) / (prevbezt->vec[1][0] - v1[0]); - if (fac) + if (fac) { fac = 1.0f / fac; + } v1[1] = prevbezt->vec[1][1] - fac * (prevbezt->vec[1][1] - bezt->vec[1][1]); } else { /* based on angle of handle 1 (relative to keyframe) */ fac = (prevbezt->vec[0][0] - prevbezt->vec[1][0]) / (prevbezt->vec[1][0] - v1[0]); - if (fac) + if (fac) { fac = 1.0f / fac; + } v1[1] = prevbezt->vec[1][1] - fac * (prevbezt->vec[0][1] - prevbezt->vec[1][1]); } @@ -778,8 +791,9 @@ static void draw_fcurve_curve_bezts( else { /* clamp resolution to max of 32 */ /* NOTE: higher values will crash */ - if (resol > 32) + if (resol > 32) { resol = 32; + } v1[0] = prevbezt->vec[1][0]; v1[1] = prevbezt->vec[1][1]; @@ -829,15 +843,17 @@ static void draw_fcurve_curve_bezts( /* extrapolate linear dosnt use the handle, use the previous points center instead */ bezt = prevbezt - 1; fac = (prevbezt->vec[1][0] - bezt->vec[1][0]) / (prevbezt->vec[1][0] - v1[0]); - if (fac) + if (fac) { fac = 1.0f / fac; + } v1[1] = prevbezt->vec[1][1] - fac * (prevbezt->vec[1][1] - bezt->vec[1][1]); } else { /* based on angle of handle 1 (relative to keyframe) */ fac = (prevbezt->vec[2][0] - prevbezt->vec[1][0]) / (prevbezt->vec[1][0] - v1[0]); - if (fac) + if (fac) { fac = 1.0f / fac; + } v1[1] = prevbezt->vec[1][1] - fac * (prevbezt->vec[2][1] - prevbezt->vec[1][1]); } @@ -865,7 +881,7 @@ static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu) float unitfac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset); /* for now, only show when debugging driver... */ - //if ((driver->flag & DRIVER_FLAG_SHOWDEBUG) == 0) + // if ((driver->flag & DRIVER_FLAG_SHOWDEBUG) == 0) // return; const uint shdr_pos = GPU_vertformat_attr_add( @@ -1025,8 +1041,7 @@ void graph_draw_ghost_curves(bAnimContext *ac, SpaceGraph *sipo, ARegion *ar) /* This is called twice from space_graph.c -> graph_main_region_draw() * Unselected then selected F-Curves are drawn so that they do not occlude each other. */ -void graph_draw_curves( - bAnimContext *ac, SpaceGraph *sipo, ARegion *ar, View2DGrid *grid, short sel) +void graph_draw_curves(bAnimContext *ac, SpaceGraph *sipo, ARegion *ar, short sel) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; @@ -1113,7 +1128,7 @@ void graph_draw_curves( /* draw a curve affected by modifiers or only allowed to have integer values * by sampling it at various small-intervals over the visible region */ - draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid, shdr_pos); + draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, shdr_pos); } else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) { /* just draw curve based on defined data (i.e. no modifiers) */ @@ -1122,7 +1137,7 @@ void graph_draw_curves( draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d, shdr_pos); } else { - draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid, shdr_pos); + draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, shdr_pos); } } else if (fcu->fpt) { @@ -1139,7 +1154,8 @@ void graph_draw_curves( } /* 2) draw handles and vertices as appropriate based on active - * - if the option to only show controls if the F-Curve is selected is enabled, we must obey this + * - If the option to only show controls if the F-Curve is selected is enabled, + * we must obey this. */ if (!(sipo->flag & SIPO_SELCUVERTSONLY) || (fcu->flag & FCURVE_SELECTED)) { if (!fcurve_are_keyframes_usable(fcu) && !(fcu->fpt && fcu->totvert)) { @@ -1163,7 +1179,8 @@ void graph_draw_curves( GPU_matrix_scale_2f(1.0f, unit_scale); GPU_matrix_translate_2f(0.0f, offset); - /* set this once and for all - all handles and handle-verts should use the same thickness */ + /* Set this once and for all - + * all handles and handle-verts should use the same thickness. */ GPU_line_width(1.0); if (fcu->bezt) { @@ -1193,8 +1210,9 @@ void graph_draw_curves( } /* undo mapping of keyframes for drawing if scaled F-Curve */ - if (adt) + if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0); + } } /* free list of curves */ diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 29058e47199..0954538e430 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -94,14 +94,18 @@ void get_graph_keyframe_extents(bAnimContext *ac, ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* set large values initial values that will be easy to override */ - if (xmin) + if (xmin) { *xmin = 999999999.0f; - if (xmax) + } + if (xmax) { *xmax = -999999999.0f; - if (ymin) + } + if (ymin) { *ymin = 999999999.0f; - if (ymax) + } + if (ymax) { *ymax = -999999999.0f; + } /* check if any channels to set range with */ if (anim_data.first) { @@ -132,14 +136,18 @@ void get_graph_keyframe_extents(bAnimContext *ac, tymax *= unitFac; /* try to set cur using these values, if they're more extreme than previously set values */ - if ((xmin) && (txmin < *xmin)) + if ((xmin) && (txmin < *xmin)) { *xmin = txmin; - if ((xmax) && (txmax > *xmax)) + } + if ((xmax) && (txmax > *xmax)) { *xmax = txmax; - if ((ymin) && (tymin < *ymin)) + } + if ((ymin) && (tymin < *ymin)) { *ymin = tymin; - if ((ymax) && (tymax > *ymax)) + } + if ((ymax) && (tymax > *ymax)) { *ymax = tymax; + } foundBounds = true; } @@ -157,14 +165,18 @@ void get_graph_keyframe_extents(bAnimContext *ac, } } else { - if (xmin) + if (xmin) { *xmin = (float)PSFRA; - if (xmax) + } + if (xmax) { *xmax = (float)PEFRA; - if (ymin) + } + if (ymin) { *ymin = -5; - if (ymax) + } + if (ymax) { *ymax = 5; + } } /* free memory */ @@ -173,22 +185,28 @@ void get_graph_keyframe_extents(bAnimContext *ac, else { /* set default range */ if (ac->scene) { - if (xmin) + if (xmin) { *xmin = (float)PSFRA; - if (xmax) + } + if (xmax) { *xmax = (float)PEFRA; + } } else { - if (xmin) + if (xmin) { *xmin = -5; - if (xmax) + } + if (xmax) { *xmax = 100; + } } - if (ymin) + if (ymin) { *ymin = -5; - if (ymax) + } + if (ymax) { *ymax = 5; + } } } @@ -201,12 +219,15 @@ static int graphkeys_previewrange_exec(bContext *C, wmOperator *UNUSED(op)) float min, max; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; - if (ac.scene == NULL) + } + if (ac.scene == NULL) { return OPERATOR_CANCELLED; - else + } + else { scene = ac.scene; + } /* set the range directly */ get_graph_keyframe_extents(&ac, &min, &max, NULL, NULL, false, false); @@ -230,8 +251,8 @@ void GRAPH_OT_previewrange_set(wmOperatorType *ot) /* api callbacks */ ot->exec = graphkeys_previewrange_exec; - ot->poll = - ED_operator_graphedit_active; // XXX: unchecked poll to get fsamples working too, but makes modifier damage trickier... + // XXX: unchecked poll to get fsamples working too, but makes modifier damage trickier... + ot->poll = ED_operator_graphedit_active; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -248,8 +269,9 @@ static int graphkeys_viewall(bContext *C, rctf cur_new; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* set the horizontal range, with an extra offset so that the extreme keys will be in view */ get_graph_keyframe_extents(&ac, @@ -444,10 +466,12 @@ static int graphkeys_create_ghostcurves_exec(bContext *C, wmOperator *UNUSED(op) int start, end; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } - /* ghost curves are snapshots of the visible portions of the curves, so set range to be the visible range */ + /* Ghost curves are snapshots of the visible portions of the curves, + * so set range to be the visible range. */ v2d = &ac.ar->v2d; start = (int)v2d->cur.xmin; end = (int)v2d->cur.xmax; @@ -488,8 +512,9 @@ static int graphkeys_clear_ghostcurves_exec(bContext *C, wmOperator *UNUSED(op)) SpaceGraph *sipo; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } sipo = (SpaceGraph *)ac.sl; /* if no ghost curves, don't do anything */ @@ -578,21 +603,26 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS); - if (mode & GRAPHKEYS_INSERTKEY_SEL) + if (mode & GRAPHKEYS_INSERTKEY_SEL) { filter |= ANIMFILTER_SEL; - else if (mode & GRAPHKEYS_INSERTKEY_ACTIVE) + } + else if (mode & GRAPHKEYS_INSERTKEY_ACTIVE) { filter |= ANIMFILTER_ACTIVE; + } num_items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); if (num_items == 0) { - if (mode & GRAPHKEYS_INSERTKEY_ACTIVE) + if (mode & GRAPHKEYS_INSERTKEY_ACTIVE) { BKE_report(reports, RPT_ERROR, "No active F-Curve to add a keyframe to. Select an editable F-Curve first"); - else if (mode & GRAPHKEYS_INSERTKEY_SEL) + } + else if (mode & GRAPHKEYS_INSERTKEY_SEL) { BKE_report(reports, RPT_ERROR, "No selected F-Curves to add keyframes to"); - else + } + else { BKE_report(reports, RPT_ERROR, "No channels to add keyframes to"); + } return; } @@ -614,18 +644,23 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) float x, y; /* perform time remapping for x-coordinate (if necessary) */ - if ((sipo) && (sipo->mode == SIPO_MODE_DRIVERS)) + if ((sipo) && (sipo->mode == SIPO_MODE_DRIVERS)) { x = sipo->cursorTime; - else if (adt) + } + else if (adt) { x = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP); - else + } + else { x = (float)CFRA; + } /* normalise units of cursor's value */ - if (sipo) + if (sipo) { y = (sipo->cursorVal / unit_scale) - offset; - else + } + else { y = 0.0f; + } /* insert keyframe directly into the F-Curve */ insert_vert_fcurve(fcu, x, y, ts->keyframe_type, 0); @@ -638,13 +673,17 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) FCurve *fcu = (FCurve *)ale->key_data; float cfra = (float)CFRA; - /* read value from property the F-Curve represents, or from the curve only? - * - ale->id != NULL: Typically, this means that we have enough info to try resolving the path - * - ale->owner != NULL: If this is set, then the path may not be resolvable from the ID alone, - * so it's easier for now to just read the F-Curve directly. - * (TODO: add the full-blown PointerRNA relative parsing case here...) - * - fcu->driver != NULL: If this is set, then it's a driver. If we don't check for this, we'd end - * up adding the keyframes on a new F-Curve in the action data instead. + /* Read value from property the F-Curve represents, or from the curve only? + * + * - ale->id != NULL: + * Typically, this means that we have enough info to try resolving the path. + * - ale->owner != NULL: + * If this is set, then the path may not be resolvable from the ID alone, + * so it's easier for now to just read the F-Curve directly. + * (TODO: add the full-blown PointerRNA relative parsing case here...) + * - fcu->driver != NULL: + * If this is set, then it's a driver. If we don't check for this, we'd end + * up adding the keyframes on a new F-Curve in the action data instead. */ if (ale->id && !ale->owner && !fcu->driver) { insert_keyframe(ac->bmain, @@ -664,10 +703,12 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* adjust current frame for NLA-mapping */ - if ((sipo) && (sipo->mode == SIPO_MODE_DRIVERS)) + if ((sipo) && (sipo->mode == SIPO_MODE_DRIVERS)) { cfra = sipo->cursorTime; - else if (adt) + } + else if (adt) { cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP); + } const float curval = evaluate_fcurve_only_curve(fcu, cfra); insert_vert_fcurve(fcu, cfra, curval, ts->keyframe_type, 0); @@ -691,8 +732,9 @@ static int graphkeys_insertkey_exec(bContext *C, wmOperator *op) eGraphKeys_InsertKey_Types mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* which channels to affect? */ mode = RNA_enum_get(op->ptr, "type"); @@ -736,14 +778,16 @@ static int graphkeys_click_insert_exec(bContext *C, wmOperator *op) float frame, val; /* get animation context */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get active F-Curve 'anim-list-element' */ ale = get_active_fcurve_channel(&ac); if (ELEM(NULL, ale, ale->data)) { - if (ale) + if (ale) { MEM_freeN(ale); + } return OPERATOR_CANCELLED; } fcu = ale->data; @@ -760,9 +804,9 @@ static int graphkeys_click_insert_exec(bContext *C, wmOperator *op) /* preserve selection? */ if (RNA_boolean_get(op->ptr, "extend") == false) { - /* deselect all keyframes first, so that we can immediately start manipulating the newly added one(s) - * - only affect the keyframes themselves, as we don't want channels popping in and out... - */ + /* Deselect all keyframes first, + * so that we can immediately start manipulating the newly added one(s) + * - only affect the keyframes themselves, as we don't want channels popping in and out. */ deselect_graph_keys(&ac, false, SELECT_SUBTRACT, false); } @@ -792,12 +836,15 @@ static int graphkeys_click_insert_exec(bContext *C, wmOperator *op) } else { /* warn about why this can't happen */ - if (fcu->fpt) + if (fcu->fpt) { BKE_report(op->reports, RPT_ERROR, "Keyframes cannot be added to sampled F-Curves"); - else if (fcu->flag & FCURVE_PROTECTED) + } + else if (fcu->flag & FCURVE_PROTECTED) { BKE_report(op->reports, RPT_ERROR, "Active F-Curve is not editable"); - else + } + else { BKE_report(op->reports, RPT_ERROR, "Remove F-Modifiers from F-Curve to add keyframes"); + } } /* free temp data */ @@ -819,8 +866,9 @@ static int graphkeys_click_insert_invoke(bContext *C, wmOperator *op, const wmEv float x, y; /* get animation context */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* store mouse coordinates in View2D space, into the operator's properties */ ar = ac.ar; @@ -884,9 +932,15 @@ static short copy_graph_keys(bAnimContext *ac) /* clear buffer first */ ANIM_fcurves_copybuf_free(); - /* filter data */ + /* filter data + * - First time we try to filter more strictly, allowing only selected channels + * to allow copying animation between channels + */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); - ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); + + if (ANIM_animdata_filter(ac, &anim_data, filter | ANIMFILTER_SEL, ac->data, ac->datatype) == 0) { + ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); + } /* copy keyframes */ ok = copy_animedit_keys(ac, &anim_data); @@ -914,8 +968,9 @@ static short paste_graph_keys(bAnimContext *ac, filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS); - if (ANIM_animdata_filter(ac, &anim_data, filter | ANIMFILTER_SEL, ac->data, ac->datatype) == 0) + if (ANIM_animdata_filter(ac, &anim_data, filter | ANIMFILTER_SEL, ac->data, ac->datatype) == 0) { ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); + } /* paste keyframes */ ok = paste_animedit_keys(ac, &anim_data, offset_mode, merge_mode, flip); @@ -933,8 +988,9 @@ static int graphkeys_copy_exec(bContext *C, wmOperator *op) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* copy keyframes */ if (copy_graph_keys(&ac)) { @@ -970,8 +1026,9 @@ static int graphkeys_paste_exec(bContext *C, wmOperator *op) const bool flipped = RNA_boolean_get(op->ptr, "flipped"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* ac.reports by default will be the global reports list, which won't show warnings */ ac.reports = op->reports; @@ -1055,8 +1112,9 @@ static int graphkeys_duplicate_exec(bContext *C, wmOperator *UNUSED(op)) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* duplicate keyframes */ duplicate_graph_keys(&ac); @@ -1135,12 +1193,14 @@ static int graphkeys_delete_exec(bContext *C, wmOperator *UNUSED(op)) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* delete keyframes */ - if (!delete_graph_keys(&ac)) + if (!delete_graph_keys(&ac)) { return OPERATOR_CANCELLED; + } /* set notifier that keyframes have changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, NULL); @@ -1197,8 +1257,9 @@ static int graphkeys_clean_exec(bContext *C, wmOperator *op) bool clean_chan; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get cleaning threshold */ thresh = RNA_float_get(op->ptr, "threshold"); @@ -1220,7 +1281,7 @@ void GRAPH_OT_clean(wmOperatorType *ot) ot->description = "Simplify F-Curves by removing closely spaced keyframes"; /* api callbacks */ - //ot->invoke = // XXX we need that number popup for this! + // ot->invoke = // XXX we need that number popup for this! ot->exec = graphkeys_clean_exec; ot->poll = graphop_editable_keyframes_poll; @@ -1278,8 +1339,9 @@ static int graphkeys_bake_exec(bContext *C, wmOperator *UNUSED(op)) int start, end; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* for now, init start/end from preview-range extents */ // TODO: add properties for this @@ -1341,8 +1403,9 @@ static float fcurve_samplingcb_sound(FCurve *UNUSED(fcu), void *data, float eval tSoundBakeInfo *sbi = (tSoundBakeInfo *)data; int position = evaltime - sbi->cfra; - if ((position < 0) || (position >= sbi->length)) + if ((position < 0) || (position >= sbi->length)) { return 0.0f; + } return sbi->samples[position]; } @@ -1363,8 +1426,9 @@ static int graphkeys_sound_bake_exec(bContext *C, wmOperator *op) char path[FILE_MAX]; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } RNA_string_get(op->ptr, "filepath", path); @@ -1426,7 +1490,7 @@ static int graphkeys_sound_bake_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -#else //WITH_AUDASPACE +#else // WITH_AUDASPACE static int graphkeys_sound_bake_exec(bContext *UNUSED(C), wmOperator *op) { @@ -1435,15 +1499,16 @@ static int graphkeys_sound_bake_exec(bContext *UNUSED(C), wmOperator *op) return OPERATOR_CANCELLED; } -#endif //WITH_AUDASPACE +#endif // WITH_AUDASPACE static int graphkeys_sound_bake_invoke(bContext *C, wmOperator *op, const wmEvent *event) { bAnimContext ac; /* verify editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } return WM_operator_filesel(C, op, event); } @@ -1583,8 +1648,9 @@ static int graphkeys_sample_exec(bContext *C, wmOperator *UNUSED(op)) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* sample keyframes */ sample_graph_keys(&ac); @@ -1685,8 +1751,9 @@ static void setexpo_graph_keys(bAnimContext *ac, short mode) for (fcm = fcu->modifiers.first; fcm; fcm = fcn) { fcn = fcm->next; - if (fcm->type == FMODIFIER_TYPE_CYCLES) + if (fcm->type == FMODIFIER_TYPE_CYCLES) { remove_fmodifier(&fcu->modifiers, fcm); + } } } } @@ -1706,8 +1773,9 @@ static int graphkeys_expo_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get handle setting mode */ mode = RNA_enum_get(op->ptr, "type"); @@ -1755,8 +1823,9 @@ static void setipo_graph_keys(bAnimContext *ac, short mode) ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - /* loop through setting BezTriple interpolation - * Note: we do not supply KeyframeEditData to the looper yet. Currently that's not necessary here... + /* Loop through setting BezTriple interpolation + * Note: we do not supply KeyframeEditData to the looper yet. + * Currently that's not necessary here. */ for (ale = anim_data.first; ale; ale = ale->next) { ANIM_fcurve_keyframes_loop(NULL, ale->key_data, NULL, set_cb, calchandles_fcurve); @@ -1776,8 +1845,9 @@ static int graphkeys_ipo_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get handle setting mode */ mode = RNA_enum_get(op->ptr, "type"); @@ -1826,8 +1896,9 @@ static void seteasing_graph_keys(bAnimContext *ac, short mode) ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - /* loop through setting BezTriple easing - * Note: we do not supply KeyframeEditData to the looper yet. Currently that's not necessary here... + /* Loop through setting BezTriple easing. + * Note: we do not supply KeyframeEditData to the looper yet. + * Currently that's not necessary here. */ for (ale = anim_data.first; ale; ale = ale->next) { ANIM_fcurve_keyframes_loop(NULL, ale->key_data, NULL, set_cb, calchandles_fcurve); @@ -1845,8 +1916,9 @@ static int graphkeys_easing_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get handle setting mode */ mode = RNA_enum_get(op->ptr, "type"); @@ -1898,8 +1970,9 @@ static void sethandles_graph_keys(bAnimContext *ac, short mode) ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - /* loop through setting flags for handles - * Note: we do not supply KeyframeEditData to the looper yet. Currently that's not necessary here... + /* Loop through setting flags for handles. + * Note: we do not supply KeyframeEditData to the looper yet. + * Currently that's not necessary here. */ for (ale = anim_data.first; ale; ale = ale->next) { FCurve *fcu = (FCurve *)ale->key_data; @@ -1924,8 +1997,9 @@ static int graphkeys_handletype_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get handle setting mode */ mode = RNA_enum_get(op->ptr, "type"); @@ -1993,8 +2067,9 @@ static int graphkeys_euler_filter_exec(bContext *C, wmOperator *op) int groups = 0, failed = 0; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* The process is done in two passes: * 1) Sets of three related rotation curves are identified from the selected channels, @@ -2015,8 +2090,9 @@ static int graphkeys_euler_filter_exec(bContext *C, wmOperator *op) * - only rotation curves * - for pchan curves, make sure we're only using the euler curves */ - if (strstr(fcu->rna_path, "rotation_euler") == NULL) + if (strstr(fcu->rna_path, "rotation_euler") == NULL) { continue; + } else if (ELEM(fcu->array_index, 0, 1, 2) == 0) { BKE_reportf(op->reports, RPT_WARNING, @@ -2081,16 +2157,19 @@ static int graphkeys_euler_filter_exec(bContext *C, wmOperator *op) continue; } - /* simple method: just treat any difference between keys of greater than 180 degrees as being a flip */ - /* FIXME: there are more complicated methods that will be needed to fix more cases than just some */ + /* Simple method: just treat any difference between + * keys of greater than 180 degrees as being a flip. */ + /* FIXME: there are more complicated methods that + * will be needed to fix more cases than just some */ for (f = 0; f < 3; f++) { FCurve *fcu = euf->fcurves[f]; BezTriple *bezt, *prev; unsigned int i; /* skip if not enough vets to do a decent analysis of... */ - if (fcu->totvert <= 2) + if (fcu->totvert <= 2) { continue; + } /* prev follows bezt, bezt = "current" point to be fixed */ /* our method depends on determining a "difference" from the previous vert */ @@ -2168,8 +2247,9 @@ void GRAPH_OT_euler_filter(wmOperatorType *ot) static bool graphkeys_framejump_poll(bContext *C) { /* prevent changes during render */ - if (G.is_rendering) + if (G.is_rendering) { return 0; + } return graphop_visible_keyframes_poll(C); } @@ -2184,8 +2264,9 @@ static int graphkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op)) KeyframeEditData ked; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* init edit data */ memset(&ked, 0, sizeof(KeyframeEditData)); @@ -2209,8 +2290,9 @@ static int graphkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op)) ANIM_fcurve_keyframes_loop(¤t_ked, ale->key_data, NULL, bezt_calc_average, NULL); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } - else + else { ANIM_fcurve_keyframes_loop(¤t_ked, ale->key_data, NULL, bezt_calc_average, NULL); + } ked.f1 += current_ked.f1; ked.i1 += current_ked.i1; @@ -2358,8 +2440,9 @@ static void snap_graph_keys(bAnimContext *ac, short mode) ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0); } - else + else { ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve); + } ale->update |= ANIM_UPDATE_DEFAULT; } @@ -2376,8 +2459,9 @@ static int graphkeys_snap_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get snapping mode */ mode = RNA_enum_get(op->ptr, "type"); @@ -2467,10 +2551,12 @@ static void mirror_graph_keys(bAnimContext *ac, short mode) marker = ED_markers_get_first_selected(ac->markers); /* store marker's time (if available) */ - if (marker) + if (marker) { ked.f1 = (float)marker->frame; - else + } + else { return; + } } else if (mode == GRAPHKEYS_MIRROR_VALUE) { cursor_value = (sipo) ? sipo->cursorVal : 0.0f; @@ -2513,8 +2599,9 @@ static void mirror_graph_keys(bAnimContext *ac, short mode) ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0); } - else + else { ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve); + } ale->update |= ANIM_UPDATE_DEFAULT; } @@ -2531,8 +2618,9 @@ static int graphkeys_mirror_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get mirroring mode */ mode = RNA_enum_get(op->ptr, "type"); @@ -2575,8 +2663,9 @@ static int graphkeys_smooth_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT | @@ -2642,8 +2731,9 @@ static const EnumPropertyItem *graph_fmodifier_itemf(bContext *C, int index; /* check if modifier is valid for this context */ - if (fmi == NULL) + if (fmi == NULL) { continue; + } index = RNA_enum_from_value(rna_enum_fmodifier_type_items, fmi->type); if (index != -1) { /* Not all types are implemented yet... */ @@ -2666,19 +2756,22 @@ static int graph_fmodifier_add_exec(bContext *C, wmOperator *op) short type; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get type of modifier to add */ type = RNA_enum_get(op->ptr, "type"); /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS); - if (RNA_boolean_get(op->ptr, "only_active")) + if (RNA_boolean_get(op->ptr, "only_active")) { filter |= ANIMFILTER_ACTIVE; // FIXME: enforce in this case only a single channel to get handled? - else + } + else { filter |= (ANIMFILTER_SEL | ANIMFILTER_CURVE_VISIBLE); + } ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* add f-modifier to each curve */ @@ -2743,8 +2836,9 @@ static int graph_fmodifier_copy_exec(bContext *C, wmOperator *op) bool ok = false; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* clear buffer first */ ANIM_fmodifiers_copybuf_free(); @@ -2768,8 +2862,9 @@ static int graph_fmodifier_copy_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "No F-Modifiers available to be copied"); return OPERATOR_CANCELLED; } - else + else { return OPERATOR_FINISHED; + } } void GRAPH_OT_fmodifier_copy(wmOperatorType *ot) @@ -2787,7 +2882,13 @@ void GRAPH_OT_fmodifier_copy(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* id-props */ - //ot->prop = RNA_def_boolean(ot->srna, "all", 1, "All F-Modifiers", "Copy all the F-Modifiers, instead of just the active one"); +#if 0 + ot->prop = RNA_def_boolean(ot->srna, + "all", + 1, + "All F-Modifiers", + "Copy all the F-Modifiers, instead of just the active one"); +#endif } /* ******************** Paste F-Modifiers Operator *********************** */ @@ -2804,8 +2905,9 @@ static int graph_fmodifier_paste_exec(bContext *C, wmOperator *op) bool ok = false; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* filter data */ if (RNA_boolean_get(op->ptr, "only_active")) { @@ -2814,7 +2916,8 @@ static int graph_fmodifier_paste_exec(bContext *C, wmOperator *op) ANIMFILTER_NODUPLIS); } else { - /* This is only if the operator gets called from a hotkey or search - Paste to all visible curves */ + /* This is only if the operator gets called from a hotkey or search - + * Paste to all visible curves. */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS); } @@ -2889,8 +2992,9 @@ static int graph_driver_vars_copy_exec(bContext *C, wmOperator *op) bool ok = false; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* clear buffer first */ ANIM_driver_vars_copybuf_free(); @@ -2909,10 +3013,12 @@ static int graph_driver_vars_copy_exec(bContext *C, wmOperator *op) } /* successful or not? */ - if (ok) + if (ok) { return OPERATOR_FINISHED; - else + } + else { return OPERATOR_CANCELLED; + } } void GRAPH_OT_driver_variables_copy(wmOperatorType *ot) @@ -2944,8 +3050,9 @@ static int graph_driver_vars_paste_exec(bContext *C, wmOperator *op) bool ok = false; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* filter data */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ACTIVE | ANIMFILTER_FOREDIT | @@ -3011,8 +3118,9 @@ static int graph_driver_delete_invalid_exec(bContext *C, wmOperator *op) unsigned int deleted = 0; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* NOTE: we might need a scene update to evaluate the driver flags */ @@ -3064,8 +3172,9 @@ static bool graph_driver_delete_invalid_poll(bContext *C) ScrArea *sa = CTX_wm_area(C); /* firstly, check if in Graph Editor */ - if ((sa == NULL) || (sa->spacetype != SPACE_GRAPH)) + if ((sa == NULL) || (sa->spacetype != SPACE_GRAPH)) { return 0; + } /* try to init Anim-Context stuff ourselves and check */ return ANIM_animdata_get_context(C, &ac) != 0; diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index 7d0a3a1f13d..6ec8e54dce9 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -28,7 +28,6 @@ struct ARegion; struct ARegionType; struct ScrArea; struct SpaceGraph; -struct View2DGrid; struct bAnimContext; struct bAnimListElem; struct bContext; @@ -36,17 +35,12 @@ struct bContext; /* internal exports only */ /* ***************************************** */ -/* space_graph.c */ -struct ARegion *graph_has_buttons_region(struct ScrArea *sa); - -/* ***************************************** */ /* graph_draw.c */ void graph_draw_channel_names(struct bContext *C, struct bAnimContext *ac, struct ARegion *ar); void graph_draw_curves(struct bAnimContext *ac, struct SpaceGraph *sipo, struct ARegion *ar, - struct View2DGrid *grid, short sel); void graph_draw_ghost_curves(struct bAnimContext *ac, struct SpaceGraph *sipo, struct ARegion *ar); @@ -164,7 +158,6 @@ void GRAPH_OT_ghost_curves_clear(struct wmOperatorType *ot); /* ***************************************** */ /* graph_buttons.c */ -void GRAPH_OT_properties(struct wmOperatorType *ot); void graph_buttons_register(struct ARegionType *art); /* ***************************************** */ diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index 6bbc6a2de1c..5c7035a4c04 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -64,8 +64,9 @@ static bool graphview_cursor_poll(bContext *C) { /* prevent changes during render */ - if (G.is_rendering) + if (G.is_rendering) { return 0; + } return ED_operator_graphedit_active(C); } @@ -132,8 +133,9 @@ static void graphview_cursor_setprops(bContext *C, wmOperator *op, const wmEvent float viewx, viewy; /* abort if not active region (should not really be possible) */ - if (ar == NULL) + if (ar == NULL) { return; + } /* convert from region coordinates to View2D 'tot' space */ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &viewx, &viewy); @@ -157,8 +159,9 @@ static int graphview_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *e graphview_cursor_apply(C, op); /* Signal that a scrubbing operating is starting */ - if (screen) + if (screen) { screen->scrubbing = true; + } /* add temp handler */ WM_event_add_modal_handler(C, op); @@ -174,8 +177,9 @@ static int graphview_cursor_modal(bContext *C, wmOperator *op, const wmEvent *ev /* execute the events */ switch (event->type) { case ESCKEY: - if (screen) + if (screen) { screen->scrubbing = false; + } WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); return OPERATOR_FINISHED; @@ -191,8 +195,9 @@ static int graphview_cursor_modal(bContext *C, wmOperator *op, const wmEvent *ev case MIDDLEMOUSE: /* We check for either mouse-button to end, to work with all user keymaps. */ if (event->val == KM_RELEASE) { - if (screen) + if (screen) { screen->scrubbing = false; + } WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); return OPERATOR_FINISHED; @@ -236,8 +241,9 @@ static int graphview_curves_hide_exec(bContext *C, wmOperator *op) const bool unselected = RNA_boolean_get(op->ptr, "unselected"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get list of all channels that selection may need to be flushed to * - hierarchy must not affect what we have access to here... @@ -250,10 +256,12 @@ static int graphview_curves_hide_exec(bContext *C, wmOperator *op) * selected/unselected (depending on "unselected" prop) */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); - if (unselected) + if (unselected) { filter |= ANIMFILTER_UNSEL; - else + } + else { filter |= ANIMFILTER_SEL; + } ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); @@ -261,8 +269,9 @@ static int graphview_curves_hide_exec(bContext *C, wmOperator *op) /* hack: skip object channels for now, since flushing those will always flush everything, * but they are always included */ /* TODO: find out why this is the case, and fix that */ - if (ale->type == ANIMTYPE_OBJECT) + if (ale->type == ANIMTYPE_OBJECT) { continue; + } /* change the hide setting, and unselect it... */ ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_CLEAR); @@ -290,8 +299,9 @@ static int graphview_curves_hide_exec(bContext *C, wmOperator *op) * will always flush everything, but they are always included */ /* TODO: find out why this is the case, and fix that */ - if (ale->type == ANIMTYPE_OBJECT) + if (ale->type == ANIMTYPE_OBJECT) { continue; + } /* change the hide setting, and unselect it... */ ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_ADD); @@ -341,8 +351,9 @@ static int graphview_curves_reveal_exec(bContext *C, wmOperator *op) const bool select = RNA_boolean_get(op->ptr, "select"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get list of all channels that selection may need to be flushed to * - hierarchy must not affect what we have access to here... @@ -360,8 +371,9 @@ static int graphview_curves_reveal_exec(bContext *C, wmOperator *op) /* hack: skip object channels for now, since flushing those will always flush everything, * but they are always included. */ /* TODO: find out why this is the case, and fix that */ - if (ale->type == ANIMTYPE_OBJECT) + if (ale->type == ANIMTYPE_OBJECT) { continue; + } /* select if it is not visible */ if (ANIM_channel_setting_get(&ac, ale, ACHANNEL_SETTING_VISIBLE) == 0) { @@ -415,7 +427,6 @@ void graphedit_operatortypes(void) WM_operatortype_append(GRAPH_OT_previewrange_set); WM_operatortype_append(GRAPH_OT_view_all); WM_operatortype_append(GRAPH_OT_view_selected); - WM_operatortype_append(GRAPH_OT_properties); WM_operatortype_append(GRAPH_OT_view_frame); WM_operatortype_append(GRAPH_OT_ghost_curves_create); @@ -483,7 +494,7 @@ void ED_operatormacros_graph(void) WM_operatortype_macro_define(ot, "GRAPH_OT_duplicate"); otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_transform"); RNA_enum_set(otmacro->ptr, "mode", TFM_TIME_DUPLICATE); - RNA_enum_set(otmacro->ptr, "proportional", PROP_EDIT_OFF); + RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false); } /* ************************** registration - keymaps **********************************/ @@ -494,9 +505,11 @@ void graphedit_keymap(wmKeyConfig *keyconf) WM_keymap_ensure(keyconf, "Graph Editor Generic", SPACE_GRAPH, 0); /* channels */ - /* Channels are not directly handled by the Graph Editor module, but are inherited from the Animation module. - * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these - * are all used for the Graph Editor too. + /* Channels are not directly handled by the Graph Editor module, + * but are inherited from the Animation module. + * All the relevant operations, keymaps, drawing, etc. + * can therefore all be found in that module instead, + * as these are all used for the Graph Editor too. */ /* keyframes */ diff --git a/source/blender/editors/space_graph/graph_select.c b/source/blender/editors/space_graph/graph_select.c index a109282978c..13a42f091f6 100644 --- a/source/blender/editors/space_graph/graph_select.c +++ b/source/blender/editors/space_graph/graph_select.c @@ -117,15 +117,18 @@ void deselect_graph_keys(bAnimContext *ac, bool test, short sel, bool do_channel /* affect channel selection status? */ if (do_channels) { - /* only change selection of channel when the visibility of keyframes doesn't depend on this */ + /* Only change selection of channel when the visibility of keyframes + * doesn't depend on this. */ if ((sipo->flag & SIPO_SELCUVERTSONLY) == 0) { /* deactivate the F-Curve, and deselect if deselecting keyframes. * otherwise select the F-Curve too since we've selected all the keyframes */ - if (sel == SELECT_SUBTRACT) + if (sel == SELECT_SUBTRACT) { fcu->flag &= ~FCURVE_SELECTED; - else + } + else { fcu->flag |= FCURVE_SELECTED; + } } /* always deactivate all F-Curves if we perform batch ops for selection */ @@ -145,8 +148,9 @@ static int graphkeys_deselectall_exec(bContext *C, wmOperator *op) bAnimListElem *ale_active = NULL; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* find active F-Curve, and preserve this for later * or else it becomes annoying with the current active @@ -216,7 +220,8 @@ void GRAPH_OT_select_all(wmOperatorType *ot) * -> BKEY - 1) all keyframes within region are selected (validation with BEZT_OK_REGION) * -> ALT-BKEY - depending on which axis of the region was larger... * -> 2) x-axis, so select all frames within frame range (validation with BEZT_OK_FRAMERANGE) - * -> 3) y-axis, so select all frames within channels that region included (validation with BEZT_OK_VALUERANGE) + * -> 3) y-axis, so select all frames within channels that region included + * (validation with BEZT_OK_VALUERANGE). * * The selection backend is also reused for the Lasso and Circle select operators. */ @@ -243,7 +248,8 @@ static void box_select_graphkeys(bAnimContext *ac, View2D *v2d = &ac->ar->v2d; rctf rectf, scaled_rectf; - /* convert mouse coordinates to frame ranges and channel coordinates corrected for view pan/zoom */ + /* Convert mouse coordinates to frame ranges and + * channel coordinates corrected for view pan/zoom. */ UI_view2d_region_to_view_rctf(v2d, rectf_view, &rectf); /* filter data */ @@ -275,8 +281,9 @@ static void box_select_graphkeys(bAnimContext *ac, ked.iterflags |= KEYFRAME_ITER_INCL_HANDLES; mapping_flag = 0; } - else + else { mapping_flag = ANIM_UNITCONV_ONLYKEYS; + } mapping_flag |= ANIM_get_normalization_flags(ac); @@ -291,8 +298,9 @@ static void box_select_graphkeys(bAnimContext *ac, /* apply NLA mapping to all the keyframes, since it's easier than trying to * guess when a callback might use something different */ - if (adt) + if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, incl_handles == 0); + } scaled_rectf.xmin = rectf.xmin; scaled_rectf.xmax = rectf.xmax; @@ -317,17 +325,20 @@ static void box_select_graphkeys(bAnimContext *ac, /* select keyframes that are in the appropriate places */ ANIM_fcurve_keyframes_loop(&ked, fcu, ok_cb, select_cb, NULL); - /* only change selection of channel when the visibility of keyframes doesn't depend on this */ + /* Only change selection of channel when the visibility of keyframes + * doesn't depend on this. */ if ((sipo->flag & SIPO_SELCUVERTSONLY) == 0) { /* select the curve too now that curve will be touched */ - if (selectmode == SELECT_ADD) + if (selectmode == SELECT_ADD) { fcu->flag |= FCURVE_SELECTED; + } } } /* un-apply NLA mapping from all the keyframes */ - if (adt) + if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, incl_handles == 0); + } } /* cleanup */ @@ -344,8 +355,9 @@ static int graphkeys_box_select_exec(bContext *C, wmOperator *op) short mode = 0; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); const int selectmode = (sel_op != SEL_OP_SUB) ? SELECT_ADD : SELECT_SUBTRACT; @@ -362,17 +374,22 @@ static int graphkeys_box_select_exec(bContext *C, wmOperator *op) /* selection 'mode' depends on whether box_select region only matters on one axis */ if (RNA_boolean_get(op->ptr, "axis_range")) { /* mode depends on which axis of the range is larger to determine which axis to use - * - checking this in region-space is fine, as it's fundamentally still going to be a different rect size - * - the frame-range select option is favored over the channel one (x over y), as frame-range one is often - * used for tweaking timing when "blocking", while channels is not that useful... + * - Checking this in region-space is fine, as it's fundamentally still going to be a + * different rect size. + * - The frame-range select option is favored over the channel one (x over y), + * as frame-range one is often used for tweaking timing when "blocking", + * while channels is not that useful. */ - if ((BLI_rcti_size_x(&rect)) >= (BLI_rcti_size_y(&rect))) + if ((BLI_rcti_size_x(&rect)) >= (BLI_rcti_size_y(&rect))) { mode = BEZT_OK_FRAMERANGE; - else + } + else { mode = BEZT_OK_VALUERANGE; + } } - else + else { mode = BEZT_OK_REGION; + } BLI_rctf_rcti_copy(&rect_fl, &rect); @@ -428,13 +445,15 @@ static int graphkeys_lassoselect_exec(bContext *C, wmOperator *op) bool incl_handles; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } data_lasso.rectf_view = &rect_fl; data_lasso.mcords = WM_gesture_lasso_path_to_array(C, op, &data_lasso.mcords_tot); - if (data_lasso.mcords == NULL) + if (data_lasso.mcords == NULL) { return OPERATOR_CANCELLED; + } const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); const short selectmode = (sel_op != SEL_OP_SUB) ? SELECT_ADD : SELECT_SUBTRACT; @@ -504,8 +523,9 @@ static int graph_circle_select_exec(bContext *C, wmOperator *op) float radius = RNA_int_get(op->ptr, "radius"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } const eSelectOp sel_op = ED_select_op_modal(RNA_enum_get(op->ptr, "mode"), WM_gesture_is_modal_first(op->customdata)); @@ -654,8 +674,9 @@ static void columnselect_graph_keys(bAnimContext *ac, short mode) filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - for (ale = anim_data.first; ale; ale = ale->next) + for (ale = anim_data.first; ale; ale = ale->next) { ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_to_cfraelem, NULL); + } ANIM_animdata_freelist(&anim_data); break; @@ -714,16 +735,19 @@ static int graphkeys_columnselect_exec(bContext *C, wmOperator *op) short mode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* action to take depends on the mode */ mode = RNA_enum_get(op->ptr, "mode"); - if (mode == GRAPHKEYS_COLUMNSEL_MARKERS_BETWEEN) + if (mode == GRAPHKEYS_COLUMNSEL_MARKERS_BETWEEN) { markers_selectkeys_between(&ac); - else + } + else { columnselect_graph_keys(&ac, mode); + } /* set notifier that keyframe selection has changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); @@ -763,8 +787,9 @@ static int graphkeys_select_linked_exec(bContext *C, wmOperator *UNUSED(op)) KeyframeEditFunc sel_cb = ANIM_editkeyframes_select(SELECT_ADD); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* loop through all of the keys and select additional keyframes based on these */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); @@ -828,8 +853,9 @@ static void select_moreless_graph_keys(bAnimContext *ac, short mode) FCurve *fcu = (FCurve *)ale->key_data; /* only continue if F-Curve has keyframes */ - if (fcu->bezt == NULL) + if (fcu->bezt == NULL) { continue; + } /* build up map of whether F-Curve's keyframes should be selected or not */ ked.data = MEM_callocN(fcu->totvert, "selmap graphEdit"); @@ -854,8 +880,9 @@ static int graphkeys_select_more_exec(bContext *C, wmOperator *UNUSED(op)) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* perform select changes */ select_moreless_graph_keys(&ac, SELMAP_MORE); @@ -888,8 +915,9 @@ static int graphkeys_select_less_exec(bContext *C, wmOperator *UNUSED(op)) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* perform select changes */ select_moreless_graph_keys(&ac, SELMAP_LESS); @@ -974,8 +1002,9 @@ static void graphkeys_select_leftright(bAnimContext *ac, short leftright, short ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); } - else + else { ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); + } } /* Cleanup */ @@ -991,18 +1020,22 @@ static int graphkeys_select_leftright_exec(bContext *C, wmOperator *op) short selectmode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* select mode is either replace (deselect all, then add) or add/extend */ - if (RNA_boolean_get(op->ptr, "extend")) + if (RNA_boolean_get(op->ptr, "extend")) { selectmode = SELECT_INVERT; - else + } + else { selectmode = SELECT_REPLACE; + } /* if "test" mode is set, we don't have any info to set this with */ - if (leftright == GRAPHKEYS_LRSEL_TEST) + if (leftright == GRAPHKEYS_LRSEL_TEST) { return OPERATOR_CANCELLED; + } /* do the selecting now */ graphkeys_select_leftright(&ac, leftright, selectmode); @@ -1020,8 +1053,9 @@ static int graphkeys_select_leftright_invoke(bContext *C, wmOperator *op, const short leftright = RNA_enum_get(op->ptr, "mode"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* handle mode-based testing */ if (leftright == GRAPHKEYS_LRSEL_TEST) { @@ -1032,10 +1066,12 @@ static int graphkeys_select_leftright_invoke(bContext *C, wmOperator *op, const /* determine which side of the current frame mouse is on */ x = UI_view2d_region_to_view_x(v2d, event->mval[0]); - if (x < CFRA) + if (x < CFRA) { RNA_enum_set(op->ptr, "mode", GRAPHKEYS_LRSEL_LEFT); - else + } + else { RNA_enum_set(op->ptr, "mode", GRAPHKEYS_LRSEL_RIGHT); + } } /* perform selection */ @@ -1113,10 +1149,12 @@ typedef enum eGraphVertIndex { // XXX also need to check for int-values only? static bool fcurve_handle_sel_check(SpaceGraph *sipo, BezTriple *bezt) { - if (sipo->flag & SIPO_NOHANDLES) + if (sipo->flag & SIPO_NOHANDLES) { return 0; - if ((sipo->flag & SIPO_SELVHANDLESONLY) && BEZT_ISSEL_ANY(bezt) == 0) + } + if ((sipo->flag & SIPO_SELVHANDLESONLY) && BEZT_ISSEL_ANY(bezt) == 0) { return 0; + } return 1; } @@ -1152,15 +1190,18 @@ static void nearest_fcurve_vert_store(ListBase *matches, tNearestVertInfo *nvi = (tNearestVertInfo *)matches->last; bool replace = false; - /* if there is already a point for the F-Curve, check if this point is closer than that was */ + /* If there is already a point for the F-Curve, + * check if this point is closer than that was. */ if ((nvi) && (nvi->fcu == fcu)) { /* replace if we are closer, or if equal and that one wasn't selected but we are... */ - if ((nvi->dist > dist) || ((nvi->sel == 0) && BEZT_ISSEL_ANY(bezt))) + if ((nvi->dist > dist) || ((nvi->sel == 0) && BEZT_ISSEL_ANY(bezt))) { replace = 1; + } } /* add new if not replacing... */ - if (replace == 0) + if (replace == 0) { nvi = MEM_callocN(sizeof(tNearestVertInfo), "Nearest Graph Vert Info - Bezt"); + } /* store values */ nvi->fcu = fcu; @@ -1175,8 +1216,9 @@ static void nearest_fcurve_vert_store(ListBase *matches, nvi->sel = BEZT_ISSEL_ANY(bezt); // XXX... should this use the individual verts instead? /* add to list of matches if appropriate... */ - if (replace == 0) + if (replace == 0) { BLI_addtail(matches, nvi); + } } } else if (fpt) { @@ -1201,8 +1243,9 @@ static void get_nearest_fcurve_verts_list(bAnimContext *ac, const int mval[2], L */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS); if (sipo->flag & - SIPO_SELCUVERTSONLY) // FIXME: this should really be check for by the filtering code... + SIPO_SELCUVERTSONLY) { // FIXME: this should really be check for by the filtering code... filter |= ANIMFILTER_SEL; + } mapping_flag |= ANIM_get_normalization_flags(ac); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); @@ -1214,8 +1257,9 @@ static void get_nearest_fcurve_verts_list(bAnimContext *ac, const int mval[2], L ac->scene, ale->id, fcu, mapping_flag, &offset); /* apply NLA mapping to all the keyframes */ - if (adt) + if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0); + } if (fcu->bezt) { BezTriple *bezt1 = fcu->bezt, *prevbezt = NULL; @@ -1272,8 +1316,9 @@ static void get_nearest_fcurve_verts_list(bAnimContext *ac, const int mval[2], L } /* un-apply NLA mapping from all the keyframes */ - if (adt) + if (adt) { ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0); + } } /* free channels */ @@ -1287,8 +1332,9 @@ static tNearestVertInfo *get_best_nearest_fcurve_vert(ListBase *matches) short found = 0; /* abort if list is empty */ - if (BLI_listbase_is_empty(matches)) + if (BLI_listbase_is_empty(matches)) { return NULL; + } /* if list only has 1 item, remove it from the list and return */ if (BLI_listbase_is_single(matches)) { @@ -1300,16 +1346,18 @@ static tNearestVertInfo *get_best_nearest_fcurve_vert(ListBase *matches) for (nvi = matches->first; nvi; nvi = nvi->next) { /* which mode of search are we in: find first selected, or find vert? */ if (found) { - /* just take this vert now that we've found the selected one - * - we'll need to remove this from the list so that it can be returned to the original caller + /* Just take this vert now that we've found the selected one + * - We'll need to remove this from the list + * so that it can be returned to the original caller. */ BLI_remlink(matches, nvi); return nvi; } else { /* if vert is selected, we've got what we want... */ - if (nvi->sel) + if (nvi->sel) { found = 1; + } } } @@ -1319,8 +1367,11 @@ static tNearestVertInfo *get_best_nearest_fcurve_vert(ListBase *matches) return BLI_pophead(matches); } -/* Find the nearest vertices (either a handle or the keyframe) that are nearest to the mouse cursor (in area coordinates) - * NOTE: the match info found must still be freed +/** + * Find the nearest vertices (either a handle or the keyframe) + * that are nearest to the mouse cursor (in area coordinates) + * + * \note the match info found must still be freed. */ static tNearestVertInfo *find_nearest_fcurve_vert(bAnimContext *ac, const int mval[2]) { @@ -1345,7 +1396,8 @@ static tNearestVertInfo *find_nearest_fcurve_vert(bAnimContext *ac, const int mv static void mouse_graph_keys(bAnimContext *ac, const int mval[2], short select_mode, - short curves_only) + const bool deselect_all, + const bool curves_only) { SpaceGraph *sipo = (SpaceGraph *)ac->sl; tNearestVertInfo *nvi; @@ -1354,12 +1406,10 @@ static void mouse_graph_keys(bAnimContext *ac, /* find the beztriple that we're selecting, and the handle that was clicked on */ nvi = find_nearest_fcurve_vert(ac, mval); - /* check if anything to select */ - if (nvi == NULL) - return; - - /* deselect all other curves? */ - if (select_mode == SELECT_REPLACE) { + /* For replacing selection, if we have something to select, we have to clear existing selection. + * The same goes if we found nothing to select, and deselect_all is true + * (deselect on nothing behavior). */ + if ((nvi != NULL && select_mode == SELECT_REPLACE) || (nvi == NULL && deselect_all)) { /* reset selection mode */ select_mode = SELECT_ADD; @@ -1370,13 +1420,18 @@ static void mouse_graph_keys(bAnimContext *ac, * selection of channel when the visibility of keyframes * doesn't depend on this */ - if ((sipo->flag & SIPO_SELCUVERTSONLY) == 0) + if ((sipo->flag & SIPO_SELCUVERTSONLY) == 0) { ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR); + } + } + + if (nvi == NULL) { + return; } /* if points can be selected on this F-Curve */ // TODO: what about those with no keyframes? - if ((curves_only == 0) && ((nvi->fcu->flag & FCURVE_PROTECTED) == 0)) { + if (!curves_only && ((nvi->fcu->flag & FCURVE_PROTECTED) == 0)) { /* only if there's keyframe */ if (nvi->bezt) { bezt = nvi->bezt; /* used to check bezt seletion is set */ @@ -1408,10 +1463,12 @@ static void mouse_graph_keys(bAnimContext *ac, BEZT_SEL_ALL(bezt); } /* otherwise, select the handle that applied */ - else if (nvi->hpoint == NEAREST_HANDLE_LEFT) + else if (nvi->hpoint == NEAREST_HANDLE_LEFT) { bezt->f1 |= SELECT; - else + } + else { bezt->f3 |= SELECT; + } } } else if (nvi->fpt) { @@ -1439,17 +1496,22 @@ static void mouse_graph_keys(bAnimContext *ac, /* take selection status from item that got hit, to prevent flip/flop on channel * selection status when shift-selecting (i.e. "SELECT_INVERT") points */ - if (BEZT_ISSEL_ANY(bezt)) + if (BEZT_ISSEL_ANY(bezt)) { nvi->fcu->flag |= FCURVE_SELECTED; - else + } + else { nvi->fcu->flag &= ~FCURVE_SELECTED; + } } else { - /* didn't hit any channel, so just apply that selection mode to the curve's selection status */ - if (select_mode == SELECT_INVERT) + /* Didn't hit any channel, + * so just apply that selection mode to the curve's selection status. */ + if (select_mode == SELECT_INVERT) { nvi->fcu->flag ^= FCURVE_SELECTED; - else if (select_mode == SELECT_ADD) + } + else if (select_mode == SELECT_ADD) { nvi->fcu->flag |= FCURVE_SELECTED; + } } } @@ -1485,8 +1547,9 @@ static void graphkeys_mselect_column(bAnimContext *ac, const int mval[2], short nvi = find_nearest_fcurve_vert(ac, mval); /* check if anything to select */ - if (nvi == NULL) + if (nvi == NULL) { return; + } /* get frame number on which elements should be selected */ // TODO: should we restrict to integer frames only? @@ -1520,10 +1583,12 @@ static void graphkeys_mselect_column(bAnimContext *ac, const int mval[2], short AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* set frame for validation callback to refer to */ - if (adt) + if (adt) { ked.f1 = BKE_nla_tweakedit_remap(adt, selx, NLATIME_CONVERT_UNMAP); - else + } + else { ked.f1 = selx; + } /* select elements with frame number matching cfra */ ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL); @@ -1541,17 +1606,15 @@ static void graphkeys_mselect_column(bAnimContext *ac, const int mval[2], short static int graphkeys_clickselect_invoke(bContext *C, wmOperator *op, const wmEvent *event) { bAnimContext ac; - short selectmode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* select mode is either replace (deselect all, then add) or add/extend */ - if (RNA_boolean_get(op->ptr, "extend")) - selectmode = SELECT_INVERT; - else - selectmode = SELECT_REPLACE; + const short selectmode = RNA_boolean_get(op->ptr, "extend") ? SELECT_INVERT : SELECT_REPLACE; + const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all"); /* figure out action to take */ if (RNA_boolean_get(op->ptr, "column")) { @@ -1560,11 +1623,11 @@ static int graphkeys_clickselect_invoke(bContext *C, wmOperator *op, const wmEve } else if (RNA_boolean_get(op->ptr, "curves")) { /* select all keyframes in the same F-Curve as the one under the mouse */ - mouse_graph_keys(&ac, event->mval, selectmode, 1); + mouse_graph_keys(&ac, event->mval, selectmode, deselect_all, true); } else { /* select keyframe under mouse */ - mouse_graph_keys(&ac, event->mval, selectmode, 0); + mouse_graph_keys(&ac, event->mval, selectmode, deselect_all, false); } /* set notifier that keyframe selection (and also channel selection in some cases) has changed */ @@ -1600,6 +1663,13 @@ void GRAPH_OT_clickselect(wmOperatorType *ot) "Toggle keyframe selection instead of leaving newly selected keyframes only"); // SHIFTKEY RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_boolean(ot->srna, + "deselect_all", + false, + "Deselect On Nothing", + "Deselect all when nothing under the cursor"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_boolean( ot->srna, "column", diff --git a/source/blender/editors/space_graph/graph_utils.c b/source/blender/editors/space_graph/graph_utils.c index 1c3b4f1377b..d582ac557fa 100644 --- a/source/blender/editors/space_graph/graph_utils.c +++ b/source/blender/editors/space_graph/graph_utils.c @@ -50,7 +50,8 @@ /* Set Up Drivers Editor */ /* Set up UI configuration for Drivers Editor */ -/* NOTE: Currently called from windowmanager (new drivers editor window) and RNA (mode switching) */ +/* NOTE: Currently called from windowmanager + * (new drivers editor window) and RNA (mode switching) */ void ED_drivers_editor_init(bContext *C, ScrArea *sa) { SpaceGraph *sipo = (SpaceGraph *)sa->spacedata.first; @@ -66,7 +67,7 @@ void ED_drivers_editor_init(bContext *C, ScrArea *sa) ar_props->flag &= ~RGN_FLAG_HIDDEN; /* XXX: Adjust width of this too? */ - ED_region_visibility_change_update(C, ar_props); + ED_region_visibility_change_update(C, sa, ar_props); } else { printf("%s: Couldn't find properties region for Drivers Editor - %p\n", __func__, sa); @@ -91,11 +92,14 @@ void ED_drivers_editor_init(bContext *C, ScrArea *sa) /* ************************************************************** */ /* Active F-Curve */ -/* Find 'active' F-Curve. It must be editable, since that's the purpose of these buttons (subject to change). - * We return the 'wrapper' since it contains valuable context info (about hierarchy), which will need to be freed - * when the caller is done with it. +/** + * Find 'active' F-Curve. + * It must be editable, since that's the purpose of these buttons (subject to change). + * We return the 'wrapper' since it contains valuable context info (about hierarchy), + * which will need to be freed when the caller is done with it. * - * NOTE: curve-visible flag isn't included, otherwise selecting a curve via list to edit is too cumbersome + * \note curve-visible flag isn't included, + * otherwise selecting a curve via list to edit is too cumbersome. */ bAnimListElem *get_active_fcurve_channel(bAnimContext *ac) { @@ -136,20 +140,23 @@ bool graphop_visible_keyframes_poll(bContext *C) /* firstly, check if in Graph Editor */ // TODO: also check for region? - if ((sa == NULL) || (sa->spacetype != SPACE_GRAPH)) + if ((sa == NULL) || (sa->spacetype != SPACE_GRAPH)) { return 0; + } /* try to init Anim-Context stuff ourselves and check */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return 0; + } /* loop over the visible (selection doesn't matter) F-Curves, and see if they're suitable * stopping on the first successful match */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE); items = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); - if (items == 0) + if (items == 0) { return 0; + } for (ale = anim_data.first; ale; ale = ale->next) { FCurve *fcu = (FCurve *)ale->data; @@ -159,8 +166,9 @@ bool graphop_visible_keyframes_poll(bContext *C) * - F-Curve modifiers do not interfere with the result too much * (i.e. the modifier-control drawing check returns false) */ - if (fcu->bezt == NULL) + if (fcu->bezt == NULL) { continue; + } if (fcurve_are_keyframes_usable(fcu)) { found = 1; break; @@ -185,20 +193,23 @@ bool graphop_editable_keyframes_poll(bContext *C) /* firstly, check if in Graph Editor */ // TODO: also check for region? - if ((sa == NULL) || (sa->spacetype != SPACE_GRAPH)) + if ((sa == NULL) || (sa->spacetype != SPACE_GRAPH)) { return 0; + } /* try to init Anim-Context stuff ourselves and check */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return 0; + } /* loop over the editable F-Curves, and see if they're suitable * stopping on the first successful match */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVE_VISIBLE); items = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); - if (items == 0) + if (items == 0) { return 0; + } for (ale = anim_data.first; ale; ale = ale->next) { FCurve *fcu = (FCurve *)ale->data; @@ -209,8 +220,9 @@ bool graphop_editable_keyframes_poll(bContext *C) * - F-Curve modifiers do not interfere with the result too much * (i.e. the modifier-control drawing check returns false) */ - if (fcu->bezt == NULL) + if (fcu->bezt == NULL) { continue; + } if (fcurve_is_keyframable(fcu)) { found = 1; break; @@ -232,21 +244,25 @@ bool graphop_active_fcurve_poll(bContext *C) /* firstly, check if in Graph Editor */ // TODO: also check for region? - if ((sa == NULL) || (sa->spacetype != SPACE_GRAPH)) + if ((sa == NULL) || (sa->spacetype != SPACE_GRAPH)) { return 0; + } /* try to init Anim-Context stuff ourselves and check */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return 0; + } /* try to get the Active F-Curve */ ale = get_active_fcurve_channel(&ac); - if (ale == NULL) + if (ale == NULL) { return 0; + } - /* do we have a suitable F-Curves? - * - For most cases, NLA Control Curves are sufficiently similar to NLA curves to serve this role too. - * Under the hood, they are F-Curves too. The only problems which will arise here are if these need to be + /* Do we have a suitable F-Curves? + * - For most cases, NLA Control Curves are sufficiently similar to NLA + * curves to serve this role too. Under the hood, they are F-Curves too. + * The only problems which will arise here are if these need to be * in an Action too (but drivers would then also be affected!) */ has_fcurve = ((ale->data) && ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)); @@ -273,20 +289,23 @@ bool graphop_selected_fcurve_poll(bContext *C) /* firstly, check if in Graph Editor */ // TODO: also check for region? - if ((sa == NULL) || (sa->spacetype != SPACE_GRAPH)) + if ((sa == NULL) || (sa->spacetype != SPACE_GRAPH)) { return 0; + } /* try to init Anim-Context stuff ourselves and check */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return 0; + } - /* get the editable + selected F-Curves, and as long as we got some, we can return - * NOTE: curve-visible flag isn't included, otherwise selecting a curve via list to edit is too cumbersome - */ + /* Get the editable + selected F-Curves, and as long as we got some, we can return. + * NOTE: curve-visible flag isn't included, + * otherwise selecting a curve via list to edit is too cumbersome. */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_FOREDIT); items = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); - if (items == 0) + if (items == 0) { return 0; + } /* cleanup and return findings */ ANIM_animdata_freelist(&anim_data); diff --git a/source/blender/editors/space_graph/space_graph.c b/source/blender/editors/space_graph/space_graph.c index d03431468d8..86d0b961a31 100644 --- a/source/blender/editors/space_graph/space_graph.c +++ b/source/blender/editors/space_graph/space_graph.c @@ -60,34 +60,6 @@ #include "graph_intern.h" // own include -/* ******************** manage regions ********************* */ - -ARegion *graph_has_buttons_region(ScrArea *sa) -{ - ARegion *ar, *arnew; - - ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); - if (ar) - return ar; - - /* add subdiv level; after main */ - ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); - - /* is error! */ - if (ar == NULL) - return NULL; - - arnew = MEM_callocN(sizeof(ARegion), "buttons for graph"); - - BLI_insertlinkafter(&sa->regionbase, ar, arnew); - arnew->regiontype = RGN_TYPE_UI; - arnew->alignment = RGN_ALIGN_RIGHT; - - arnew->flag = RGN_FLAG_HIDDEN; - - return arnew; -} - /* ******************** default callbacks for ipo space ***************** */ static SpaceLink *graph_new(const ScrArea *UNUSED(sa), const Scene *scene) @@ -214,7 +186,7 @@ static void graph_main_region_init(wmWindowManager *wm, ARegion *ar) /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "Graph Editor", SPACE_GRAPH, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "Graph Editor Generic", SPACE_GRAPH, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); } @@ -226,10 +198,9 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar) Scene *scene = CTX_data_scene(C); bAnimContext ac; View2D *v2d = &ar->v2d; - View2DGrid *grid; View2DScrollers *scrollers; float col[3]; - short unitx = 0, unity = V2D_UNIT_VALUES, cfra_flag = 0; + short cfra_flag = 0; /* clear and setup matrix */ UI_GetThemeColor3fv(TH_BACK, col); @@ -239,18 +210,9 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_ortho(v2d); /* grid */ - unitx = ((sipo->mode == SIPO_MODE_ANIMATION) && (sipo->flag & SIPO_DRAWTIME)) ? - V2D_UNIT_SECONDS : - V2D_UNIT_FRAMESCALE; - grid = UI_view2d_grid_calc(CTX_data_scene(C), - v2d, - unitx, - V2D_GRID_NOCLAMP, - unity, - V2D_GRID_NOCLAMP, - ar->winx, - ar->winy); - UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL); + bool display_seconds = (sipo->mode == SIPO_MODE_ANIMATION) && (sipo->flag & SIPO_DRAWTIME); + UI_view2d_draw_lines_x__frames_or_seconds(v2d, scene, display_seconds); + UI_view2d_draw_lines_y__values(v2d); ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); @@ -265,8 +227,8 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar) graph_draw_ghost_curves(&ac, sipo, ar); /* draw curves twice - unselected, then selected, so that the are fewer occlusion problems */ - graph_draw_curves(&ac, sipo, ar, grid, 0); - graph_draw_curves(&ac, sipo, ar, grid, 1); + graph_draw_curves(&ac, sipo, ar, 0); + graph_draw_curves(&ac, sipo, ar, 1); /* XXX the slow way to set tot rect... but for nice sliders needed (ton) */ get_graph_keyframe_extents( @@ -276,9 +238,6 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar) v2d->tot.xmax += 10.0f; } - /* only free grid after drawing data, as we need to use it to determine sampling rate */ - UI_view2d_grid_free(grid); - if (((sipo->flag & SIPO_NODRAWCURSOR) == 0) || (sipo->mode == SIPO_MODE_DRIVERS)) { uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); @@ -325,8 +284,9 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar) if (sipo->mode != SIPO_MODE_DRIVERS) { /* current frame */ - if (sipo->flag & SIPO_DRAWTIME) + if (sipo->flag & SIPO_DRAWTIME) { cfra_flag |= DRAWCFRA_UNIT_SECONDS; + } ANIM_draw_cfra(C, v2d, cfra_flag); } @@ -351,11 +311,14 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar) /* scrollers */ // FIXME: args for scrollers depend on the type of data being shown... - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP); - UI_view2d_scrollers_draw(C, v2d, scrollers); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); + /* scale numbers */ + UI_view2d_draw_scale_x__frames_or_seconds(ar, v2d, &v2d->hor, scene, display_seconds); + UI_view2d_draw_scale_y__values(ar, v2d, &v2d->vert); + /* draw current frame number-indicator on top of scrollers */ if ((sipo->mode != SIPO_MODE_DRIVERS) && ((sipo->flag & SIPO_NODRAWCFRANUM) == 0)) { UI_view2d_view_orthoSpecial(ar, v2d, 1); @@ -380,7 +343,7 @@ static void graph_channel_region_init(wmWindowManager *wm, ARegion *ar) /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "Animation Channels", 0, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "Graph Editor Generic", SPACE_GRAPH, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); } @@ -408,9 +371,8 @@ static void graph_channel_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); /* scrollers */ - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY); - UI_view2d_scrollers_draw(C, v2d, scrollers); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); } @@ -433,7 +395,7 @@ static void graph_buttons_region_init(wmWindowManager *wm, ARegion *ar) ED_region_panels_init(wm, ar); keymap = WM_keymap_ensure(wm->defaultconf, "Graph Editor Generic", SPACE_GRAPH, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } static void graph_buttons_region_draw(const bContext *C, ARegion *ar) @@ -462,8 +424,9 @@ static void graph_region_listener(wmWindow *UNUSED(win), ED_region_tag_redraw(ar); break; case ND_SEQUENCER: - if (wmn->action == NA_SELECTED) + if (wmn->action == NA_SELECTED) { ED_region_tag_redraw(ar); + } break; } break; @@ -475,8 +438,9 @@ static void graph_region_listener(wmWindow *UNUSED(win), ED_region_tag_redraw(ar); break; case ND_MODIFIER: - if (wmn->action == NA_RENAME) + if (wmn->action == NA_RENAME) { ED_region_tag_redraw(ar); + } break; } break; @@ -489,8 +453,9 @@ static void graph_region_listener(wmWindow *UNUSED(win), } break; case NC_ID: - if (wmn->action == NA_RENAME) + if (wmn->action == NA_RENAME) { ED_region_tag_redraw(ar); + } break; case NC_SCREEN: if (ELEM(wmn->data, ND_LAYER)) { @@ -498,8 +463,9 @@ static void graph_region_listener(wmWindow *UNUSED(win), } break; default: - if (wmn->data == ND_KEYS) + if (wmn->data == ND_KEYS) { ED_region_tag_redraw(ar); + } break; } } @@ -592,15 +558,17 @@ static void graph_listener(wmWindow *UNUSED(win), case NC_ANIMATION: /* for selection changes of animation data, we can just redraw... * otherwise autocolor might need to be done again */ - if (ELEM(wmn->data, ND_KEYFRAME, ND_ANIMCHAN) && (wmn->action == NA_SELECTED)) + if (ELEM(wmn->data, ND_KEYFRAME, ND_ANIMCHAN) && (wmn->action == NA_SELECTED)) { ED_area_tag_redraw(sa); - else + } + else { ED_area_tag_refresh(sa); + } break; case NC_SCENE: switch (wmn->data) { - case ND_OB_ACTIVE: /* selection changed, so force refresh to flush - * (needs flag set to do syncing) */ + case ND_OB_ACTIVE: /* Selection changed, so force refresh to flush + * (needs flag set to do syncing). */ case ND_OB_SELECT: sipo->runtime.flag |= SIPO_RUNTIME_FLAG_NEED_CHAN_SYNC; ED_area_tag_refresh(sa); @@ -613,8 +581,8 @@ static void graph_listener(wmWindow *UNUSED(win), break; case NC_OBJECT: switch (wmn->data) { - case ND_BONE_SELECT: /* selection changed, so force refresh to flush - * (needs flag set to do syncing) */ + case ND_BONE_SELECT: /* Selection changed, so force refresh to flush + * (needs flag set to do syncing). */ case ND_BONE_ACTIVE: sipo->runtime.flag |= SIPO_RUNTIME_FLAG_NEED_CHAN_SYNC; ED_area_tag_refresh(sa); @@ -635,8 +603,9 @@ static void graph_listener(wmWindow *UNUSED(win), } break; case NC_SPACE: - if (wmn->data == ND_SPACE_GRAPH) + if (wmn->data == ND_SPACE_GRAPH) { ED_area_tag_redraw(sa); + } break; case NC_WINDOW: if (sipo->runtime.flag & @@ -647,7 +616,7 @@ static void graph_listener(wmWindow *UNUSED(win), break; // XXX: restore the case below if not enough updates occur... - //default: + // default: // if (wmn->data == ND_KEYS) // ED_area_tag_redraw(sa); } @@ -664,8 +633,9 @@ static void graph_refresh_fcurve_colors(const bContext *C) int filter; int i; - if (ANIM_animdata_get_context(C, &ac) == false) + if (ANIM_animdata_get_context(C, &ac) == false) { return; + } UI_SetTheme(SPACE_GRAPH, RGN_TYPE_WINDOW); @@ -683,13 +653,15 @@ static void graph_refresh_fcurve_colors(const bContext *C) /* set color of curve here */ switch (fcu->color_mode) { case FCURVE_COLOR_CUSTOM: { - /* User has defined a custom color for this curve already (we assume it's not going to cause clashes with text colors), + /* User has defined a custom color for this curve already + * (we assume it's not going to cause clashes with text colors), * which should be left alone... Nothing needs to be done here. */ break; } case FCURVE_COLOR_AUTO_RGB: { - /* F-Curve's array index is automatically mapped to RGB values. This works best of 3-value vectors. + /* F-Curve's array index is automatically mapped to RGB values. + * This works best of 3-value vectors. * TODO: find a way to module the hue so that not all curves have same color... */ float *col = fcu->color; @@ -793,9 +765,9 @@ static void graph_refresh(const bContext *C, ScrArea *sa) /* region updates? */ // XXX re-sizing y-extents of tot should go here? - /* update the state of the animchannels in response to changes from the data they represent - * NOTE: the temp flag is used to indicate when this needs to be done, and will be cleared once handled - */ + /* Update the state of the animchannels in response to changes from the data they represent + * NOTE: the temp flag is used to indicate when this needs to be done, + * and will be cleared once handled. */ if (sipo->runtime.flag & SIPO_RUNTIME_FLAG_NEED_CHAN_SYNC) { ANIM_sync_animchannels_to_data(C); sipo->runtime.flag &= ~SIPO_RUNTIME_FLAG_NEED_CHAN_SYNC; diff --git a/source/blender/editors/space_image/CMakeLists.txt b/source/blender/editors/space_image/CMakeLists.txt index 70b7387bf6b..61e6b065cba 100644 --- a/source/blender/editors/space_image/CMakeLists.txt +++ b/source/blender/editors/space_image/CMakeLists.txt @@ -23,14 +23,14 @@ set(INC ../../blentranslation ../../bmesh ../../depsgraph - ../../imbuf ../../gpu + ../../imbuf ../../makesdna ../../makesrna ../../render/extern/include ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c index e217987f212..752eedebe71 100644 --- a/source/blender/editors/space_image/image_buttons.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -154,146 +154,6 @@ struct ImageUser *ntree_get_active_iuser(bNodeTree *ntree) return NULL; } -/* ************ panel stuff ************* */ - -#if 0 -/* 0: disable preview - * otherwise refresh preview - * - * XXX if you put this back, also check XXX in image_main_region_draw() */ -void image_preview_event(int event) -{ - int exec = 0; - - if (event == 0) { - G.scene->r.scemode &= ~R_COMP_CROP; - exec = 1; - } - else { - if (image_preview_active(curarea, NULL, NULL)) { - G.scene->r.scemode |= R_COMP_CROP; - exec = 1; - } - else - G.scene->r.scemode &= ~R_COMP_CROP; - } - - if (exec && G.scene->nodetree) { - Scene *scene = G.scene; - /* should work when no node editor in screen..., so we execute right away */ - - ntreeCompositTagGenerators(G.scene->nodetree); - - G.is_break = false; - G.scene->nodetree->timecursor = set_timecursor; - G.scene->nodetree->test_break = BKE_blender_test_break; - - BIF_store_spare(); - - /* 1 is do_previews */ - ntreeCompositExecTree(scene->nodetree, &scene->r, 1, &scene->view_settings, &scene->display_settings); - - G.scene->nodetree->timecursor = NULL; - G.scene->nodetree->test_break = NULL; - - scrarea_do_windraw(curarea); - waitcursor(0); - - WM_event_add_notifier(C, NC_IMAGE, ima_v); - } -} - - -/* nothing drawn here, we use it to store values */ -static void preview_cb(ScrArea *sa, struct uiBlock *block) -{ - SpaceImage *sima = sa->spacedata.first; - rctf dispf; - rcti *disprect = &G.scene->r.disprect; - int winx = (G.scene->r.size * G.scene->r.xsch) / 100; - int winy = (G.scene->r.size * G.scene->r.ysch) / 100; - int mval[2]; - - if (G.scene->r.mode & R_BORDER) { - winx *= BLI_rcti_size_x(&G.scene->r.border); - winy *= BLI_rctf_size_y(&G.scene->r.border); - } - - /* while dragging we need to update the rects, otherwise it doesn't end with correct one */ - - BLI_rctf_init(&dispf, 15.0f, BLI_rcti_size_x(&block->rect) - 15.0f, 15.0f, (BLI_rctf_size_y(&block->rect)) - 15.0f); - ui_graphics_to_window_rct(sa->win, &dispf, disprect); - - /* correction for gla draw */ - BLI_rcti_translate(disprect, -curarea->winrct.xmin, -curarea->winrct.ymin); - - calc_image_view(sima, 'p'); -// printf("winrct %d %d %d %d\n", disprect->xmin, disprect->ymin, disprect->xmax, disprect->ymax); - /* map to image space coordinates */ - mval[0] = disprect->xmin; mval[1] = disprect->ymin; - areamouseco_to_ipoco(v2d, mval, &dispf.xmin, &dispf.ymin); - mval[0] = disprect->xmax; mval[1] = disprect->ymax; - areamouseco_to_ipoco(v2d, mval, &dispf.xmax, &dispf.ymax); - - /* map to render coordinates */ - disprect->xmin = dispf.xmin; - disprect->xmax = dispf.xmax; - disprect->ymin = dispf.ymin; - disprect->ymax = dispf.ymax; - - CLAMP(disprect->xmin, 0, winx); - CLAMP(disprect->xmax, 0, winx); - CLAMP(disprect->ymin, 0, winy); - CLAMP(disprect->ymax, 0, winy); -// printf("drawrct %d %d %d %d\n", disprect->xmin, disprect->ymin, disprect->xmax, disprect->ymax); - -} - -static bool is_preview_allowed(ScrArea *cur) -{ - SpaceImage *sima = cur->spacedata.first; - ScrArea *sa; - - /* check if another areawindow has preview set */ - for (sa = G.curscreen->areabase.first; sa; sa = sa->next) { - if (sa != cur && sa->spacetype == SPACE_IMAGE) { - if (image_preview_active(sa, NULL, NULL)) - return 0; - } - } - /* check image type */ - if (sima->image == NULL || sima->image->type != IMA_TYPE_COMPOSITE) - return 0; - - return 1; -} - - -static void image_panel_preview(ScrArea *sa, short cntrl) // IMAGE_HANDLER_PREVIEW -{ - uiBlock *block; - SpaceImage *sima = sa->spacedata.first; - int ofsx, ofsy; - - if (is_preview_allowed(sa) == 0) { - rem_blockhandler(sa, IMAGE_HANDLER_PREVIEW); - G.scene->r.scemode &= ~R_COMP_CROP; /* quite weak */ - return; - } - - block = UI_block_begin(C, ar, __func__, UI_EMBOSS); - uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | UI_PNL_SCALE | cntrl); - uiSetPanelHandler(IMAGE_HANDLER_PREVIEW); // for close and esc - - ofsx = -150 + (sa->winx / 2) / sima->blockscale; - ofsy = -100 + (sa->winy / 2) / sima->blockscale; - if (uiNewPanel(C, ar, block, "Preview", "Image", ofsx, ofsy, 300, 200) == 0) return; - - UI_but_func_drawextra_set(block, preview_cb); - -} -#endif - /* ********************* callbacks for standard image buttons *************** */ static void ui_imageuser_slot_menu(bContext *UNUSED(C), uiLayout *layout, void *image_p) @@ -1063,17 +923,73 @@ void uiTemplateImage(uiLayout *layout, iuser = ntree_get_active_iuser(scene->nodetree); if (iuser) { UI_block_align_begin(block); - uiDefIconTextBut(block, UI_BTYPE_BUT, B_SIMA_RECORD, ICON_REC, "Record", 10, 120, 100, 20, 0, 0, 0, 0, 0, ""); - uiDefIconTextBut(block, UI_BTYPE_BUT, B_SIMA_PLAY, ICON_PLAY, "Play", 110, 120, 100, 20, 0, 0, 0, 0, 0, ""); - but = uiDefBut(block, UI_BTYPE_BUT, B_NOP, "Free Cache", 210, 120, 100, 20, 0, 0, 0, 0, 0, ""); + uiDefIconTextBut(block, + UI_BTYPE_BUT, + B_SIMA_RECORD, + ICON_REC, + "Record", + 10, + 120, + 100, + 20, + 0, + 0, + 0, + 0, + 0, + ""); + uiDefIconTextBut(block, + UI_BTYPE_BUT, + B_SIMA_PLAY, + ICON_PLAY, + "Play", + 110, + 120, + 100, + 20, + 0, + 0, + 0, + 0, + 0, + ""); + but = uiDefBut( + block, UI_BTYPE_BUT, B_NOP, "Free Cache", 210, 120, 100, 20, 0, 0, 0, 0, 0, ""); UI_but_func_set(but, image_freecache_cb, ima, NULL); if (iuser->frames) BLI_snprintf(str, sizeof(str), "(%d) Frames:", iuser->framenr); - else strcpy(str, "Frames:"); + else + strcpy(str, "Frames:"); UI_block_align_begin(block); - uiDefButI(block, UI_BTYPE_NUM, imagechanged, str, 10, 90, 150, 20, &iuser->frames, 0.0, MAXFRAMEF, 0, 0, "Number of images of a movie to use"); - uiDefButI(block, UI_BTYPE_NUM, imagechanged, "StartFr:", 160, 90, 150, 20, &iuser->sfra, 1.0, MAXFRAMEF, 0, 0, "Global starting frame of the movie"); + uiDefButI(block, + UI_BTYPE_NUM, + imagechanged, + str, + 10, + 90, + 150, + 20, + &iuser->frames, + 0.0, + MAXFRAMEF, + 0, + 0, + "Number of images of a movie to use"); + uiDefButI(block, + UI_BTYPE_NUM, + imagechanged, + "StartFr:", + 160, + 90, + 150, + 20, + &iuser->sfra, + 1.0, + MAXFRAMEF, + 0, + 0, + "Global starting frame of the movie"); } #endif } @@ -1455,59 +1371,10 @@ void image_buttons_register(ARegionType *art) pt = MEM_callocN(sizeof(PanelType), "spacetype image panel metadata"); strcpy(pt->idname, "IMAGE_PT_metadata"); strcpy(pt->label, N_("Metadata")); + strcpy(pt->category, "Image"); strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); pt->poll = metadata_panel_context_poll; pt->draw = metadata_panel_context_draw; pt->flag |= PNL_DEFAULT_CLOSED; BLI_addtail(&art->paneltypes, pt); } - -static int image_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = image_has_buttons_region(sa); - - if (ar) { - ED_region_toggle_hidden(C, ar); - } - - return OPERATOR_FINISHED; -} - -void IMAGE_OT_properties(wmOperatorType *ot) -{ - ot->name = "Toggle Sidebar"; - ot->idname = "IMAGE_OT_properties"; - ot->description = "Toggle the properties region visibility"; - - ot->exec = image_properties_toggle_exec; - ot->poll = ED_operator_image_active; - - /* flags */ - ot->flag = 0; -} - -static int image_scopes_toggle_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = image_has_tools_region(sa); - - if (ar) { - ED_region_toggle_hidden(C, ar); - } - - return OPERATOR_FINISHED; -} - -void IMAGE_OT_toolshelf(wmOperatorType *ot) -{ - ot->name = "Toggle Toolbar"; - ot->idname = "IMAGE_OT_toolshelf"; - ot->description = "Toggles tool shelf display"; - - ot->exec = image_scopes_toggle_exec; - ot->poll = ED_operator_image_active; - - /* flags */ - ot->flag = 0; -} diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index a87808e1601..9b57644b6ec 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -575,7 +575,7 @@ static void draw_image_buffer(const bContext *C, /* If RGBA display with color management */ if ((sima->flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B | SI_SHOW_ALPHA)) == 0) { - glaDrawImBuf_glsl_ctx_clipping( + ED_draw_imbuf_ctx_clipping( C, ibuf, x, y, GL_NEAREST, 0, 0, clip_max_x, clip_max_y, zoomx, zoomy); } else { @@ -673,7 +673,7 @@ void draw_image_grease_pencil(bContext *C, bool onlyv2d) } else { /* assume that UI_view2d_restore(C) has been called... */ - //SpaceImage *sima = (SpaceImage *)CTX_wm_space_data(C); + // SpaceImage *sima = (SpaceImage *)CTX_wm_space_data(C); /* draw grease-pencil ('screen' strokes) */ ED_annotation_draw_view2d(C, 0); diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h index db56f1051c5..a851684f2f3 100644 --- a/source/blender/editors/space_image/image_intern.h +++ b/source/blender/editors/space_image/image_intern.h @@ -34,8 +34,6 @@ struct bNodeTree; struct wmOperatorType; /* space_image.c */ -struct ARegion *image_has_buttons_region(struct ScrArea *sa); -struct ARegion *image_has_tools_region(struct ScrArea *sa); extern const char *image_context_dir[]; /* doc access */ @@ -91,7 +89,5 @@ void IMAGE_OT_clear_render_border(struct wmOperatorType *ot); /* image_panels.c */ struct ImageUser *ntree_get_active_iuser(struct bNodeTree *ntree); void image_buttons_register(struct ARegionType *art); -void IMAGE_OT_properties(struct wmOperatorType *ot); -void IMAGE_OT_toolshelf(struct wmOperatorType *ot); #endif /* __IMAGE_INTERN_H__ */ diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 06bacabe6fa..cec2e1c68d9 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -51,6 +51,7 @@ #include "BKE_context.h" #include "BKE_icons.h" #include "BKE_image.h" +#include "BKE_image_save.h" #include "BKE_global.h" #include "BKE_library.h" #include "BKE_main.h" @@ -64,6 +65,7 @@ #include "DEG_depsgraph.h" #include "GPU_draw.h" +#include "GPU_state.h" #include "GPU_immediate.h" #include "IMB_colormanagement.h" @@ -289,7 +291,8 @@ static bool image_sample_poll(bContext *C) if (sima) { Object *obedit = CTX_data_edit_object(C); if (obedit) { - /* Disable when UV editing so it doesn't swallow all click events (use for setting cursor). */ + /* Disable when UV editing so it doesn't swallow all click events + * (use for setting cursor). */ if (ED_space_image_show_uvedit(sima, obedit)) { return false; } @@ -355,15 +358,6 @@ static int image_view_pan_exec(bContext *C, wmOperator *op) ED_region_tag_redraw(CTX_wm_region(C)); - /* XXX notifier? */ -#if 0 - if (image_preview_active(curarea, NULL, NULL)) { - /* recalculates new preview rect */ - scrarea_do_windraw(curarea); - image_preview_event(2); - } -#endif - return OPERATOR_FINISHED; } @@ -520,15 +514,6 @@ static int image_view_zoom_exec(bContext *C, wmOperator *op) ED_region_tag_redraw(ar); - /* XXX notifier? */ -#if 0 - if (image_preview_active(curarea, NULL, NULL)) { - /* recalculates new preview rect */ - scrarea_do_windraw(curarea); - image_preview_event(2); - } -#endif - return OPERATOR_FINISHED; } @@ -596,7 +581,7 @@ static void image_zoom_apply(ViewZoomData *vpd, zfac = 1.0f + ((fac / 20.0f) * time_step); vpd->timer_lastdraw = time; /* this is the final zoom, but instead make it into a factor */ - //zoom = vpd->sima->zoom * zfac; + // zoom = vpd->sima->zoom * zfac; factor = (vpd->sima->zoom * zfac) / vpd->zoom; } else { @@ -1005,15 +990,6 @@ static int image_view_zoom_ratio_exec(bContext *C, wmOperator *op) sima->xof = (int)sima->xof; sima->yof = (int)sima->yof; - /* XXX notifier? */ -#if 0 - if (image_preview_active(curarea, NULL, NULL)) { - /* recalculates new preview rect */ - scrarea_do_windraw(curarea); - image_preview_event(2); - } -#endif - ED_region_tag_redraw(ar); return OPERATOR_FINISHED; @@ -1143,9 +1119,10 @@ static void image_open_cancel(bContext *UNUSED(C), wmOperator *op) } /** - * \brief Get a list of frames from the list of image files matching the first file name sequence pattern - * \param ptr: [in] the RNA pointer containing the "directory" entry and "files" collection - * \param frames_all: [out] the list of frame numbers found in the files matching the first one by name + * Get a list of frames from the list of image files matching the first file name sequence pattern. + * \param ptr[in]: The RNA pointer containing the "directory" entry and "files" collection. + * \param frames_all[out]: the list of frame numbers found in the files matching + * the first one by name. */ static void image_sequence_get_frame_ranges(PointerRNA *ptr, ListBase *frames_all) { @@ -1200,7 +1177,8 @@ static int image_cmp_frame(const void *a, const void *b) } /** - * Return the start (offset) and the length of the sequence of continuous frames in the list of frames + * Return the start (offset) and the length of the sequence of + * continuous frames in the list of frames. * * \param frames: [in] the list of frame numbers, as a side-effect the list is sorted. * \param ofs: [out] offset the first frame number in the sequence. @@ -1678,19 +1656,6 @@ void IMAGE_OT_replace(wmOperatorType *ot) /******************** save image as operator ********************/ -typedef struct { - /* matching scene->r settings */ - //short planes, imtype, subimtype, quality; - ImageFormatData im_format; - char filepath[FILE_MAX]; /* keep absolute */ -} SaveImageOptions; - -static void save_image_options_defaults(SaveImageOptions *simopts) -{ - BKE_imformat_defaults(&simopts->im_format); - simopts->filepath[0] = '\0'; -} - static char imtype_best_depth(ImBuf *ibuf, const char imtype) { const char depth_ok = BKE_imtype_valid_depths(imtype); @@ -1730,466 +1695,148 @@ static char imtype_best_depth(ImBuf *ibuf, const char imtype) } } -static int save_image_options_init(Main *bmain, - SaveImageOptions *simopts, - SpaceImage *sima, - Scene *scene, +static int image_save_options_init(Main *bmain, + ImageSaveOptions *opts, + Image *ima, + ImageUser *iuser, const bool guess_path, const bool save_as_render) { void *lock; - ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock); + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock); if (ibuf) { - Image *ima = sima->image; + Scene *scene = opts->scene; bool is_depth_set = false; if (ELEM(ima->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) { /* imtype */ - simopts->im_format = scene->r.im_format; + opts->im_format = scene->r.im_format; is_depth_set = true; if (!BKE_image_is_multiview(ima)) { /* In case multiview is disabled, * render settings would be invalid for render result in this area. */ - simopts->im_format.stereo3d_format = *ima->stereo3d_format; - simopts->im_format.views_format = ima->views_format; + opts->im_format.stereo3d_format = *ima->stereo3d_format; + opts->im_format.views_format = ima->views_format; } } else { if (ima->source == IMA_SRC_GENERATED) { - simopts->im_format.imtype = R_IMF_IMTYPE_PNG; - simopts->im_format.compress = ibuf->foptions.quality; - simopts->im_format.planes = ibuf->planes; + opts->im_format.imtype = R_IMF_IMTYPE_PNG; + opts->im_format.compress = ibuf->foptions.quality; + opts->im_format.planes = ibuf->planes; } else { - BKE_imbuf_to_image_format(&simopts->im_format, ibuf); + BKE_imbuf_to_image_format(&opts->im_format, ibuf); } /* use the multiview image settings as the default */ - simopts->im_format.stereo3d_format = *ima->stereo3d_format; - simopts->im_format.views_format = ima->views_format; + opts->im_format.stereo3d_format = *ima->stereo3d_format; + opts->im_format.views_format = ima->views_format; } ///* XXX - this is lame, we need to make these available too! */ - //simopts->subimtype = scene->r.subimtype; + // opts->subimtype = scene->r.subimtype; - BLI_strncpy(simopts->filepath, ibuf->name, sizeof(simopts->filepath)); + BLI_strncpy(opts->filepath, ibuf->name, sizeof(opts->filepath)); /* sanitize all settings */ /* unlikely but just in case */ - if (ELEM(simopts->im_format.planes, R_IMF_PLANES_BW, R_IMF_PLANES_RGB, R_IMF_PLANES_RGBA) == - 0) { - simopts->im_format.planes = R_IMF_PLANES_RGBA; + if (ELEM(opts->im_format.planes, R_IMF_PLANES_BW, R_IMF_PLANES_RGB, R_IMF_PLANES_RGBA) == 0) { + opts->im_format.planes = R_IMF_PLANES_RGBA; } /* depth, account for float buffer and format support */ if (is_depth_set == false) { - simopts->im_format.depth = imtype_best_depth(ibuf, simopts->im_format.imtype); + opts->im_format.depth = imtype_best_depth(ibuf, opts->im_format.imtype); } /* some formats don't use quality so fallback to scenes quality */ - if (simopts->im_format.quality == 0) { - simopts->im_format.quality = scene->r.im_format.quality; + if (opts->im_format.quality == 0) { + opts->im_format.quality = scene->r.im_format.quality; } /* check for empty path */ - if (guess_path && simopts->filepath[0] == 0) { + if (guess_path && opts->filepath[0] == 0) { const bool is_prev_save = !STREQ(G.ima, "//"); if (save_as_render) { if (is_prev_save) { - BLI_strncpy(simopts->filepath, G.ima, sizeof(simopts->filepath)); + BLI_strncpy(opts->filepath, G.ima, sizeof(opts->filepath)); } else { - BLI_strncpy(simopts->filepath, "//untitled", sizeof(simopts->filepath)); - BLI_path_abs(simopts->filepath, BKE_main_blendfile_path(bmain)); + BLI_strncpy(opts->filepath, "//untitled", sizeof(opts->filepath)); + BLI_path_abs(opts->filepath, BKE_main_blendfile_path(bmain)); } } else { - BLI_snprintf(simopts->filepath, sizeof(simopts->filepath), "//%s", ima->id.name + 2); - BLI_path_abs(simopts->filepath, is_prev_save ? G.ima : BKE_main_blendfile_path(bmain)); + BLI_snprintf(opts->filepath, sizeof(opts->filepath), "//%s", ima->id.name + 2); + BLI_path_abs(opts->filepath, is_prev_save ? G.ima : BKE_main_blendfile_path(bmain)); } } /* color management */ - BKE_color_managed_display_settings_copy(&simopts->im_format.display_settings, + BKE_color_managed_display_settings_copy(&opts->im_format.display_settings, &scene->display_settings); - BKE_color_managed_view_settings_copy(&simopts->im_format.view_settings, &scene->view_settings); + BKE_color_managed_view_settings_copy(&opts->im_format.view_settings, &scene->view_settings); } - ED_space_image_release_buffer(sima, ibuf, lock); + BKE_image_release_ibuf(ima, ibuf, lock); return (ibuf != NULL); } -static void save_image_options_from_op(Main *bmain, SaveImageOptions *simopts, wmOperator *op) +static void image_save_options_from_op(Main *bmain, ImageSaveOptions *opts, wmOperator *op) { if (op->customdata) { - BKE_color_managed_view_settings_free(&simopts->im_format.view_settings); + BKE_color_managed_view_settings_free(&opts->im_format.view_settings); - simopts->im_format = *(ImageFormatData *)op->customdata; + opts->im_format = *(ImageFormatData *)op->customdata; } if (RNA_struct_property_is_set(op->ptr, "filepath")) { - RNA_string_get(op->ptr, "filepath", simopts->filepath); - BLI_path_abs(simopts->filepath, BKE_main_blendfile_path(bmain)); + RNA_string_get(op->ptr, "filepath", opts->filepath); + BLI_path_abs(opts->filepath, BKE_main_blendfile_path(bmain)); } } -static void save_image_options_to_op(SaveImageOptions *simopts, wmOperator *op) +static void image_save_options_to_op(ImageSaveOptions *opts, wmOperator *op) { if (op->customdata) { BKE_color_managed_view_settings_free(&((ImageFormatData *)op->customdata)->view_settings); - *(ImageFormatData *)op->customdata = simopts->im_format; - } - - RNA_string_set(op->ptr, "filepath", simopts->filepath); -} - -static void save_image_post(Main *bmain, - wmOperator *op, - ImBuf *ibuf, - Image *ima, - int ok, - int save_copy, - const char *relbase, - int relative, - int do_newpath, - const char *filepath) -{ - if (ok) { - if (!save_copy) { - ColorManagedColorspaceSettings old_colorspace_settings; - - if (do_newpath) { - BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name)); - BLI_strncpy(ima->name, filepath, sizeof(ima->name)); - } - - ibuf->userflags &= ~IB_BITMAPDIRTY; - - /* change type? */ - if (ima->type == IMA_TYPE_R_RESULT) { - ima->type = IMA_TYPE_IMAGE; - - /* workaround to ensure the render result buffer is no longer used - * by this image, otherwise can crash when a new render result is - * created. */ - if (ibuf->rect && !(ibuf->mall & IB_rect)) { - imb_freerectImBuf(ibuf); - } - if (ibuf->rect_float && !(ibuf->mall & IB_rectfloat)) { - imb_freerectfloatImBuf(ibuf); - } - if (ibuf->zbuf && !(ibuf->mall & IB_zbuf)) { - IMB_freezbufImBuf(ibuf); - } - if (ibuf->zbuf_float && !(ibuf->mall & IB_zbuffloat)) { - IMB_freezbuffloatImBuf(ibuf); - } - } - if (ELEM(ima->source, IMA_SRC_GENERATED, IMA_SRC_VIEWER)) { - ima->source = IMA_SRC_FILE; - ima->type = IMA_TYPE_IMAGE; - } - - /* only image path, never ibuf */ - if (relative) { - BLI_path_rel(ima->name, relbase); /* only after saving */ - } - - BKE_color_managed_colorspace_settings_copy(&old_colorspace_settings, - &ima->colorspace_settings); - IMB_colormanagement_colorspace_from_ibuf_ftype(&ima->colorspace_settings, ibuf); - if (!BKE_color_managed_colorspace_settings_equals(&old_colorspace_settings, - &ima->colorspace_settings)) { - BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_COLORMANAGE); - } - } - } - else { - BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno)); + *(ImageFormatData *)op->customdata = opts->im_format; } -} - -static void save_imbuf_post(ImBuf *ibuf, ImBuf *colormanaged_ibuf) -{ - if (colormanaged_ibuf != ibuf) { - /* This guys might be modified by image buffer write functions, - * need to copy them back from color managed image buffer to an - * original one, so file type of image is being properly updated. - */ - ibuf->ftype = colormanaged_ibuf->ftype; - ibuf->foptions = colormanaged_ibuf->foptions; - ibuf->planes = colormanaged_ibuf->planes; - IMB_freeImBuf(colormanaged_ibuf); - } + RNA_string_set(op->ptr, "filepath", opts->filepath); } -/** - * \return success. - * \note ``ima->name`` and ``ibuf->name`` should end up the same. - * \note for multiview the first ``ibuf`` is important to get the settings. - */ -static bool save_image_doit( - bContext *C, SpaceImage *sima, wmOperator *op, SaveImageOptions *simopts, bool do_newpath) +static bool save_image_op(const bContext *C, + SpaceImage *sima, + wmOperator *op, + ImageSaveOptions *opts) { Main *bmain = CTX_data_main(C); Image *ima = ED_space_image(sima); - void *lock; - ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock); - Scene *scene; - RenderResult *rr = NULL; - bool ok = false; - - WM_cursor_wait(1); - - if (ibuf) { - ImBuf *colormanaged_ibuf = NULL; - const char *relbase = ID_BLEND_PATH(CTX_data_main(C), &ima->id); - const bool relative = (RNA_struct_find_property(op->ptr, "relative_path") && - RNA_boolean_get(op->ptr, "relative_path")); - const bool save_copy = (RNA_struct_find_property(op->ptr, "copy") && - RNA_boolean_get(op->ptr, "copy")); - const bool save_as_render = (RNA_struct_find_property(op->ptr, "save_as_render") && - RNA_boolean_get(op->ptr, "save_as_render")); - ImageFormatData *imf = &simopts->im_format; - - /* old global to ensure a 2nd save goes to same dir */ - BLI_strncpy(G.ima, simopts->filepath, sizeof(G.ima)); - - if (ima->type == IMA_TYPE_R_RESULT) { - /* enforce user setting for RGB or RGBA, but skip BW */ - if (simopts->im_format.planes == R_IMF_PLANES_RGBA) { - ibuf->planes = R_IMF_PLANES_RGBA; - } - else if (simopts->im_format.planes == R_IMF_PLANES_RGB) { - ibuf->planes = R_IMF_PLANES_RGB; - } - } - else { - /* TODO, better solution, if a 24bit image is painted onto it may contain alpha */ - if ((simopts->im_format.planes == R_IMF_PLANES_RGBA) && - /* it has been painted onto */ - (ibuf->userflags & IB_BITMAPDIRTY)) { - /* checks each pixel, not ideal */ - ibuf->planes = BKE_imbuf_alpha_test(ibuf) ? R_IMF_PLANES_RGBA : R_IMF_PLANES_RGB; - } - } - - /* we need renderresult for exr and rendered multiview */ - scene = CTX_data_scene(C); - rr = BKE_image_acquire_renderresult(scene, ima); - bool is_mono = rr ? BLI_listbase_count_at_most(&rr->views, 2) < 2 : - BLI_listbase_count_at_most(&ima->views, 2) < 2; - bool is_exr_rr = rr && ELEM(imf->imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER) && - RE_HasFloatPixels(rr); - bool is_multilayer = is_exr_rr && (imf->imtype == R_IMF_IMTYPE_MULTILAYER); - int layer = (is_multilayer) ? -1 : sima->iuser.layer; - - /* error handling */ - if (!rr) { - if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) { - BKE_report(op->reports, RPT_ERROR, "Did not write, no Multilayer Image"); - goto cleanup; - } - } - else { - if (imf->views_format == R_IMF_VIEWS_STEREO_3D) { - if (!BKE_image_is_stereo(ima)) { - BKE_reportf(op->reports, - RPT_ERROR, - "Did not write, the image doesn't have a \"%s\" and \"%s\" views", - STEREO_LEFT_NAME, - STEREO_RIGHT_NAME); - goto cleanup; - } - - /* it shouldn't ever happen*/ - if ((BLI_findstring(&rr->views, STEREO_LEFT_NAME, offsetof(RenderView, name)) == NULL) || - (BLI_findstring(&rr->views, STEREO_RIGHT_NAME, offsetof(RenderView, name)) == NULL)) { - BKE_reportf(op->reports, - RPT_ERROR, - "Did not write, the image doesn't have a \"%s\" and \"%s\" views", - STEREO_LEFT_NAME, - STEREO_RIGHT_NAME); - goto cleanup; - } - } - BKE_imbuf_stamp_info(rr, ibuf); - } - - /* fancy multiview OpenEXR */ - if (imf->views_format == R_IMF_VIEWS_MULTIVIEW && is_exr_rr) { - /* save render result */ - ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, NULL, layer); - save_image_post( - bmain, op, ibuf, ima, ok, true, relbase, relative, do_newpath, simopts->filepath); - ED_space_image_release_buffer(sima, ibuf, lock); - } - /* regular mono pipeline */ - else if (is_mono) { - if (is_exr_rr) { - ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, NULL, layer); - } - else { - colormanaged_ibuf = IMB_colormanagement_imbuf_for_write( - ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf); - ok = BKE_imbuf_write_as(colormanaged_ibuf, simopts->filepath, imf, save_copy); - save_imbuf_post(ibuf, colormanaged_ibuf); - } - save_image_post(bmain, - op, - ibuf, - ima, - ok, - (is_exr_rr ? true : save_copy), - relbase, - relative, - do_newpath, - simopts->filepath); - ED_space_image_release_buffer(sima, ibuf, lock); - } - /* individual multiview images */ - else if (imf->views_format == R_IMF_VIEWS_INDIVIDUAL) { - int i; - unsigned char planes = ibuf->planes; - const int totviews = (rr ? BLI_listbase_count(&rr->views) : BLI_listbase_count(&ima->views)); - - if (!is_exr_rr) { - ED_space_image_release_buffer(sima, ibuf, lock); - } - - for (i = 0; i < totviews; i++) { - char filepath[FILE_MAX]; - bool ok_view = false; - const char *view = rr ? ((RenderView *)BLI_findlink(&rr->views, i))->name : - ((ImageView *)BLI_findlink(&ima->views, i))->name; - - if (is_exr_rr) { - BKE_scene_multiview_view_filepath_get(&scene->r, simopts->filepath, view, filepath); - ok_view = RE_WriteRenderResult(op->reports, rr, filepath, imf, view, layer); - save_image_post( - bmain, op, ibuf, ima, ok_view, true, relbase, relative, do_newpath, filepath); - } - else { - /* copy iuser to get the correct ibuf for this view */ - ImageUser iuser = sima->iuser; - iuser.view = i; - iuser.flag &= ~IMA_SHOW_STEREO; - - if (rr) { - BKE_image_multilayer_index(rr, &iuser); - } - else { - BKE_image_multiview_index(ima, &iuser); - } - - ibuf = BKE_image_acquire_ibuf(sima->image, &iuser, &lock); - ibuf->planes = planes; - - BKE_scene_multiview_view_filepath_get(&scene->r, simopts->filepath, view, filepath); - - colormanaged_ibuf = IMB_colormanagement_imbuf_for_write( - ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf); - ok_view = BKE_imbuf_write_as( - colormanaged_ibuf, filepath, &simopts->im_format, save_copy); - save_imbuf_post(ibuf, colormanaged_ibuf); - save_image_post( - bmain, op, ibuf, ima, ok_view, true, relbase, relative, do_newpath, filepath); - BKE_image_release_ibuf(sima->image, ibuf, lock); - } - ok &= ok_view; - } - - if (is_exr_rr) { - ED_space_image_release_buffer(sima, ibuf, lock); - } - } - /* stereo (multiview) images */ - else if (simopts->im_format.views_format == R_IMF_VIEWS_STEREO_3D) { - if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) { - ok = RE_WriteRenderResult(op->reports, rr, simopts->filepath, imf, NULL, layer); - save_image_post( - bmain, op, ibuf, ima, ok, true, relbase, relative, do_newpath, simopts->filepath); - ED_space_image_release_buffer(sima, ibuf, lock); - } - else { - ImBuf *ibuf_stereo[2] = {NULL}; - - unsigned char planes = ibuf->planes; - const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME}; - int i; + ImageUser *iuser = &sima->iuser; - /* we need to get the specific per-view buffers */ - ED_space_image_release_buffer(sima, ibuf, lock); + opts->relative = (RNA_struct_find_property(op->ptr, "relative_path") && + RNA_boolean_get(op->ptr, "relative_path")); + opts->save_copy = (RNA_struct_find_property(op->ptr, "copy") && + RNA_boolean_get(op->ptr, "copy")); + opts->save_as_render = (RNA_struct_find_property(op->ptr, "save_as_render") && + RNA_boolean_get(op->ptr, "save_as_render")); - for (i = 0; i < 2; i++) { - ImageUser iuser = sima->iuser; - iuser.flag &= ~IMA_SHOW_STEREO; - - if (rr) { - int id = BLI_findstringindex(&rr->views, names[i], offsetof(RenderView, name)); - iuser.view = id; - BKE_image_multilayer_index(rr, &iuser); - } - else { - iuser.view = i; - BKE_image_multiview_index(ima, &iuser); - } - - ibuf = BKE_image_acquire_ibuf(sima->image, &iuser, &lock); - - if (ibuf == NULL) { - BKE_report(op->reports, - RPT_ERROR, - "Did not write, unexpected error when saving stereo image"); - goto cleanup; - } - - ibuf->planes = planes; - - /* color manage the ImBuf leaving it ready for saving */ - colormanaged_ibuf = IMB_colormanagement_imbuf_for_write( - ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf); - - BKE_imbuf_write_prepare(colormanaged_ibuf, imf); - IMB_prepare_write_ImBuf(IMB_isfloat(colormanaged_ibuf), colormanaged_ibuf); - - /* duplicate buffer to prevent locker issue when using render result */ - ibuf_stereo[i] = IMB_dupImBuf(colormanaged_ibuf); - - save_imbuf_post(ibuf, colormanaged_ibuf); - BKE_image_release_ibuf(sima->image, ibuf, lock); - } - - ibuf = IMB_stereo3d_ImBuf(imf, ibuf_stereo[0], ibuf_stereo[1]); - - /* save via traditional path */ - ok = BKE_imbuf_write_as(ibuf, simopts->filepath, imf, save_copy); - - IMB_freeImBuf(ibuf); + WM_cursor_wait(1); - for (i = 0; i < 2; i++) { - IMB_freeImBuf(ibuf_stereo[i]); - } - } - } + bool ok = BKE_image_save(op->reports, bmain, ima, iuser, opts); - WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, sima->image); - } - else { - cleanup: - ED_space_image_release_buffer(sima, ibuf, lock); - } + WM_cursor_wait(0); - if (rr) { - BKE_image_release_renderresult(scene, ima); - } + /* Remember file path for next save. */ + BLI_strncpy(G.ima, opts->filepath, sizeof(G.ima)); - WM_cursor_wait(0); + WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima); return ok; } @@ -2208,18 +1855,20 @@ static void image_save_as_free(wmOperator *op) static int image_save_as_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); SpaceImage *sima = CTX_wm_space_image(C); - SaveImageOptions simopts; + ImageSaveOptions opts; - save_image_options_defaults(&simopts); + BKE_image_save_options_init(&opts, bmain, scene); /* just in case to initialize values, * these should be set on invoke or by the caller. */ - save_image_options_init(bmain, &simopts, sima, CTX_data_scene(C), false, false); + image_save_options_init(bmain, &opts, sima->image, &sima->iuser, false, false); - save_image_options_from_op(bmain, &simopts, op); + image_save_options_from_op(bmain, &opts, op); + opts.do_newpath = true; - save_image_doit(C, sima, op, &simopts, true); + save_image_op(C, sima, op, &opts); image_save_as_free(op); return OPERATOR_FINISHED; @@ -2237,7 +1886,7 @@ static int image_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS SpaceImage *sima = CTX_wm_space_image(C); Image *ima = ED_space_image(sima); Scene *scene = CTX_data_scene(C); - SaveImageOptions simopts; + ImageSaveOptions opts; PropertyRNA *prop; const bool save_as_render = ((ima->source == IMA_SRC_VIEWER) || (ima->flag & IMA_VIEW_AS_RENDER)); @@ -2246,12 +1895,12 @@ static int image_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS return image_save_as_exec(C, op); } - save_image_options_defaults(&simopts); + BKE_image_save_options_init(&opts, bmain, scene); - if (save_image_options_init(bmain, &simopts, sima, scene, true, save_as_render) == 0) { + if (image_save_options_init(bmain, &opts, ima, &sima->iuser, true, save_as_render) == 0) { return OPERATOR_CANCELLED; } - save_image_options_to_op(&simopts, op); + image_save_options_to_op(&opts, op); /* enable save_copy by default for render results */ if (ELEM(ima->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE) && @@ -2261,8 +1910,8 @@ static int image_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS RNA_boolean_set(op->ptr, "save_as_render", save_as_render); - op->customdata = MEM_mallocN(sizeof(simopts.im_format), __func__); - memcpy(op->customdata, &simopts.im_format, sizeof(simopts.im_format)); + op->customdata = MEM_mallocN(sizeof(opts.im_format), __func__); + memcpy(op->customdata, &opts.im_format, sizeof(opts.im_format)); /* show multiview save options only if image has multiviews */ prop = RNA_struct_find_property(op->ptr, "show_multiview"); @@ -2270,7 +1919,7 @@ static int image_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS prop = RNA_struct_find_property(op->ptr, "use_multiview"); RNA_property_boolean_set(op->ptr, prop, BKE_image_is_multiview(ima)); - image_filesel(C, op, simopts.filepath); + image_filesel(C, op, opts.filepath); return OPERATOR_RUNNING_MODAL; } @@ -2378,23 +2027,23 @@ static int image_save_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); SpaceImage *sima = CTX_wm_space_image(C); Scene *scene = CTX_data_scene(C); - SaveImageOptions simopts; + ImageSaveOptions opts; - save_image_options_defaults(&simopts); - if (save_image_options_init(bmain, &simopts, sima, scene, false, false) == 0) { + BKE_image_save_options_init(&opts, bmain, scene); + if (image_save_options_init(bmain, &opts, sima->image, &sima->iuser, false, false) == 0) { return OPERATOR_CANCELLED; } - save_image_options_from_op(bmain, &simopts, op); + image_save_options_from_op(bmain, &opts, op); - if (BLI_exists(simopts.filepath) && BLI_file_is_writable(simopts.filepath)) { - if (save_image_doit(C, sima, op, &simopts, false)) { + if (BLI_exists(opts.filepath) && BLI_file_is_writable(opts.filepath)) { + if (save_image_op(C, sima, op, &opts)) { /* report since this can be called from key-shortcuts */ - BKE_reportf(op->reports, RPT_INFO, "Saved Image '%s'", simopts.filepath); + BKE_reportf(op->reports, RPT_INFO, "Saved Image '%s'", opts.filepath); } } else { BKE_reportf( - op->reports, RPT_ERROR, "Cannot save image, path '%s' is not writable", simopts.filepath); + op->reports, RPT_ERROR, "Cannot save image, path '%s' is not writable", opts.filepath); return OPERATOR_CANCELLED; } @@ -2897,14 +2546,10 @@ void IMAGE_OT_invert(wmOperatorType *ot) static bool image_pack_test(bContext *C, wmOperator *op) { Image *ima = CTX_data_edit_image(C); - const bool as_png = RNA_boolean_get(op->ptr, "as_png"); if (!ima) { return 0; } - if (!as_png && BKE_image_has_packedfile(ima)) { - return 0; - } if (ima->source == IMA_SRC_SEQUENCE || ima->source == IMA_SRC_MOVIE) { BKE_report(op->reports, RPT_ERROR, "Packing movies or image sequences not supported"); @@ -2918,19 +2563,12 @@ static int image_pack_exec(bContext *C, wmOperator *op) { struct Main *bmain = CTX_data_main(C); Image *ima = CTX_data_edit_image(C); - ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL); - const bool as_png = RNA_boolean_get(op->ptr, "as_png"); if (!image_pack_test(C, op)) { return OPERATOR_CANCELLED; } - if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) { - BKE_report(op->reports, RPT_ERROR, "Cannot pack edited image from disk, only as internal PNG"); - return OPERATOR_CANCELLED; - } - - if (as_png) { + if (BKE_image_is_dirty(ima)) { BKE_image_memorypack(ima); } else { @@ -2939,46 +2577,9 @@ static int image_pack_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima); - BKE_image_release_ibuf(ima, ibuf, NULL); - return OPERATOR_FINISHED; } -static int image_pack_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) -{ - Image *ima = CTX_data_edit_image(C); - ImBuf *ibuf; - uiPopupMenu *pup; - uiLayout *layout; - const bool as_png = RNA_boolean_get(op->ptr, "as_png"); - - if (!image_pack_test(C, op)) { - return OPERATOR_CANCELLED; - } - - ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL); - - if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) { - pup = UI_popup_menu_begin(C, IFACE_("OK"), ICON_QUESTION); - layout = UI_popup_menu_layout(pup); - uiItemBooleanO(layout, - IFACE_("Can't pack edited image from disk, pack as internal PNG?"), - ICON_NONE, - op->idname, - "as_png", - 1); - UI_popup_menu_end(C, pup); - - BKE_image_release_ibuf(ima, ibuf, NULL); - - return OPERATOR_INTERFACE; - } - - BKE_image_release_ibuf(ima, ibuf, NULL); - - return image_pack_exec(C, op); -} - void IMAGE_OT_pack(wmOperatorType *ot) { /* identifiers */ @@ -2988,13 +2589,9 @@ void IMAGE_OT_pack(wmOperatorType *ot) /* api callbacks */ ot->exec = image_pack_exec; - ot->invoke = image_pack_invoke; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* properties */ - RNA_def_boolean(ot->srna, "as_png", 0, "Pack As PNG", "Pack image as lossless PNG"); } /********************* unpack operator *********************/ @@ -3164,6 +2761,7 @@ static void image_sample_draw(const bContext *C, ARegion *ar, void *arg_info) glEnable(GL_COLOR_LOGIC_OP); glLogicOp(GL_XOR); + GPU_line_width(1.0f); imm_draw_box_wire_2d(pos, (float)sample_rect_fl.xmin, (float)sample_rect_fl.ymin, @@ -3403,14 +3001,14 @@ static void image_sample_apply(bContext *C, wmOperator *op, const wmEvent *event { ScrArea *sa, *cur = curarea; - node_curvemap_sample(fp); /* sends global to node editor */ + node_curvemap_sample(fp); /* sends global to node editor */ for (sa = G.curscreen->areabase.first; sa; sa = sa->next) { if (sa->spacetype == SPACE_NODE) { areawinset(sa->win); scrarea_do_windraw(sa); } } - node_curvemap_sample(NULL); /* clears global in node editor */ + node_curvemap_sample(NULL); /* clears global in node editor */ curarea = cur; } #endif @@ -3649,9 +3247,12 @@ static int image_record_composite_apply(bContext *C, wmOperator *op) // XXX scene->nodetree->test_break = NULL; BKE_image_all_free_anim_ibufs(scene->r.cfra); - ntreeCompositTagAnimated(scene->nodetree); - ntreeCompositExecTree(scene->nodetree, &scene->r, 0, scene->r.cfra != rcd->old_cfra, - &scene->view_settings, &scene->display_settings); /* 1 is no previews */ + ntreeCompositExecTree(scene->nodetree, + &scene->r, + 0, + scene->r.cfra != rcd->old_cfra, + &scene->view_settings, + &scene->display_settings); /* 1 is no previews */ ED_area_tag_redraw(CTX_wm_area(C)); @@ -3714,7 +3315,8 @@ static int image_record_composite_exec(bContext *C, wmOperator *op) if (!image_record_composite_init(C, op)) return OPERATOR_CANCELLED; - while (image_record_composite_apply(C, op)) {} + while (image_record_composite_apply(C, op)) { + } image_record_composite_exit(C, op); diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index e1875fd6129..386e258a833 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -115,66 +115,6 @@ static void image_user_refresh_scene(const bContext *C, SpaceImage *sima) ED_space_image_auto_set(C, sima); } -/* ******************** manage regions ********************* */ - -ARegion *image_has_buttons_region(ScrArea *sa) -{ - ARegion *ar, *arnew; - - ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); - if (ar) { - return ar; - } - - /* add subdiv level; after header */ - ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); - - /* is error! */ - if (ar == NULL) { - return NULL; - } - - arnew = MEM_callocN(sizeof(ARegion), "buttons for image"); - - BLI_insertlinkafter(&sa->regionbase, ar, arnew); - arnew->regiontype = RGN_TYPE_UI; - arnew->alignment = RGN_ALIGN_RIGHT; - - arnew->flag = RGN_FLAG_HIDDEN; - - return arnew; -} - -ARegion *image_has_tools_region(ScrArea *sa) -{ - ARegion *ar, *arnew; - - ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS); - if (ar) { - return ar; - } - - /* add subdiv level; after buttons */ - ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); - - /* is error! */ - if (ar == NULL) { - return NULL; - } - - arnew = MEM_callocN(sizeof(ARegion), "scopes for image"); - - BLI_insertlinkafter(&sa->regionbase, ar, arnew); - arnew->regiontype = RGN_TYPE_TOOLS; - arnew->alignment = RGN_ALIGN_LEFT; - - arnew->flag = RGN_FLAG_HIDDEN; - - image_scopes_tag_refresh(sa); - - return arnew; -} - /* ******************** default callbacks for image space ***************** */ static SpaceLink *image_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene)) @@ -188,13 +128,20 @@ static SpaceLink *image_new(const ScrArea *UNUSED(area), const Scene *UNUSED(sce simage->lock = true; simage->flag = SI_SHOW_GPENCIL | SI_USE_ALPHA | SI_COORDFLOATS; - simage->iuser.ok = true; - simage->iuser.frames = 100; + BKE_imageuser_default(&simage->iuser); simage->iuser.flag = IMA_SHOW_STEREO | IMA_ANIM_ALWAYS; scopes_new(&simage->scopes); simage->sample_line_hist.height = 100; + /* tool header */ + ar = MEM_callocN(sizeof(ARegion), "tool header for image"); + + BLI_addtail(&simage->regionbase, ar); + ar->regiontype = RGN_TYPE_TOOL_HEADER; + ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP; + ar->flag = RGN_FLAG_HIDDEN | RGN_FLAG_HIDDEN_BY_USER; + /* header */ ar = MEM_callocN(sizeof(ARegion), "header for image"); @@ -291,9 +238,6 @@ static void image_operatortypes(void) WM_operatortype_append(IMAGE_OT_sample_line); WM_operatortype_append(IMAGE_OT_curves_point_set); - WM_operatortype_append(IMAGE_OT_properties); - WM_operatortype_append(IMAGE_OT_toolshelf); - WM_operatortype_append(IMAGE_OT_change_frame); WM_operatortype_append(IMAGE_OT_read_viewlayers); @@ -593,29 +537,26 @@ static void image_main_region_init(wmWindowManager *wm, ARegion *ar) /* mask polls mode */ keymap = WM_keymap_ensure(wm->defaultconf, "Mask Editing", 0, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); /* image paint polls for mode */ keymap = WM_keymap_ensure(wm->defaultconf, "Curve", 0, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "Paint Curve", 0, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "Image Paint", 0, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "UV Editor", 0, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); - keymap = WM_keymap_ensure(wm->defaultconf, "UV Sculpt", 0, 0); - WM_event_add_keymap_handler(&ar->handlers, keymap); - /* own keymaps */ keymap = WM_keymap_ensure(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "Image", SPACE_IMAGE, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } static void image_main_region_draw(const bContext *C, ARegion *ar) @@ -630,7 +571,7 @@ static void image_main_region_draw(const bContext *C, ARegion *ar) Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); View2D *v2d = &ar->v2d; - //View2DScrollers *scrollers; + // View2DScrollers *scrollers; float col[3]; /* XXX This is in order to draw UI batches with the DRW @@ -664,7 +605,7 @@ static void image_main_region_draw(const bContext *C, ARegion *ar) ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); - ED_uvedit_draw_main(sima, ar, scene, view_layer, obedit, obact, depsgraph); + ED_uvedit_draw_main(sima, scene, view_layer, obedit, obact, depsgraph); /* check for mask (delay draw) */ if (ED_space_image_show_uvedit(sima, obedit)) { @@ -742,13 +683,6 @@ static void image_main_region_draw(const bContext *C, ARegion *ar) WM_gizmomap_draw(ar->gizmo_map, C, WM_GIZMOMAP_DRAWSTEP_2D); draw_image_cache(C, ar); - - /* scrollers? */ -#if 0 - scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_UNIT_VALUES, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY); - UI_view2d_scrollers_draw(C, v2d, scrollers); - UI_view2d_scrollers_free(scrollers); -#endif } static void image_main_region_listener( @@ -806,6 +740,33 @@ static void image_buttons_region_init(wmWindowManager *wm, ARegion *ar) WM_event_add_keymap_handler(&ar->handlers, keymap); } +static void image_buttons_region_layout(const bContext *C, ARegion *ar) +{ + const enum eContextObjectMode mode = CTX_data_mode_enum(C); + const char *contexts_base[3] = {NULL}; + + const char **contexts = contexts_base; + + SpaceImage *sima = CTX_wm_space_image(C); + switch (sima->mode) { + case SI_MODE_VIEW: + break; + case SI_MODE_PAINT: + ARRAY_SET_ITEMS(contexts, ".paint_common_2d", ".imagepaint_2d"); + break; + case SI_MODE_MASK: + break; + case SI_MODE_UV: + if (mode == CTX_MODE_EDIT_MESH) { + ARRAY_SET_ITEMS(contexts, ".uv_sculpt"); + } + break; + } + + const bool vertical = true; + ED_region_panels_layout_ex(C, ar, contexts_base, -1, vertical); +} + static void image_buttons_region_draw(const bContext *C, ARegion *ar) { SpaceImage *sima = CTX_wm_space_image(C); @@ -832,7 +793,8 @@ static void image_buttons_region_draw(const bContext *C, ARegion *ar) } ED_space_image_release_buffer(sima, ibuf, lock); - ED_region_panels(C, ar); + /* Layout handles details. */ + ED_region_panels_draw(C, ar); } static void image_buttons_region_listener(wmWindow *UNUSED(win), @@ -1077,6 +1039,7 @@ void ED_spacetype_image(void) art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; art->listener = image_buttons_region_listener; art->init = image_buttons_region_init; + art->layout = image_buttons_region_layout; art->draw = image_buttons_region_draw; BLI_addhead(&st->regiontypes, art); @@ -1096,6 +1059,17 @@ void ED_spacetype_image(void) art->draw = image_tools_region_draw; BLI_addhead(&st->regiontypes, art); + /* regions: tool header */ + art = MEM_callocN(sizeof(ARegionType), "spacetype image tool header region"); + art->regionid = RGN_TYPE_TOOL_HEADER; + art->prefsizey = HEADERY; + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER; + art->listener = image_header_region_listener; + art->init = image_header_region_init; + art->draw = image_header_region_draw; + art->message_subscribe = ED_area_do_mgs_subscribe_for_tool_header; + BLI_addhead(&st->regiontypes, art); + /* regions: header */ art = MEM_callocN(sizeof(ARegionType), "spacetype image region"); art->regionid = RGN_TYPE_HEADER; diff --git a/source/blender/editors/space_info/CMakeLists.txt b/source/blender/editors/space_info/CMakeLists.txt index bb403751fe2..ad410e0aade 100644 --- a/source/blender/editors/space_info/CMakeLists.txt +++ b/source/blender/editors/space_info/CMakeLists.txt @@ -22,15 +22,15 @@ set(INC ../../blenlib ../../blenloader ../../blentranslation - ../../depsgraph - ../../imbuf ../../bmesh + ../../depsgraph ../../gpu + ../../imbuf ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_info/info_draw.c b/source/blender/editors/space_info/info_draw.c index a7d6694b362..c588df9528f 100644 --- a/source/blender/editors/space_info/info_draw.c +++ b/source/blender/editors/space_info/info_draw.c @@ -116,7 +116,7 @@ static int report_textview_begin(TextViewContext *tvc) // SpaceConsole *sc = (SpaceConsole *)tvc->arg1; ReportList *reports = (ReportList *)tvc->arg2; - tvc->lheight = 14 * UI_DPI_FAC; //sc->lheight; + tvc->lheight = 14 * UI_DPI_FAC; // sc->lheight; tvc->sel_start = 0; tvc->sel_end = 0; @@ -256,7 +256,7 @@ static int info_textview_main__internal(struct SpaceInfo *sinfo, /* view */ tvc.sel_start = 0; tvc.sel_end = 0; - tvc.lheight = 14 * UI_DPI_FAC; //sc->lheight; + tvc.lheight = 14 * UI_DPI_FAC; // sc->lheight; tvc.ymin = v2d->cur.ymin; tvc.ymax = v2d->cur.ymax; tvc.winx = ar->winx - V2D_SCROLL_WIDTH; diff --git a/source/blender/editors/space_info/info_report.c b/source/blender/editors/space_info/info_report.c index 707838cf7e5..4c00512d838 100644 --- a/source/blender/editors/space_info/info_report.c +++ b/source/blender/editors/space_info/info_report.c @@ -41,16 +41,52 @@ #include "info_intern.h" +static void reports_select_all(ReportList *reports, int report_mask, int action) +{ + if (action == SEL_TOGGLE) { + action = SEL_SELECT; + for (Report *report = reports->list.last; report; report = report->prev) { + if ((report->type & report_mask) && (report->flag & SELECT)) { + action = SEL_DESELECT; + break; + } + } + } + + for (Report *report = reports->list.last; report; report = report->prev) { + if (report->type & report_mask) { + switch (action) { + case SEL_SELECT: + report->flag = SELECT; + break; + case SEL_DESELECT: + report->flag = ~SELECT; + break; + case SEL_INVERT: + report->flag ^= SELECT; + break; + default: + BLI_assert(0); + } + } + } +} + int info_report_mask(SpaceInfo *UNUSED(sinfo)) { #if 0 int report_mask = 0; - if (sinfo->rpt_mask & INFO_RPT_DEBUG) report_mask |= RPT_DEBUG_ALL; - if (sinfo->rpt_mask & INFO_RPT_INFO) report_mask |= RPT_INFO_ALL; - if (sinfo->rpt_mask & INFO_RPT_OP) report_mask |= RPT_OPERATOR_ALL; - if (sinfo->rpt_mask & INFO_RPT_WARN) report_mask |= RPT_WARNING_ALL; - if (sinfo->rpt_mask & INFO_RPT_ERR) report_mask |= RPT_ERROR_ALL; + if (sinfo->rpt_mask & INFO_RPT_DEBUG) + report_mask |= RPT_DEBUG_ALL; + if (sinfo->rpt_mask & INFO_RPT_INFO) + report_mask |= RPT_INFO_ALL; + if (sinfo->rpt_mask & INFO_RPT_OP) + report_mask |= RPT_OPERATOR_ALL; + if (sinfo->rpt_mask & INFO_RPT_WARN) + report_mask |= RPT_WARNING_ALL; + if (sinfo->rpt_mask & INFO_RPT_ERR) + report_mask |= RPT_ERROR_ALL; return report_mask; #endif @@ -71,10 +107,8 @@ static int report_replay_exec(bContext *C, wmOperator *UNUSED(op)) sc->type = CONSOLE_TYPE_PYTHON; for (report = reports->list.last; report; report = report->prev) { - if ((report->type & report_mask) && - (report->type & RPT_OPERATOR_ALL | RPT_PROPERTY_ALL) && - (report->flag & SELECT)) - { + if ((report->type & report_mask) && (report->type & RPT_OPERATOR_ALL | RPT_PROPERTY_ALL) && + (report->flag & SELECT)) { console_history_add_str(sc, report->message, 0); WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL); @@ -109,12 +143,20 @@ void INFO_OT_report_replay(wmOperatorType *ot) static int select_report_pick_exec(bContext *C, wmOperator *op) { int report_index = RNA_int_get(op->ptr, "report_index"); + bool extend = RNA_boolean_get(op->ptr, "extend"); + Report *report = BLI_findlink(&CTX_wm_reports(C)->list, report_index); + SpaceInfo *sinfo = CTX_wm_space_info(C); + ReportList *reports = CTX_wm_reports(C); + const int report_mask = info_report_mask(sinfo); if (!report) { return OPERATOR_CANCELLED; } + if (!extend) { + reports_select_all(reports, report_mask, SEL_DESELECT); + } report->flag ^= SELECT; /* toggle */ ED_area_tag_redraw(CTX_wm_area(C)); @@ -152,8 +194,11 @@ void INFO_OT_select_pick(wmOperatorType *ot) /* ot->flag = OPTYPE_REGISTER; */ /* properties */ + PropertyRNA *prop; RNA_def_int( ot->srna, "report_index", 0, 0, INT_MAX, "Report", "Index of the report", 0, INT_MAX); + prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend report selection"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } static int report_select_all_exec(bContext *C, wmOperator *op) @@ -163,34 +208,7 @@ static int report_select_all_exec(bContext *C, wmOperator *op) const int report_mask = info_report_mask(sinfo); int action = RNA_enum_get(op->ptr, "action"); - - if (action == SEL_TOGGLE) { - action = SEL_SELECT; - for (Report *report = reports->list.last; report; report = report->prev) { - if ((report->type & report_mask) && (report->flag & SELECT)) { - action = SEL_DESELECT; - break; - } - } - } - - for (Report *report = reports->list.last; report; report = report->prev) { - if (report->type & report_mask) { - switch (action) { - case SEL_SELECT: - report->flag = SELECT; - break; - case SEL_DESELECT: - report->flag = ~SELECT; - break; - case SEL_INVERT: - report->flag ^= SELECT; - break; - default: - BLI_assert(0); - } - } - } + reports_select_all(reports, report_mask, action); ED_area_tag_redraw(CTX_wm_area(C)); diff --git a/source/blender/editors/space_info/space_info.c b/source/blender/editors/space_info/space_info.c index 6ed9d80d145..8eddf90b06b 100644 --- a/source/blender/editors/space_info/space_info.c +++ b/source/blender/editors/space_info/space_info.c @@ -85,7 +85,7 @@ static SpaceLink *info_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scen ar->v2d.minzoom = ar->v2d.maxzoom = 1.0f; /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */ - //ar->v2d.keepzoom = (V2D_KEEPASPECT|V2D_LIMITZOOM); + // ar->v2d.keepzoom = (V2D_KEEPASPECT|V2D_LIMITZOOM); return (SpaceLink *)sinfo; } @@ -160,9 +160,8 @@ static void info_main_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); /* scrollers */ - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_GRID_CLAMP); - UI_view2d_scrollers_draw(C, v2d, scrollers); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); } diff --git a/source/blender/editors/space_info/textview.c b/source/blender/editors/space_info/textview.c index c81e7574186..108803a865f 100644 --- a/source/blender/editors/space_info/textview.c +++ b/source/blender/editors/space_info/textview.c @@ -161,8 +161,9 @@ static int console_draw_string(ConsoleDrawContext *cdc, CLAMP(ofs, 0, str_len); *cdc->pos_pick += str_len - ofs; } - else + else { *cdc->pos_pick += str_len + 1; + } } cdc->xy[1] = y_next; diff --git a/source/blender/editors/space_nla/CMakeLists.txt b/source/blender/editors/space_nla/CMakeLists.txt index 3048c64c49e..60152bffaf4 100644 --- a/source/blender/editors/space_nla/CMakeLists.txt +++ b/source/blender/editors/space_nla/CMakeLists.txt @@ -25,8 +25,8 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_nla/nla_buttons.c b/source/blender/editors/space_nla/nla_buttons.c index b19dc3680bf..719efc7eeac 100644 --- a/source/blender/editors/space_nla/nla_buttons.c +++ b/source/blender/editors/space_nla/nla_buttons.c @@ -59,7 +59,7 @@ static void do_nla_region_buttons(bContext *C, void *UNUSED(arg), int UNUSED(event)) { - //Scene *scene = CTX_data_scene(C); + // Scene *scene = CTX_data_scene(C); #if 0 switch (event) { /* pass */ @@ -81,11 +81,12 @@ bool nla_panel_context(const bContext *C, short found = 0; /* not bool, since we need to indicate "found but not ideal" status */ int filter; - /* for now, only draw if we could init the anim-context info (necessary for all animation-related tools) - * to work correctly is able to be correctly retrieved. There's no point showing empty panels? - */ - if (ANIM_animdata_get_context(C, &ac) == 0) + /* For now, only draw if we could init the anim-context info + * (necessary for all animation-related tools) + * to work correctly is able to be correctly retrieved. There's no point showing empty panels? */ + if (ANIM_animdata_get_context(C, &ac) == 0) { return false; + } /* extract list of active channel(s), of which we should only take the first one * - we need the channels flag to get the active AnimData block when there are no NLA Tracks @@ -168,8 +169,9 @@ bool nla_panel_context(const bContext *C, } } - if (found > 0) + if (found > 0) { break; + } } /* free temp data */ @@ -208,10 +210,12 @@ static bool nla_strip_actclip_panel_poll(const bContext *C, PanelType *UNUSED(pt PointerRNA ptr; NlaStrip *strip; - if (!nla_panel_context(C, NULL, NULL, &ptr)) + if (!nla_panel_context(C, NULL, NULL, &ptr)) { return 0; - if (ptr.data == NULL) + } + if (ptr.data == NULL) { return 0; + } strip = ptr.data; return (strip->type == NLASTRIP_TYPE_CLIP); @@ -222,15 +226,18 @@ static bool nla_strip_eval_panel_poll(const bContext *C, PanelType *UNUSED(pt)) PointerRNA ptr; NlaStrip *strip; - if (!nla_panel_context(C, NULL, NULL, &ptr)) + if (!nla_panel_context(C, NULL, NULL, &ptr)) { return 0; - if (ptr.data == NULL) + } + if (ptr.data == NULL) { return 0; + } strip = ptr.data; - if (strip->type == NLASTRIP_TYPE_SOUND) + if (strip->type == NLASTRIP_TYPE_SOUND) { return 0; + } return 1; } @@ -247,8 +254,9 @@ static void nla_panel_animdata(const bContext *C, Panel *pa) uiBlock *block; /* check context and also validity of pointer */ - if (!nla_panel_context(C, &adt_ptr, NULL, NULL)) + if (!nla_panel_context(C, &adt_ptr, NULL, NULL)) { return; + } /* adt = adt_ptr.data; */ @@ -312,8 +320,9 @@ static void nla_panel_track(const bContext *C, Panel *pa) uiBlock *block; /* check context and also validity of pointer */ - if (!nla_panel_context(C, NULL, &nlt_ptr, NULL)) + if (!nla_panel_context(C, NULL, &nlt_ptr, NULL)) { return; + } block = uiLayoutGetBlock(layout); UI_block_func_handle_set(block, do_nla_region_buttons, NULL); @@ -332,8 +341,9 @@ static void nla_panel_properties(const bContext *C, Panel *pa) uiBlock *block; short showEvalProps = 1; - if (!nla_panel_context(C, NULL, NULL, &strip_ptr)) + if (!nla_panel_context(C, NULL, NULL, &strip_ptr)) { return; + } block = uiLayoutGetBlock(layout); UI_block_func_handle_set(block, do_nla_region_buttons, NULL); @@ -353,8 +363,9 @@ static void nla_panel_properties(const bContext *C, Panel *pa) /* Evaluation-Related Strip Properties ------------------ */ /* sound properties strips don't have these settings */ - if (RNA_enum_get(&strip_ptr, "type") == NLASTRIP_TYPE_SOUND) + if (RNA_enum_get(&strip_ptr, "type") == NLASTRIP_TYPE_SOUND) { showEvalProps = 0; + } /* only show if allowed to... */ if (showEvalProps) { @@ -398,8 +409,9 @@ static void nla_panel_actclip(const bContext *C, Panel *pa) uiBlock *block; /* check context and also validity of pointer */ - if (!nla_panel_context(C, NULL, NULL, &strip_ptr)) + if (!nla_panel_context(C, NULL, NULL, &strip_ptr)) { return; + } block = uiLayoutGetBlock(layout); UI_block_func_handle_set(block, do_nla_region_buttons, NULL); @@ -416,7 +428,8 @@ static void nla_panel_actclip(const bContext *C, Panel *pa) uiItemR(column, &strip_ptr, "action_frame_start", 0, IFACE_("Start Frame"), ICON_NONE); uiItemR(column, &strip_ptr, "action_frame_end", 0, IFACE_("End Frame"), ICON_NONE); - // XXX: this layout may actually be too abstract and confusing, and may be better using standard column layout + /* XXX: this layout may actually be too abstract and confusing, + * and may be better using standard column layout. */ row = uiLayoutRow(layout, false); uiItemR(row, &strip_ptr, "use_sync_length", 0, IFACE_("Sync Length"), ICON_NONE); uiItemO(row, IFACE_("Now"), ICON_FILE_REFRESH, "NLA_OT_action_sync_length"); @@ -438,8 +451,9 @@ static void nla_panel_evaluation(const bContext *C, Panel *pa) uiBlock *block; /* check context and also validity of pointer */ - if (!nla_panel_context(C, NULL, NULL, &strip_ptr)) + if (!nla_panel_context(C, NULL, NULL, &strip_ptr)) { return; + } block = uiLayoutGetBlock(layout); UI_block_func_handle_set(block, do_nla_region_buttons, NULL); @@ -471,8 +485,9 @@ static void nla_panel_modifiers(const bContext *C, Panel *pa) uiBlock *block; /* check context and also validity of pointer */ - if (!nla_panel_context(C, NULL, NULL, &strip_ptr)) + if (!nla_panel_context(C, NULL, NULL, &strip_ptr)) { return; + } strip = strip_ptr.data; block = uiLayoutGetBlock(pa->layout); @@ -483,7 +498,8 @@ static void nla_panel_modifiers(const bContext *C, Panel *pa) row = uiLayoutRow(pa->layout, false); block = uiLayoutGetBlock(row); - // FIXME: we need to set the only-active property so that this will only add modifiers for the active strip (not all selected) + // FIXME: we need to set the only-active property so that this + // will only add modifiers for the active strip (not all selected). uiItemMenuEnumO( row, (bContext *)C, "NLA_OT_fmodifier_add", "type", IFACE_("Add Modifier"), ICON_NONE); @@ -562,27 +578,3 @@ void nla_buttons_register(ARegionType *art) pt->poll = nla_strip_eval_panel_poll; BLI_addtail(&art->paneltypes, pt); } - -static int nla_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = nla_has_buttons_region(sa); - - if (ar) - ED_region_toggle_hidden(C, ar); - - return OPERATOR_FINISHED; -} - -void NLA_OT_properties(wmOperatorType *ot) -{ - ot->name = "Toggle Sidebar"; - ot->idname = "NLA_OT_properties"; - ot->description = "Toggle the properties region visibility"; - - ot->exec = nla_properties_toggle_exec; - ot->poll = ED_operator_nla_active; - - /* flags */ - ot->flag = 0; -} diff --git a/source/blender/editors/space_nla/nla_channels.c b/source/blender/editors/space_nla/nla_channels.c index 90e70b835f8..4115d6b49ba 100644 --- a/source/blender/editors/space_nla/nla_channels.c +++ b/source/blender/editors/space_nla/nla_channels.c @@ -67,8 +67,9 @@ /* Depending on the channel that was clicked on, the mouse click will activate whichever * part of the channel is relevant. * - * NOTE: eventually, this should probably be phased out when many of these things are replaced with buttons - * --> Most channels are now selection only... + * NOTE: eventually, + * this should probably be phased out when many of these things are replaced with buttons + * --> Most channels are now selection only. */ static int mouse_nla_channels( @@ -90,9 +91,10 @@ static int mouse_nla_channels( ale = BLI_findlink(&anim_data, channel_index); if (ale == NULL) { /* channel not found */ - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: animation channel (index = %d) not found in mouse_anim_channels()\n", channel_index); + } ANIM_animdata_freelist(&anim_data); return 0; @@ -109,13 +111,15 @@ static int mouse_nla_channels( if (selectmode == SELECT_INVERT) { /* swap select */ sce->flag ^= SCE_DS_SELECTED; - if (adt) + if (adt) { adt->flag ^= ADT_UI_SELECTED; + } } else { sce->flag |= SCE_DS_SELECTED; - if (adt) + if (adt) { adt->flag |= ADT_UI_SELECTED; + } } notifierFlags |= (ND_ANIMCHAN | NA_SELECTED); @@ -132,33 +136,34 @@ static int mouse_nla_channels( if (selectmode == SELECT_INVERT) { /* swap select */ ED_object_base_select(base, BA_INVERT); - BKE_scene_object_base_flag_sync_from_base(base); - if (adt) + if (adt) { adt->flag ^= ADT_UI_SELECTED; + } } else { /* deselect all */ /* TODO: should this deselect all other types of channels too? */ for (Base *b = view_layer->object_bases.first; b; b = b->next) { ED_object_base_select(b, BA_DESELECT); - BKE_scene_object_base_flag_sync_from_base(b); - if (b->object->adt) + if (b->object->adt) { b->object->adt->flag &= ~(ADT_UI_SELECTED | ADT_UI_ACTIVE); + } } /* select object now */ ED_object_base_select(base, BA_SELECT); - BKE_scene_object_base_flag_sync_from_base(base); - if (adt) + if (adt) { adt->flag |= ADT_UI_SELECTED; + } } /* change active object - regardless of whether it is now selected [T37883] */ ED_object_base_activate(C, base); /* adds notifier */ - if ((adt) && (adt->flag & ADT_UI_SELECTED)) + if ((adt) && (adt->flag & ADT_UI_SELECTED)) { adt->flag |= ADT_UI_ACTIVE; + } /* notifiers - channel was selected */ notifierFlags |= (ND_ANIMCHAN | NA_SELECTED); @@ -198,8 +203,9 @@ static int mouse_nla_channels( } /* set active? */ - if ((ale->adt) && (ale->adt->flag & ADT_UI_SELECTED)) + if ((ale->adt) && (ale->adt->flag & ADT_UI_SELECTED)) { ale->adt->flag |= ADT_UI_ACTIVE; + } } notifierFlags |= (ND_ANIMCHAN | NA_SELECTED); @@ -213,13 +219,16 @@ static int mouse_nla_channels( /* offset for start of channel (on LHS of channel-list) */ if (ale->id) { /* special exception for materials and particles */ - if (ELEM(GS(ale->id->name), ID_MA, ID_PA)) + if (ELEM(GS(ale->id->name), ID_MA, ID_PA)) { offset = 21 + NLACHANNEL_BUTTON_WIDTH; - else + } + else { offset = 14; + } } - else + else { offset = 0; + } if (x >= (v2d->cur.xmax - NLACHANNEL_BUTTON_WIDTH)) { /* toggle protection (only if there's a toggle there) */ @@ -258,8 +267,9 @@ static int mouse_nla_channels( /* if NLA-Track is selected now, * make NLA-Track the 'active' one in the visible list */ - if (nlt->flag & NLATRACK_SELECTED) + if (nlt->flag & NLATRACK_SELECTED) { ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, nlt, ANIMTYPE_NLATRACK); + } /* notifier flags - channel was selected */ notifierFlags |= (ND_ANIMCHAN | NA_SELECTED); @@ -318,8 +328,9 @@ static int mouse_nla_channels( } /* set active? */ - if (adt->flag & ADT_UI_SELECTED) + if (adt->flag & ADT_UI_SELECTED) { adt->flag |= ADT_UI_ACTIVE; + } notifierFlags |= (ND_ANIMCHAN | NA_SELECTED); } @@ -327,8 +338,9 @@ static int mouse_nla_channels( break; } default: - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("Error: Invalid channel type in mouse_nla_channels()\n"); + } break; } @@ -355,8 +367,9 @@ static int nlachannels_mouseclick_invoke(bContext *C, wmOperator *op, const wmEv float x, y; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get useful pointers from animation context data */ snla = (SpaceNla *)ac.sl; @@ -364,15 +377,19 @@ static int nlachannels_mouseclick_invoke(bContext *C, wmOperator *op, const wmEv v2d = &ar->v2d; /* select mode is either replace (deselect all, then add) or add/extend */ - if (RNA_boolean_get(op->ptr, "extend")) + if (RNA_boolean_get(op->ptr, "extend")) { selectmode = SELECT_INVERT; - else + } + else { selectmode = SELECT_REPLACE; + } - /* figure out which channel user clicked in - * Note: although channels technically start at y= NLACHANNEL_FIRST, we need to adjust by half a channel's height - * so that the tops of channels get caught ok. Since NLACHANNEL_FIRST is really NLACHANNEL_HEIGHT, we simply use - * NLACHANNEL_HEIGHT_HALF. + /** + * Figure out which channel user clicked in: + * + * \note Although channels technically start at y= NLACHANNEL_FIRST, + * we need to adjust by half a channel's height so that the tops of channels get caught ok. + * Since NLACHANNEL_FIRST is really NLACHANNEL_HEIGHT, we simply use NLACHANNEL_HEIGHT_HALF. */ UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &x, &y); UI_view2d_listview_view_to_cell(v2d, @@ -428,8 +445,9 @@ static int nlachannels_pushdown_exec(bContext *C, wmOperator *op) int channel_index = RNA_int_get(op->ptr, "channel_index"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get anim-channel to use (or more specifically, the animdata block behind it) */ if (channel_index == -1) { @@ -555,13 +573,15 @@ static int nla_action_unlink_exec(bContext *C, wmOperator *op) AnimData *adt; /* check context and also validity of pointer */ - if (!nla_panel_context(C, &adt_ptr, NULL, NULL)) + if (!nla_panel_context(C, &adt_ptr, NULL, NULL)) { return OPERATOR_CANCELLED; + } /* get animdata */ adt = adt_ptr.data; - if (adt == NULL) + if (adt == NULL) { return OPERATOR_CANCELLED; + } /* do unlinking */ if (adt && adt->action) { @@ -698,8 +718,9 @@ static int nlaedit_add_tracks_exec(bContext *C, wmOperator *op) bool op_done = false; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* perform adding in two passes - existing first so that we don't double up for empty */ op_done |= nlaedit_add_tracks_existing(&ac, above_sel); @@ -759,8 +780,9 @@ static int nlaedit_delete_tracks_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the AnimData blocks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_SEL | @@ -776,8 +798,9 @@ static int nlaedit_delete_tracks_exec(bContext *C, wmOperator *UNUSED(op)) /* if track is currently 'solo', then AnimData should have its * 'has solo' flag disabled */ - if (nlt->flag & NLATRACK_SOLO) + if (nlt->flag & NLATRACK_SOLO) { adt->flag &= ~ADT_NLA_SOLO_TRACK; + } /* call delete on this track - deletes all strips too */ BKE_nlatrack_free(&adt->nla_tracks, nlt, true); @@ -830,8 +853,9 @@ static int nlaedit_objects_add_exec(bContext *C, wmOperator *UNUSED(op)) SpaceNla *snla; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* ensure that filters are set so that the effect will be immediately visible */ snla = (SpaceNla *)ac.sl; diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c index 65115819874..1df2190b7af 100644 --- a/source/blender/editors/space_nla/nla_draw.c +++ b/source/blender/editors/space_nla/nla_draw.c @@ -86,8 +86,9 @@ void nla_action_get_color(AnimData *adt, bAction *act, float color[4]) /* when an NLA track is tagged "solo", action doesn't contribute, * so shouldn't be as prominent */ - if (adt && (adt->flag & ADT_NLA_SOLO_TRACK)) + if (adt && (adt->flag & ADT_NLA_SOLO_TRACK)) { color[3] *= 0.15f; + } } /* draw the keyframes in the specified Action */ @@ -99,8 +100,9 @@ static void nla_action_draw_keyframes( BLI_dlrbTree_init(&keys); action_to_keylist(adt, act, &keys, 0); - if (ELEM(NULL, act, keys.first)) + if (ELEM(NULL, act, keys.first)) { return; + } /* draw a darkened region behind the strips * - get and reset the background color, this time without the alpha to stand out better @@ -181,8 +183,9 @@ static void nla_actionclip_draw_markers( { const bAction *act = strip->act; - if (ELEM(NULL, act, act->markers.first)) + if (ELEM(NULL, act, act->markers.first)) { return; + } const uint shdr_pos = GPU_vertformat_attr_add( immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); @@ -351,16 +354,18 @@ static void nla_draw_strip_curves(NlaStrip *strip, float yminc, float ymaxc, uns immVertex2f(pos, strip->start, yminc); immVertex2f(pos, strip->start + strip->blendin, ymaxc); } - else + else { immVertex2f(pos, strip->start, ymaxc); + } /* end of strip */ if (IS_EQF(strip->blendout, 0.0f) == 0) { immVertex2f(pos, strip->end - strip->blendout, ymaxc); immVertex2f(pos, strip->end, yminc); } - else + else { immVertex2f(pos, strip->end, ymaxc); + } immEnd(); } @@ -489,15 +494,17 @@ static void nla_draw_strip(SpaceNla *snla, /* draw strip's control 'curves' * - only if user hasn't hidden them... */ - if ((snla->flag & SNLA_NOSTRIPCURVES) == 0) + if ((snla->flag & SNLA_NOSTRIPCURVES) == 0) { nla_draw_strip_curves(strip, yminc, ymaxc, shdr_pos); + } immUnbindProgram(); /* draw markings indicating locations of local markers * (useful for lining up different actions) */ - if ((snla->flag & SNLA_NOLOCALMARKERS) == 0) + if ((snla->flag & SNLA_NOLOCALMARKERS) == 0) { nla_strip_draw_markers(strip, yminc, ymaxc); + } /* draw strip outline * - color used here is to indicate active vs non-active @@ -615,10 +622,12 @@ static void nla_draw_strip_text(AnimData *adt, } /* text opacity depends on whether if there's a solo'd track, this isn't it */ - if (non_solo == 0) + if (non_solo == 0) { col[3] = 255; - else + } + else { col[3] = 128; + } /* set bounding-box for text * - padding of 2 'units' on either side @@ -722,8 +731,9 @@ void draw_nla_main_data(bAnimContext *ac, SpaceNla *snla, ARegion *ar) /* if transforming strips (only real reason for temp-metas currently), * add to the cache the frame numbers of the strip's extents */ - if (strip->flag & NLASTRIP_FLAG_TEMP_META) + if (strip->flag & NLASTRIP_FLAG_TEMP_META) { nla_draw_strip_frames_text(nlt, strip, v2d, yminc, ymaxc); + } } } break; diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index 79c2242cd01..0446235a776 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -113,8 +113,9 @@ static int nlaedit_enable_tweakmode_exec(bContext *C, wmOperator *op) bool ok = false; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the AnimData blocks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ANIMDATA); @@ -257,17 +258,20 @@ static int nlaedit_disable_tweakmode_exec(bContext *C, wmOperator *op) bool ok = false; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* perform operation */ ok = nlaedit_disable_tweakmode(&ac, do_solo); /* success? */ - if (ok) + if (ok) { return OPERATOR_FINISHED; - else + } + else { return OPERATOR_CANCELLED; + } } void NLA_OT_tweakmode_exit(wmOperatorType *ot) @@ -362,13 +366,16 @@ static int nlaedit_previewrange_exec(bContext *C, wmOperator *UNUSED(op)) float min, max; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } - if (ac.scene == NULL) + if (ac.scene == NULL) { return OPERATOR_CANCELLED; - else + } + else { scene = ac.scene; + } /* set the range directly */ get_nlastrip_extents(&ac, &min, &max, true); @@ -464,8 +471,9 @@ static int nlaedit_viewall(bContext *C, const bool only_sel) float extra; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } v2d = &ac.ar->v2d; /* set the horizontal range, with an extra offset so that the extreme keys will be in view */ @@ -597,8 +605,9 @@ static int nlaedit_add_actionclip_exec(bContext *C, wmOperator *op) float cfra; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } scene = ac.scene; cfra = (float)CFRA; @@ -608,7 +617,7 @@ static int nlaedit_add_actionclip_exec(bContext *C, wmOperator *op) if (act == NULL) { BKE_report(op->reports, RPT_ERROR, "No valid action to add"); - //printf("Add strip - actname = '%s'\n", actname); + // printf("Add strip - actname = '%s'\n", actname); return OPERATOR_CANCELLED; } else if (act->idroot == 0) { @@ -648,8 +657,9 @@ static int nlaedit_add_actionclip_exec(bContext *C, wmOperator *op) AnimData *adt = ale->adt; NlaStrip *strip = NULL; - /* sanity check: only apply actions of the right type for this ID - * NOTE: in the case that this hasn't been set, we've already warned the user about this already + /* Sanity check: only apply actions of the right type for this ID. + * NOTE: in the case that this hasn't been set, + * we've already warned the user about this already */ if ((act->idroot) && (act->idroot != GS(ale->id->name))) { BKE_reportf( @@ -735,8 +745,9 @@ static int nlaedit_add_transition_exec(bContext *C, wmOperator *op) bool done = false; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -749,8 +760,9 @@ static int nlaedit_add_transition_exec(bContext *C, wmOperator *op) NlaStrip *s1, *s2; /* get initial pair of strips */ - if (ELEM(nlt->strips.first, NULL, nlt->strips.last)) + if (ELEM(nlt->strips.first, NULL, nlt->strips.last)) { continue; + } s1 = nlt->strips.first; s2 = s1->next; @@ -759,20 +771,24 @@ static int nlaedit_add_transition_exec(bContext *C, wmOperator *op) NlaStrip *strip; /* check if both are selected */ - if (ELEM(0, (s1->flag & NLASTRIP_FLAG_SELECT), (s2->flag & NLASTRIP_FLAG_SELECT))) + if (ELEM(0, (s1->flag & NLASTRIP_FLAG_SELECT), (s2->flag & NLASTRIP_FLAG_SELECT))) { continue; + } /* check if there's space between the two */ - if (IS_EQF(s1->end, s2->start)) + if (IS_EQF(s1->end, s2->start)) { continue; + } /* make sure neither one is a transition * - although this is impossible to create with the standard tools, * the user may have altered the settings */ - if (ELEM(NLASTRIP_TYPE_TRANSITION, s1->type, s2->type)) + if (ELEM(NLASTRIP_TYPE_TRANSITION, s1->type, s2->type)) { continue; + } /* also make sure neither one is a soundclip */ - if (ELEM(NLASTRIP_TYPE_SOUND, s1->type, s2->type)) + if (ELEM(NLASTRIP_TYPE_SOUND, s1->type, s2->type)) { continue; + } /* allocate new strip */ strip = MEM_callocN(sizeof(NlaStrip), "NlaStrip"); @@ -856,8 +872,9 @@ static int nlaedit_add_sound_exec(bContext *C, wmOperator *UNUSED(op)) int cfra; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } scene = ac.scene; cfra = CFRA; @@ -877,8 +894,9 @@ static int nlaedit_add_sound_exec(bContext *C, wmOperator *UNUSED(op)) NlaStrip *strip; /* does this belong to speaker - assumed to live on Object level only */ - if ((GS(ale->id->name) != ID_OB) || (ob->type != OB_SPEAKER)) + if ((GS(ale->id->name) != ID_OB) || (ob->type != OB_SPEAKER)) { continue; + } /* create a new strip, and offset it to start on the current frame */ strip = BKE_nla_add_soundstrip(ac.scene, ob->data); @@ -940,8 +958,9 @@ static int nlaedit_add_meta_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -959,8 +978,9 @@ static int nlaedit_add_meta_exec(bContext *C, wmOperator *UNUSED(op)) /* name the metas */ for (strip = nlt->strips.first; strip; strip = strip->next) { /* auto-name this strip if selected (that means it is a meta) */ - if (strip->flag & NLASTRIP_FLAG_SELECT) + if (strip->flag & NLASTRIP_FLAG_SELECT) { BKE_nlastrip_validate_name(adt, strip); + } } ale->update |= ANIM_UPDATE_DEPS; @@ -1004,8 +1024,9 @@ static int nlaedit_remove_meta_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -1064,8 +1085,9 @@ static int nlaedit_duplicate_exec(bContext *C, wmOperator *op) bool done = false; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -1127,8 +1149,9 @@ static int nlaedit_duplicate_exec(bContext *C, wmOperator *op) /* done */ return OPERATOR_FINISHED; } - else + else { return OPERATOR_CANCELLED; + } } static int nlaedit_duplicate_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) @@ -1180,8 +1203,9 @@ static int nlaedit_delete_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -1198,8 +1222,9 @@ static int nlaedit_delete_exec(bContext *C, wmOperator *UNUSED(op)) /* if selected, delete */ if (strip->flag & NLASTRIP_FLAG_SELECT) { /* if a strip either side of this was a transition, delete those too */ - if ((strip->prev) && (strip->prev->type == NLASTRIP_TYPE_TRANSITION)) + if ((strip->prev) && (strip->prev->type == NLASTRIP_TYPE_TRANSITION)) { BKE_nlastrip_free(&nlt->strips, strip->prev, true); + } if ((nstrip) && (nstrip->type == NLASTRIP_TYPE_TRANSITION)) { nstrip = nstrip->next; BKE_nlastrip_free(&nlt->strips, strip->next, true); @@ -1268,17 +1293,21 @@ static void nlaedit_split_strip_actclip( /* strip extents */ len = strip->end - strip->start; - if (IS_EQF(len, 0.0f)) + if (IS_EQF(len, 0.0f)) { return; - else + } + else { splitframe = strip->start + (len / 2.0f); + } /* action range */ len = strip->actend - strip->actstart; - if (IS_EQF(len, 0.0f)) + if (IS_EQF(len, 0.0f)) { splitaframe = strip->actend; - else + } + else { splitaframe = strip->actstart + (len / 2.0f); + } } /* make a copy (assume that this is possible) and append @@ -1324,8 +1353,9 @@ static int nlaedit_split_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -1402,8 +1432,9 @@ static int nlaedit_toggle_mute_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -1465,8 +1496,9 @@ static int nlaedit_swap_exec(bContext *C, wmOperator *op) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -1482,7 +1514,8 @@ static int nlaedit_swap_exec(bContext *C, wmOperator *op) /* make temporary metastrips so that entire islands of selections can be moved around */ BKE_nlastrips_make_metas(&nlt->strips, 1); - /* special case: if there is only 1 island (i.e. temp meta BUT NOT unselected/normal/normal-meta strips) left after this, + /* special case: if there is only 1 island + * (i.e. temp meta BUT NOT unselected/normal/normal-meta strips) left after this, * and this island has two strips inside it, then we should be able to just swap these still... */ if (BLI_listbase_is_empty(&nlt->strips) == false) { @@ -1633,8 +1666,9 @@ static int nlaedit_move_up_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -1649,8 +1683,9 @@ static int nlaedit_move_up_exec(bContext *C, wmOperator *UNUSED(op)) NlaStrip *strip, *stripn; /* if this track has no tracks after it, skip for now... */ - if (nltn == NULL) + if (nltn == NULL) { continue; + } /* for every selected strip, try to move */ for (strip = nlt->strips.first; strip; strip = stripn) { @@ -1708,8 +1743,9 @@ static int nlaedit_move_down_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -1724,8 +1760,9 @@ static int nlaedit_move_down_exec(bContext *C, wmOperator *UNUSED(op)) NlaStrip *strip, *stripn; /* if this track has no tracks before it, skip for now... */ - if (nltp == NULL) + if (nltp == NULL) { continue; + } /* for every selected strip, try to move */ for (strip = nlt->strips.first; strip; strip = stripn) { @@ -1784,13 +1821,15 @@ static int nlaedit_sync_actlen_exec(bContext *C, wmOperator *op) const bool active_only = RNA_boolean_get(op->ptr, "active"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); - if (active_only) + if (active_only) { filter |= ANIMFILTER_ACTIVE; + } ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* for each NLA-Track, apply scale of all selected strips */ @@ -1801,18 +1840,21 @@ static int nlaedit_sync_actlen_exec(bContext *C, wmOperator *op) for (strip = nlt->strips.first; strip; strip = strip->next) { /* strip selection/active status check */ if (active_only) { - if ((strip->flag & NLASTRIP_FLAG_ACTIVE) == 0) + if ((strip->flag & NLASTRIP_FLAG_ACTIVE) == 0) { continue; + } } else { - if ((strip->flag & NLASTRIP_FLAG_SELECT) == 0) + if ((strip->flag & NLASTRIP_FLAG_SELECT) == 0) { continue; + } } /* must be action-clip only (transitions don't have scale) */ if (strip->type == NLASTRIP_TYPE_CLIP) { - if (strip->act == NULL) + if (strip->act == NULL) { continue; + } /* recalculate the length of the action */ calc_action_range(strip->act, &strip->actstart, &strip->actend, 0); @@ -1873,8 +1915,9 @@ static int nlaedit_make_single_user_exec(bContext *C, wmOperator *UNUSED(op)) bool copied = false; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -1891,8 +1934,9 @@ static int nlaedit_make_single_user_exec(bContext *C, wmOperator *UNUSED(op)) for (strip = nlt->strips.last; strip; strip = strip->prev) { /* must be action-clip only (as only these have actions) */ if ((strip->flag & NLASTRIP_FLAG_SELECT) && (strip->type == NLASTRIP_TYPE_CLIP)) { - if (strip->act == NULL) + if (strip->act == NULL) { continue; + } /* multi-user? */ if (ID_REAL_USERS(strip->act) > 1) { @@ -1974,8 +2018,9 @@ static int nlaedit_apply_scale_exec(bContext *C, wmOperator *UNUSED(op)) KeyframeEditData ked = {{NULL}}; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -1992,8 +2037,9 @@ static int nlaedit_apply_scale_exec(bContext *C, wmOperator *UNUSED(op)) if ((strip->flag & NLASTRIP_FLAG_SELECT) && (strip->type == NLASTRIP_TYPE_CLIP)) { /* if the referenced action is used by other strips, * make this strip use its own copy */ - if (strip->act == NULL) + if (strip->act == NULL) { continue; + } if (strip->act->id.us > 1) { /* make a copy of the Action to work on */ bAction *act = BKE_action_copy(bmain, strip->act); @@ -2066,8 +2112,9 @@ static int nlaedit_clear_scale_exec(bContext *C, wmOperator *UNUSED(op)) int filter; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -2125,11 +2172,8 @@ void NLA_OT_clear_scale(wmOperatorType *ot) static const EnumPropertyItem prop_nlaedit_snap_types[] = { {NLAEDIT_SNAP_CFRA, "CFRA", 0, "Current Frame", ""}, {NLAEDIT_SNAP_NEAREST_FRAME, "NEAREST_FRAME", 0, "Nearest Frame", ""}, // XXX as single entry? - {NLAEDIT_SNAP_NEAREST_SECOND, - "NEAREST_SECOND", - 0, - "Nearest Second", - ""}, // XXX as single entry? + // XXX as single entry? + {NLAEDIT_SNAP_NEAREST_SECOND, "NEAREST_SECOND", 0, "Nearest Second", ""}, {NLAEDIT_SNAP_NEAREST_MARKER, "NEAREST_MARKER", 0, "Nearest Marker", ""}, {0, NULL, 0, NULL, NULL}, }; @@ -2147,8 +2191,9 @@ static int nlaedit_snap_exec(bContext *C, wmOperator *op) float secf; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -2296,10 +2341,12 @@ static const EnumPropertyItem *nla_fmodifier_itemf(bContext *C, int index; /* check if modifier is valid for this context */ - if (fmi == NULL) + if (fmi == NULL) { continue; - if (i == FMODIFIER_TYPE_CYCLES) /* we already have repeat... */ + } + if (i == FMODIFIER_TYPE_CYCLES) { /* we already have repeat... */ continue; + } index = RNA_enum_from_value(rna_enum_fmodifier_type_items, fmi->type); if (index != -1) { /* Not all types are implemented yet... */ @@ -2326,8 +2373,9 @@ static int nla_fmodifier_add_exec(bContext *C, wmOperator *op) const bool active_only = RNA_boolean_get(op->ptr, "only_active"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT); @@ -2342,18 +2390,21 @@ static int nla_fmodifier_add_exec(bContext *C, wmOperator *op) /* can F-Modifier be added to the current strip? */ if (active_only) { /* if not active, cannot add since we're only adding to active strip */ - if ((strip->flag & NLASTRIP_FLAG_ACTIVE) == 0) + if ((strip->flag & NLASTRIP_FLAG_ACTIVE) == 0) { continue; + } } else { /* strip must be selected, since we're not just doing active */ - if ((strip->flag & NLASTRIP_FLAG_SELECT) == 0) + if ((strip->flag & NLASTRIP_FLAG_SELECT) == 0) { continue; + } } /* sound clips are not affected by FModifiers */ - if (strip->type == NLASTRIP_TYPE_SOUND) + if (strip->type == NLASTRIP_TYPE_SOUND) { continue; + } /* add F-Modifier of specified type to selected, and make it the active one */ fcm = add_fmodifier(&strip->modifiers, type, NULL); @@ -2420,8 +2471,9 @@ static int nla_fmodifier_copy_exec(bContext *C, wmOperator *op) bool ok = false; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* clear buffer first */ ANIM_fmodifiers_copybuf_free(); @@ -2437,8 +2489,9 @@ static int nla_fmodifier_copy_exec(bContext *C, wmOperator *op) for (strip = nlt->strips.first; strip; strip = strip->next) { /* only add F-Modifier if on active strip? */ - if ((strip->flag & NLASTRIP_FLAG_ACTIVE) == 0) + if ((strip->flag & NLASTRIP_FLAG_ACTIVE) == 0) { continue; + } // TODO: when 'active' vs 'all' boolean is added, change last param! ok |= ANIM_fmodifiers_copy_to_buf(&strip->modifiers, 0); @@ -2474,7 +2527,13 @@ void NLA_OT_fmodifier_copy(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* id-props */ - //ot->prop = RNA_def_boolean(ot->srna, "all", 1, "All F-Modifiers", "Copy all the F-Modifiers, instead of just the active one"); +#if 0 + ot->prop = RNA_def_boolean(ot->srna, + "all", + 1, + "All F-Modifiers", + "Copy all the F-Modifiers, instead of just the active one"); +#endif } /* ******************** Paste F-Modifiers Operator *********************** */ @@ -2490,8 +2549,9 @@ static int nla_fmodifier_paste_exec(bContext *C, wmOperator *op) const bool replace = RNA_boolean_get(op->ptr, "replace"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* get a list of the editable tracks being shown in the NLA */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT | @@ -2507,13 +2567,15 @@ static int nla_fmodifier_paste_exec(bContext *C, wmOperator *op) /* can F-Modifier be added to the current strip? */ if (active_only) { /* if not active, cannot add since we're only adding to active strip */ - if ((strip->flag & NLASTRIP_FLAG_ACTIVE) == 0) + if ((strip->flag & NLASTRIP_FLAG_ACTIVE) == 0) { continue; + } } else { /* strip must be selected, since we're not just doing active */ - if ((strip->flag & NLASTRIP_FLAG_SELECT) == 0) + if ((strip->flag & NLASTRIP_FLAG_SELECT) == 0) { continue; + } } /* paste FModifiers from buffer */ diff --git a/source/blender/editors/space_nla/nla_intern.h b/source/blender/editors/space_nla/nla_intern.h index 291dfe17343..2b20ab69fa7 100644 --- a/source/blender/editors/space_nla/nla_intern.h +++ b/source/blender/editors/space_nla/nla_intern.h @@ -32,15 +32,12 @@ /* **************************************** */ /* space_nla.c / nla_buttons.c */ -ARegion *nla_has_buttons_region(ScrArea *sa); - bool nla_panel_context(const bContext *C, PointerRNA *adt_ptr, PointerRNA *nlt_ptr, PointerRNA *strip_ptr); void nla_buttons_register(ARegionType *art); -void NLA_OT_properties(wmOperatorType *ot); /* **************************************** */ /* nla_draw.c */ diff --git a/source/blender/editors/space_nla/nla_ops.c b/source/blender/editors/space_nla/nla_ops.c index 51d6232cf71..55470388e22 100644 --- a/source/blender/editors/space_nla/nla_ops.c +++ b/source/blender/editors/space_nla/nla_ops.c @@ -56,12 +56,14 @@ bool nlaop_poll_tweakmode_off(bContext *C) * but not all AnimData blocks will be in tweakmode for * various reasons */ - if (ED_operator_nla_active(C) == 0) + if (ED_operator_nla_active(C) == 0) { return 0; + } scene = CTX_data_scene(C); - if ((scene == NULL) || (scene->flag & SCE_NLA_EDIT_ON)) + if ((scene == NULL) || (scene->flag & SCE_NLA_EDIT_ON)) { return 0; + } return 1; } @@ -78,12 +80,14 @@ bool nlaop_poll_tweakmode_on(bContext *C) * but not all AnimData blocks will be in tweakmode for * various reasons */ - if (ED_operator_nla_active(C) == 0) + if (ED_operator_nla_active(C) == 0) { return 0; + } scene = CTX_data_scene(C); - if ((scene == NULL) || !(scene->flag & SCE_NLA_EDIT_ON)) + if ((scene == NULL) || !(scene->flag & SCE_NLA_EDIT_ON)) { return 0; + } return 1; } @@ -91,8 +95,9 @@ bool nlaop_poll_tweakmode_on(bContext *C) /* is tweakmode enabled - for use in NLA operator code */ bool nlaedit_is_tweakmode_on(bAnimContext *ac) { - if (ac && ac->scene) + if (ac && ac->scene) { return (ac->scene->flag & SCE_NLA_EDIT_ON) != 0; + } return 0; } @@ -100,9 +105,6 @@ bool nlaedit_is_tweakmode_on(bAnimContext *ac) void nla_operatortypes(void) { - /* view */ - WM_operatortype_append(NLA_OT_properties); - /* channels */ WM_operatortype_append(NLA_OT_channels_click); @@ -170,9 +172,10 @@ void nla_keymap(wmKeyConfig *keyconf) WM_keymap_ensure(keyconf, "NLA Generic", SPACE_NLA, 0); /* channels ---------------------------------------------------------- */ - /* Channels are not directly handled by the NLA Editor module, but are inherited from the Animation module. - * Most of the relevant operations, keymaps, drawing, etc. can therefore all - * be found in that module instead, as there are many similarities with the other Animation Editors. + /* Channels are not directly handled by the NLA Editor module, but are inherited from the + * animation module. Most of the relevant operations, keymaps, drawing, etc. can therefore all + * be found in that module instead, as there are many similarities with the other + * animation editors. * * However, those operations which involve clicking on channels and/or * the placement of them in the view are implemented here instead diff --git a/source/blender/editors/space_nla/nla_select.c b/source/blender/editors/space_nla/nla_select.c index 0df0c5a99da..5c9e48f3d5d 100644 --- a/source/blender/editors/space_nla/nla_select.c +++ b/source/blender/editors/space_nla/nla_select.c @@ -119,8 +119,9 @@ static void deselect_nla_strips(bAnimContext *ac, short test, short sel) } } - if (sel == SELECT_SUBTRACT) + if (sel == SELECT_SUBTRACT) { break; + } } } @@ -135,11 +136,13 @@ static void deselect_nla_strips(bAnimContext *ac, short test, short sel) /* apply same selection to all strips */ for (strip = nlt->strips.first; strip; strip = strip->next) { /* set selection */ - if (test != DESELECT_STRIPS_CLEARACTIVE) + if (test != DESELECT_STRIPS_CLEARACTIVE) { ACHANNEL_SET_FLAG(strip, smode, NLASTRIP_FLAG_SELECT); + } /* clear active flag */ - // TODO: for clear active, do we want to limit this to only doing this on a certain set of tracks though? + /* TODO: for clear active, + * do we want to limit this to only doing this on a certain set of tracks though? */ strip->flag &= ~NLASTRIP_FLAG_ACTIVE; } } @@ -155,8 +158,9 @@ static int nlaedit_deselectall_exec(bContext *C, wmOperator *op) bAnimContext ac; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* 'standard' behavior - check if selected, then apply relevant selection */ const int action = RNA_enum_get(op->ptr, "action"); @@ -203,11 +207,13 @@ void NLA_OT_select_all(wmOperatorType *ot) } /* ******************** Box Select Operator **************************** */ -/* This operator currently works in one of three ways: - * -> BKEY - 1) all strips within region are selected (NLAEDIT_BORDERSEL_ALLSTRIPS) - * -> ALT-BKEY - depending on which axis of the region was larger... - * -> 2) x-axis, so select all frames within frame range (NLAEDIT_BORDERSEL_FRAMERANGE) - * -> 3) y-axis, so select all frames within channels that region included (NLAEDIT_BORDERSEL_CHANNELS) +/** + * This operator currently works in one of three ways: + * - BKEY - 1: all strips within region are selected #NLAEDIT_BOX_ALLSTRIPS. + * - ALT-BKEY - depending on which axis of the region was larger. + * - 2: x-axis, so select all frames within frame range #NLAEDIT_BOXSEL_FRAMERANGE. + * - 3: y-axis, so select all frames within channels that region included + * #NLAEDIT_BOXSEL_CHANNELS. */ /* defines for box_select mode */ @@ -281,8 +287,9 @@ static int nlaedit_box_select_exec(bContext *C, wmOperator *op) short mode = 0; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); const int selectmode = (sel_op != SEL_OP_SUB) ? SELECT_ADD : SELECT_SUBTRACT; @@ -295,18 +302,23 @@ static int nlaedit_box_select_exec(bContext *C, wmOperator *op) /* selection 'mode' depends on whether box_select region only matters on one axis */ if (RNA_boolean_get(op->ptr, "axis_range")) { - /* mode depends on which axis of the range is larger to determine which axis to use - * - checking this in region-space is fine, as it's fundamentally still going to be a different rect size - * - the frame-range select option is favored over the channel one (x over y), as frame-range one is often - * used for tweaking timing when "blocking", while channels is not that useful... + /* mode depends on which axis of the range is larger to determine which axis to use. + * - Checking this in region-space is fine, + * as it's fundamentally still going to be a different rect size. + * - The frame-range select option is favored over the channel one (x over y), + * as frame-range one is often. + * Used for tweaking timing when "blocking", while channels is not that useful. */ - if (BLI_rcti_size_x(&rect) >= BLI_rcti_size_y(&rect)) + if (BLI_rcti_size_x(&rect) >= BLI_rcti_size_y(&rect)) { mode = NLA_BOXSEL_FRAMERANGE; - else + } + else { mode = NLA_BOXSEL_CHANNELS; + } } - else + else { mode = NLA_BOXSEL_ALLSTRIPS; + } /* apply box_select action */ box_select_nla_strips(&ac, rect, mode, selectmode); @@ -368,8 +380,9 @@ static void nlaedit_select_leftright(bContext *C, float xmin, xmax; /* if currently in tweakmode, exit tweakmode first */ - if (scene->flag & SCE_NLA_EDIT_ON) + if (scene->flag & SCE_NLA_EDIT_ON) { WM_operator_name_call(C, "NLA_OT_tweakmode_exit", WM_OP_EXEC_DEFAULT, NULL); + } /* if select mode is replace, deselect all keyframes (and channels) first */ if (select_mode == SELECT_REPLACE) { @@ -423,18 +436,22 @@ static int nlaedit_select_leftright_exec(bContext *C, wmOperator *op) short selectmode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* select mode is either replace (deselect all, then add) or add/extend */ - if (RNA_boolean_get(op->ptr, "extend")) + if (RNA_boolean_get(op->ptr, "extend")) { selectmode = SELECT_INVERT; - else + } + else { selectmode = SELECT_REPLACE; + } /* if "test" mode is set, we don't have any info to set this with */ - if (leftright == NLAEDIT_LRSEL_TEST) + if (leftright == NLAEDIT_LRSEL_TEST) { return OPERATOR_CANCELLED; + } /* do the selecting now */ nlaedit_select_leftright(C, &ac, leftright, selectmode); @@ -452,8 +469,9 @@ static int nlaedit_select_leftright_invoke(bContext *C, wmOperator *op, const wm short leftright = RNA_enum_get(op->ptr, "mode"); /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; + } /* handle mode-based testing */ if (leftright == NLAEDIT_LRSEL_TEST) { @@ -464,10 +482,12 @@ static int nlaedit_select_leftright_invoke(bContext *C, wmOperator *op, const wm /* determine which side of the current frame mouse is on */ x = UI_view2d_region_to_view_x(v2d, event->mval[0]); - if (x < CFRA) + if (x < CFRA) { RNA_enum_set(op->ptr, "mode", NLAEDIT_LRSEL_LEFT); - else + } + else { RNA_enum_set(op->ptr, "mode", NLAEDIT_LRSEL_RIGHT); + } } /* perform selection */ @@ -503,7 +523,8 @@ void NLA_OT_select_leftright(wmOperatorType *ot) /* ******************** Mouse-Click Select Operator *********************** */ /* select strip directly under mouse */ -static void mouse_nla_strips(bContext *C, bAnimContext *ac, const int mval[2], short select_mode) +static void mouse_nla_strips( + bContext *C, bAnimContext *ac, const int mval[2], short select_mode, const bool deselect_all) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale = NULL; @@ -542,14 +563,7 @@ static void mouse_nla_strips(bContext *C, bAnimContext *ac, const int mval[2], s /* try to get channel */ ale = BLI_findlink(&anim_data, channel_index); - if (ale == NULL) { - /* channel not found */ - printf("Error: animation channel (index = %d) not found in mouse_nla_strips()\n", - channel_index); - ANIM_animdata_freelist(&anim_data); - return; - } - else { + if (ale != NULL) { /* found some channel - we only really should do something when its an Nla-Track */ if (ale->type == ANIMTYPE_NLATRACK) { NlaTrack *nlt = (NlaTrack *)ale->data; @@ -557,27 +571,31 @@ static void mouse_nla_strips(bContext *C, bAnimContext *ac, const int mval[2], s /* loop over NLA-strips in this track, * trying to find one which occurs in the necessary bounds */ for (strip = nlt->strips.first; strip; strip = strip->next) { - if (BKE_nlastrip_within_bounds(strip, xmin, xmax)) + if (BKE_nlastrip_within_bounds(strip, xmin, xmax)) { break; + } } } /* remove active channel from list of channels for separate treatment * (since it's needed later on) */ BLI_remlink(&anim_data, ale); - - /* free list of channels, since it's not used anymore */ - ANIM_animdata_freelist(&anim_data); } + /* free list of channels, since it's not used anymore */ + ANIM_animdata_freelist(&anim_data); + /* if currently in tweakmode, exit tweakmode before changing selection states * now that we've found our target... */ - if (scene->flag & SCE_NLA_EDIT_ON) + if (scene->flag & SCE_NLA_EDIT_ON) { WM_operator_name_call(C, "NLA_OT_tweakmode_exit", WM_OP_EXEC_DEFAULT, NULL); + } - /* for replacing selection, firstly need to clear existing selection */ - if (select_mode == SELECT_REPLACE) { + /* For replacing selection, if we have something to select, we have to clear existing selection. + * The same goes if we found nothing to select, and deselect_all is true + * (deselect on nothing behavior). */ + if ((strip != NULL && select_mode == SELECT_REPLACE) || (strip == NULL && deselect_all)) { /* reset selection mode for next steps */ select_mode = SELECT_ADD; @@ -589,9 +607,9 @@ static void mouse_nla_strips(bContext *C, bAnimContext *ac, const int mval[2], s } /* only select strip if we clicked on a valid channel and hit something */ - if (ale) { + if (ale != NULL) { /* select the strip accordingly (if a matching one was found) */ - if (strip) { + if (strip != NULL) { select_mode = selmodes_to_flagmodes(select_mode); ACHANNEL_SET_FLAG(strip, select_mode, NLASTRIP_FLAG_SELECT); @@ -625,28 +643,18 @@ static void mouse_nla_strips(bContext *C, bAnimContext *ac, const int mval[2], s static int nlaedit_clickselect_invoke(bContext *C, wmOperator *op, const wmEvent *event) { bAnimContext ac; - /* Scene *scene; */ /* UNUSED */ - /* ARegion *ar; */ /* UNUSED */ - // View2D *v2d; /*UNUSED*/ - short selectmode; /* get editor data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return OPERATOR_CANCELLED; - - /* get useful pointers from animation context data */ - /* scene= ac.scene; */ /* UNUSED */ - /* ar= ac.ar; */ /* UNUSED */ - // v2d= &ar->v2d; + } /* select mode is either replace (deselect all, then add) or add/extend */ - if (RNA_boolean_get(op->ptr, "extend")) - selectmode = SELECT_INVERT; - else - selectmode = SELECT_REPLACE; + const short selectmode = RNA_boolean_get(op->ptr, "extend") ? SELECT_INVERT : SELECT_REPLACE; + const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all"); /* select strips based upon mouse position */ - mouse_nla_strips(C, &ac, event->mval, selectmode); + mouse_nla_strips(C, &ac, event->mval, selectmode, deselect_all); /* set notifier that things have changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_SELECTED, NULL); @@ -674,6 +682,13 @@ void NLA_OT_click_select(wmOperatorType *ot) /* properties */ prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_boolean(ot->srna, + "deselect_all", + false, + "Deselect On Nothing", + "Deselect all when nothing under the cursor"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /* *********************************************** */ diff --git a/source/blender/editors/space_nla/space_nla.c b/source/blender/editors/space_nla/space_nla.c index ccf2e552644..b054f550c6c 100644 --- a/source/blender/editors/space_nla/space_nla.c +++ b/source/blender/editors/space_nla/space_nla.c @@ -53,34 +53,6 @@ #include "nla_intern.h" /* own include */ #include "GPU_framebuffer.h" -/* ******************** manage regions ********************* */ - -ARegion *nla_has_buttons_region(ScrArea *sa) -{ - ARegion *ar, *arnew; - - ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); - if (ar) - return ar; - - /* add subdiv level; after main */ - ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); - - /* is error! */ - if (ar == NULL) - return NULL; - - arnew = MEM_callocN(sizeof(ARegion), "buttons for nla"); - - BLI_insertlinkafter(&sa->regionbase, ar, arnew); - arnew->regiontype = RGN_TYPE_UI; - arnew->alignment = RGN_ALIGN_RIGHT; - - arnew->flag = RGN_FLAG_HIDDEN; - - return arnew; -} - /* ******************** default callbacks for nla space ***************** */ static SpaceLink *nla_new(const ScrArea *sa, const Scene *scene) @@ -202,13 +174,13 @@ static void nla_channel_region_init(wmWindowManager *wm, ARegion *ar) /* own keymap */ /* own channels map first to override some channel keymaps */ keymap = WM_keymap_ensure(wm->defaultconf, "NLA Channels", SPACE_NLA, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); /* now generic channels map for everything else that can apply */ keymap = WM_keymap_ensure(wm->defaultconf, "Animation Channels", 0, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "NLA Generic", SPACE_NLA, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } /* draw entirely, view changes should be handled here */ @@ -233,9 +205,8 @@ static void nla_channel_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); /* scrollers */ - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY); - UI_view2d_scrollers_draw(C, v2d, scrollers); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); } @@ -248,7 +219,7 @@ static void nla_main_region_init(wmWindowManager *wm, ARegion *ar) /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "NLA Editor", SPACE_NLA, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "NLA Generic", SPACE_NLA, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); } @@ -260,9 +231,8 @@ static void nla_main_region_draw(const bContext *C, ARegion *ar) Scene *scene = CTX_data_scene(C); bAnimContext ac; View2D *v2d = &ar->v2d; - View2DGrid *grid; View2DScrollers *scrollers; - short unit = 0, cfra_flag = 0; + short cfra_flag = 0; /* clear and setup matrix */ UI_ThemeClearColor(TH_BACK); @@ -271,17 +241,7 @@ static void nla_main_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_ortho(v2d); /* time grid */ - unit = (snla->flag & SNLA_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES; - grid = UI_view2d_grid_calc(CTX_data_scene(C), - v2d, - unit, - V2D_GRID_CLAMP, - V2D_ARG_DUMMY, - V2D_ARG_DUMMY, - ar->winx, - ar->winy); - UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL); - UI_view2d_grid_free(grid); + UI_view2d_draw_lines_x__discrete_frames_or_seconds(v2d, scene, snla->flag & SNLA_DRAWTIME); ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); @@ -300,15 +260,17 @@ static void nla_main_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_ortho(v2d); /* current frame */ - if (snla->flag & SNLA_DRAWTIME) + if (snla->flag & SNLA_DRAWTIME) { cfra_flag |= DRAWCFRA_UNIT_SECONDS; + } ANIM_draw_cfra(C, v2d, cfra_flag); /* markers */ UI_view2d_view_orthoSpecial(ar, v2d, 1); int marker_draw_flag = DRAW_MARKERS_MARGIN; - if (snla->flag & SNLA_SHOW_MARKER_LINES) + if (snla->flag & SNLA_SHOW_MARKER_LINES) { marker_draw_flag |= DRAW_MARKERS_LINES; + } ED_markers_draw(C, marker_draw_flag); /* preview range */ @@ -323,11 +285,14 @@ static void nla_main_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); /* scrollers */ - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY); - UI_view2d_scrollers_draw(C, v2d, scrollers); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); + /* frame numbers */ + UI_view2d_draw_scale_x__discrete_frames_or_seconds( + ar, v2d, &v2d->hor, scene, snla->flag & SNLA_DRAWTIME); + /* draw current frame number-indicator on top of scrollers */ if ((snla->flag & SNLA_NODRAWCFRANUM) == 0) { UI_view2d_view_orthoSpecial(ar, v2d, 1); @@ -354,7 +319,7 @@ static void nla_buttons_region_init(wmWindowManager *wm, ARegion *ar) ED_region_panels_init(wm, ar); keymap = WM_keymap_ensure(wm->defaultconf, "NLA Generic", SPACE_NLA, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } static void nla_buttons_region_draw(const bContext *C, ARegion *ar) @@ -392,8 +357,9 @@ static void nla_region_listener(wmWindow *UNUSED(win), } break; default: - if (wmn->data == ND_KEYS) + if (wmn->data == ND_KEYS) { ED_region_tag_redraw(ar); + } break; } } @@ -438,8 +404,9 @@ static void nla_main_region_listener(wmWindow *UNUSED(win), } break; case NC_ID: - if (wmn->action == NA_RENAME) + if (wmn->action == NA_RENAME) { ED_region_tag_redraw(ar); + } break; case NC_SCREEN: if (ELEM(wmn->data, ND_LAYER)) { @@ -447,8 +414,9 @@ static void nla_main_region_listener(wmWindow *UNUSED(win), } break; default: - if (wmn->data == ND_KEYS) + if (wmn->data == ND_KEYS) { ED_region_tag_redraw(ar); + } break; } } @@ -523,12 +491,14 @@ static void nla_channel_region_listener(wmWindow *UNUSED(win), } break; case NC_ID: - if (wmn->action == NA_RENAME) + if (wmn->action == NA_RENAME) { ED_region_tag_redraw(ar); + } break; default: - if (wmn->data == ND_KEYS) + if (wmn->data == ND_KEYS) { ED_region_tag_redraw(ar); + } break; } } @@ -598,8 +568,9 @@ static void nla_listener(wmWindow *UNUSED(win), ScrArea *sa, wmNotifier *wmn, Sc } break; case NC_SPACE: - if (wmn->data == ND_SPACE_NLA) + if (wmn->data == ND_SPACE_NLA) { ED_area_tag_redraw(sa); + } break; } } diff --git a/source/blender/editors/space_node/CMakeLists.txt b/source/blender/editors/space_node/CMakeLists.txt index df1b7c03aab..03c83305618 100644 --- a/source/blender/editors/space_node/CMakeLists.txt +++ b/source/blender/editors/space_node/CMakeLists.txt @@ -22,16 +22,16 @@ set(INC ../../blenlib ../../blentranslation ../../depsgraph - ../../imbuf ../../gpu + ../../imbuf ../../makesdna ../../makesrna ../../nodes ../../render/extern/include - ../../windowmanager ../../compositor - ../../../../intern/guardedalloc + ../../windowmanager ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 7072f34ee4d..447fea8098c 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -55,6 +55,7 @@ #include "RNA_define.h" #include "ED_node.h" +#include "ED_space_api.h" #include "WM_api.h" #include "WM_types.h" @@ -204,7 +205,8 @@ static void node_browse_tex_cb(bContext *C, void *ntree_v, void *node_v) bNode *node = node_v; Tex *tex; - if (node->menunr < 1) return; + if (node->menunr < 1) + return; if (node->id) { id_us_min(node->id); @@ -3413,6 +3415,14 @@ void draw_nodespace_back_pix(const bContext *C, void *lock; ImBuf *ibuf; + GPU_matrix_push_projection(); + GPU_matrix_push(); + wmOrtho2_region_pixelspace(ar); + GPU_matrix_identity_set(); + ED_region_draw_cb_draw(C, ar, REGION_DRAW_BACKDROP); + GPU_matrix_pop_projection(); + GPU_matrix_pop(); + if (!(snode->flag & SNODE_BACKDRAW) || !ED_node_is_compositor(snode)) { return; } @@ -3480,12 +3490,12 @@ void draw_nodespace_back_pix(const bContext *C, GPU_blend_set_func_separate( GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); - glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST, snode->zoom, snode->zoom); + ED_draw_imbuf_ctx(C, ibuf, x, y, GL_NEAREST, snode->zoom, snode->zoom); GPU_blend(false); } else { - glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST, snode->zoom, snode->zoom); + ED_draw_imbuf_ctx(C, ibuf, x, y, GL_NEAREST, snode->zoom, snode->zoom); } if (cache_handle) { diff --git a/source/blender/editors/space_node/node_add.c b/source/blender/editors/space_node/node_add.c index 8d754087855..714ed707e18 100644 --- a/source/blender/editors/space_node/node_add.c +++ b/source/blender/editors/space_node/node_add.c @@ -54,8 +54,10 @@ #include "node_intern.h" /* own include */ -/* XXX Does some additional initialization on top of nodeAddNode - * Can be used with both custom and static nodes, if idname==NULL the static int type will be used instead. +/** + * XXX Does some additional initialization on top of #nodeAddNode + * Can be used with both custom and static nodes, + * if `idname == NULL` the static int type will be used instead. */ bNode *node_add_node(const bContext *C, const char *idname, int type, float locx, float locy) { diff --git a/source/blender/editors/space_node/node_buttons.c b/source/blender/editors/space_node/node_buttons.c index 63e97ecd955..072a67dee6c 100644 --- a/source/blender/editors/space_node/node_buttons.c +++ b/source/blender/editors/space_node/node_buttons.c @@ -226,35 +226,3 @@ void node_buttons_register(ARegionType *art) pt->poll = node_tree_interface_poll; BLI_addtail(&art->paneltypes, pt); } - -static int node_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = node_has_buttons_region(sa); - - if (ar) { - ED_region_toggle_hidden(C, ar); - } - - return OPERATOR_FINISHED; -} - -/* non-standard poll operator which doesn't care if there are any nodes */ -static bool node_properties_poll(bContext *C) -{ - ScrArea *sa = CTX_wm_area(C); - return (sa && (sa->spacetype == SPACE_NODE)); -} - -void NODE_OT_properties(wmOperatorType *ot) -{ - ot->name = "Toggle Sidebar"; - ot->description = "Toggle the properties region visibility"; - ot->idname = "NODE_OT_properties"; - - ot->exec = node_properties_toggle_exec; - ot->poll = node_properties_poll; - - /* flags */ - ot->flag = 0; -} diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index a694ac2c38b..020bdbf60a1 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -1309,7 +1309,7 @@ static void node_draw_hidden(const bContext *C, nodeLabel(ntree, node, showname, sizeof(showname)); /* XXX - don't print into self! */ - //if (node->flag & NODE_MUTED) + // if (node->flag & NODE_MUTED) // BLI_snprintf(showname, sizeof(showname), "[%s]", showname); uiBut *but = uiDefBut(node->block, @@ -1728,8 +1728,7 @@ void drawnodespace(const bContext *C, ARegion *ar) draw_tree_path(snode); /* scrollers */ - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, 10, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY); - UI_view2d_scrollers_draw(C, v2d, scrollers); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); } diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 84f512957c7..3e73cc52c52 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -752,8 +752,8 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node) #if 0 if (node->id) ; // XXX BIF_preview_changed(-1); - // allqueue(REDRAWBUTSSHADING, 1); - // allqueue(REDRAWIPO, 0); + // allqueue(REDRAWBUTSSHADING, 1); + // allqueue(REDRAWIPO, 0); #endif } } @@ -804,7 +804,8 @@ static int edit_node_invoke_properties(bContext *C, wmOperator *op) return 1; } -static void edit_node_properties_get(wmOperator *op, bNodeTree *ntree, bNode **rnode, bNodeSocket **rsock, int *rin_out) +static void edit_node_properties_get( + wmOperator *op, bNodeTree *ntree, bNode **rnode, bNodeSocket **rsock, int *rin_out) { bNode *node; bNodeSocket *sock = NULL; @@ -819,8 +820,12 @@ static void edit_node_properties_get(wmOperator *op, bNodeTree *ntree, bNode **r sockindex = RNA_int_get(op->ptr, "socket"); switch (in_out) { - case SOCK_IN: sock = BLI_findlink(&node->inputs, sockindex); break; - case SOCK_OUT: sock = BLI_findlink(&node->outputs, sockindex); break; + case SOCK_IN: + sock = BLI_findlink(&node->inputs, sockindex); + break; + case SOCK_OUT: + sock = BLI_findlink(&node->outputs, sockindex); + break; } if (rnode) @@ -2027,7 +2032,8 @@ static int node_clipboard_copy_exec(bContext *C, wmOperator *UNUSED(op)) for (node = ntree->nodes.first; node; node = node->next) { if (node->flag & SELECT) { - /* No ID refcounting, this node is virtual, detached from any actual Blender data currently. */ + /* No ID refcounting, this node is virtual, + * detached from any actual Blender data currently. */ bNode *new_node = BKE_node_copy_ex(NULL, node, LIB_ID_CREATE_NO_USER_REFCOUNT); BKE_node_clipboard_add_node(new_node); } diff --git a/source/blender/editors/space_node/node_group.c b/source/blender/editors/space_node/node_group.c index 3c65c4854b8..08328681f7a 100644 --- a/source/blender/editors/space_node/node_group.c +++ b/source/blender/editors/space_node/node_group.c @@ -823,8 +823,8 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, /* update the group node and interface node sockets, * so the new interface socket can be linked. */ - node_group_verify(ntree, gnode, (ID *)ngroup); - node_group_input_verify(ngroup, input_node, (ID *)ngroup); + node_group_update(ntree, gnode); + node_group_input_update(ngroup, input_node); /* create new internal link */ input_sock = node_group_input_find_socket(input_node, iosock->identifier); @@ -857,8 +857,8 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, /* update the group node and interface node sockets, * so the new interface socket can be linked. */ - node_group_verify(ntree, gnode, (ID *)ngroup); - node_group_output_verify(ngroup, output_node, (ID *)ngroup); + node_group_update(ntree, gnode); + node_group_output_update(ngroup, output_node); /* create new internal link */ output_sock = node_group_output_find_socket(output_node, iosock->identifier); @@ -898,7 +898,7 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock); - node_group_input_verify(ngroup, input_node, (ID *)ngroup); + node_group_input_update(ngroup, input_node); /* create new internal link */ input_sock = node_group_input_find_socket(input_node, iosock->identifier); @@ -919,7 +919,7 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock); - node_group_output_verify(ngroup, output_node, (ID *)ngroup); + node_group_output_update(ngroup, output_node); /* create new internal link */ output_sock = node_group_output_find_socket(output_node, iosock->identifier); diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h index 7b4102ce324..1825396805c 100644 --- a/source/blender/editors/space_node/node_intern.h +++ b/source/blender/editors/space_node/node_intern.h @@ -54,8 +54,6 @@ typedef struct bNodeLinkDrag { } bNodeLinkDrag; /* space_node.c */ -ARegion *node_has_buttons_region(ScrArea *sa); -ARegion *node_has_tools_region(ScrArea *sa); /* transform between View2Ds in the tree path */ void snode_group_offset(struct SpaceNode *snode, float *x, float *y); @@ -95,11 +93,9 @@ void node_from_view(struct bNode *node, float x, float y, float *rx, float *ry); /* node_buttons.c */ void node_buttons_register(struct ARegionType *art); -void NODE_OT_properties(struct wmOperatorType *ot); /* node_toolbar.c */ void node_toolbar_register(struct ARegionType *art); -void NODE_OT_toolbar(struct wmOperatorType *ot); /* node_ops.c */ void node_operatortypes(void); @@ -155,7 +151,16 @@ bool node_link_bezier_points(struct View2D *v2d, struct bNodeLink *link, float coord_array[][2], int resol); -// void node_draw_link_straight(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3 ); +#if 0 +void node_draw_link_straight(View2D *v2d, + SpaceNode *snode, + bNodeLink *link, + int th_col1, + int do_shaded, + int th_col2, + int do_triple, + int th_col3); +#endif void draw_nodespace_back_pix(const struct bContext *C, struct ARegion *ar, struct SpaceNode *snode, diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c index ce6bf2820c6..0836617ab44 100644 --- a/source/blender/editors/space_node/node_ops.c +++ b/source/blender/editors/space_node/node_ops.c @@ -41,9 +41,6 @@ void node_operatortypes(void) { - WM_operatortype_append(NODE_OT_properties); - WM_operatortype_append(NODE_OT_toolbar); - WM_operatortype_append(NODE_OT_select); WM_operatortype_append(NODE_OT_select_all); WM_operatortype_append(NODE_OT_select_linked_to); diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c index 14636dad8c6..d34ba14700a 100644 --- a/source/blender/editors/space_node/node_relationships.c +++ b/source/blender/editors/space_node/node_relationships.c @@ -986,8 +986,8 @@ void NODE_OT_link_make(wmOperatorType *ot) /* callbacks */ ot->exec = node_make_link_exec; - ot->poll = - ED_operator_node_editable; // XXX we need a special poll which checks that there are selected input/output sockets + // XXX we need a special poll which checks that there are selected input/output sockets + ot->poll = ED_operator_node_editable; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c index 58531ec32b1..b52d1d3b78f 100644 --- a/source/blender/editors/space_node/node_select.c +++ b/source/blender/editors/space_node/node_select.c @@ -429,8 +429,13 @@ void node_select_single(bContext *C, bNode *node) WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); } -static int node_mouse_select( - Main *bmain, SpaceNode *snode, ARegion *ar, const int mval[2], bool extend, bool socket_select) +static int node_mouse_select(Main *bmain, + SpaceNode *snode, + ARegion *ar, + const int mval[2], + const bool extend, + const bool socket_select, + const bool deselect_all) { bNode *node, *tnode; bNodeSocket *sock = NULL; @@ -500,13 +505,15 @@ static int node_mouse_select( /* find the closest visible node */ node = node_under_mouse_select(snode->edittree, cursor[0], cursor[1]); - if (node) { + if (node != NULL || deselect_all) { for (tnode = snode->edittree->nodes.first; tnode; tnode = tnode->next) { nodeSetSelected(tnode, false); } - nodeSetSelected(node, true); - ED_node_set_active(bmain, snode->edittree, node); selected = true; + if (node != NULL) { + nodeSetSelected(node, true); + ED_node_set_active(bmain, snode->edittree, node); + } } } } @@ -526,19 +533,18 @@ static int node_select_exec(bContext *C, wmOperator *op) SpaceNode *snode = CTX_wm_space_node(C); ARegion *ar = CTX_wm_region(C); int mval[2]; - short extend; - bool socket_select; /* get settings from RNA properties for operator */ mval[0] = RNA_int_get(op->ptr, "mouse_x"); mval[1] = RNA_int_get(op->ptr, "mouse_y"); - extend = RNA_boolean_get(op->ptr, "extend"); + const bool extend = RNA_boolean_get(op->ptr, "extend"); /* always do socket_select when extending selection. */ - socket_select = extend || RNA_boolean_get(op->ptr, "socket_select"); + const bool socket_select = extend || RNA_boolean_get(op->ptr, "socket_select"); + const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all"); /* perform the select */ - if (node_mouse_select(bmain, snode, ar, mval, extend, socket_select)) { + if (node_mouse_select(bmain, snode, ar, mval, extend, socket_select, deselect_all)) { /* send notifiers */ WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); @@ -575,10 +581,17 @@ void NODE_OT_select(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ + PropertyRNA *prop; RNA_def_int(ot->srna, "mouse_x", 0, INT_MIN, INT_MAX, "Mouse X", "", INT_MIN, INT_MAX); RNA_def_int(ot->srna, "mouse_y", 0, INT_MIN, INT_MAX, "Mouse Y", "", INT_MIN, INT_MAX); RNA_def_boolean(ot->srna, "extend", false, "Extend", ""); RNA_def_boolean(ot->srna, "socket_select", false, "Socket Select", ""); + prop = RNA_def_boolean(ot->srna, + "deselect_all", + false, + "Deselect On Nothing", + "Deselect all when nothing under the cursor"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /** \} */ diff --git a/source/blender/editors/space_node/node_toolbar.c b/source/blender/editors/space_node/node_toolbar.c index bc7119fa4ab..7afd3fef4db 100644 --- a/source/blender/editors/space_node/node_toolbar.c +++ b/source/blender/editors/space_node/node_toolbar.c @@ -40,37 +40,3 @@ void node_toolbar_register(ARegionType *UNUSED(art)) { } - -/* ********** operator to open/close toolshelf region */ - -static int node_toolbar_toggle_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = node_has_tools_region(sa); - - if (ar) { - ED_region_toggle_hidden(C, ar); - } - - return OPERATOR_FINISHED; -} - -/* non-standard poll operator which doesn't care if there are any nodes */ -static bool node_toolbar_poll(bContext *C) -{ - ScrArea *sa = CTX_wm_area(C); - return (sa && (sa->spacetype == SPACE_NODE)); -} - -void NODE_OT_toolbar(wmOperatorType *ot) -{ - ot->name = "Tool Shelf"; - ot->description = "Toggles tool shelf display"; - ot->idname = "NODE_OT_toolbar"; - - ot->exec = node_toolbar_toggle_exec; - ot->poll = node_toolbar_poll; - - /* flags */ - ot->flag = 0; -} diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index 52dab2a44a8..2152bb9847a 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -242,64 +242,6 @@ void snode_group_offset(SpaceNode *snode, float *x, float *y) } } -/* ******************** manage regions ********************* */ - -ARegion *node_has_buttons_region(ScrArea *sa) -{ - ARegion *ar, *arnew; - - ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); - if (ar) { - return ar; - } - - /* add subdiv level; after header */ - ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); - - /* is error! */ - if (ar == NULL) { - return NULL; - } - - arnew = MEM_callocN(sizeof(ARegion), "buttons for node"); - - BLI_insertlinkafter(&sa->regionbase, ar, arnew); - arnew->regiontype = RGN_TYPE_UI; - arnew->alignment = RGN_ALIGN_RIGHT; - - arnew->flag = RGN_FLAG_HIDDEN; - - return arnew; -} - -ARegion *node_has_tools_region(ScrArea *sa) -{ - ARegion *ar, *arnew; - - ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS); - if (ar) { - return ar; - } - - /* add subdiv level; after header */ - ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); - - /* is error! */ - if (ar == NULL) { - return NULL; - } - - arnew = MEM_callocN(sizeof(ARegion), "node tools"); - - BLI_insertlinkafter(&sa->regionbase, ar, arnew); - arnew->regiontype = RGN_TYPE_TOOLS; - arnew->alignment = RGN_ALIGN_LEFT; - - arnew->flag = RGN_FLAG_HIDDEN; - - return arnew; -} - /* ******************** default callbacks for node space ***************** */ static SpaceLink *node_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene)) @@ -675,7 +617,7 @@ static void node_main_region_init(wmWindowManager *wm, ARegion *ar) WM_event_add_keymap_handler(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "Node Editor", SPACE_NODE, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); /* add drop boxes */ lb = WM_dropboxmap_find("Node Editor", SPACE_NODE, RGN_TYPE_WINDOW); diff --git a/source/blender/editors/space_outliner/CMakeLists.txt b/source/blender/editors/space_outliner/CMakeLists.txt index f08069c418b..d235dd47136 100644 --- a/source/blender/editors/space_outliner/CMakeLists.txt +++ b/source/blender/editors/space_outliner/CMakeLists.txt @@ -21,13 +21,13 @@ set(INC ../../blenlib ../../blentranslation ../../depsgraph - ../../imbuf ../../gpu + ../../imbuf ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c index 835c154786b..6da42ecb3c0 100644 --- a/source/blender/editors/space_outliner/outliner_collections.c +++ b/source/blender/editors/space_outliner/outliner_collections.c @@ -284,7 +284,8 @@ static int collection_delete_exec(bContext *C, wmOperator *op) data.collections_to_edit = BLI_gset_ptr_new(__func__); - /* We first walk over and find the Collections we actually want to delete (ignoring duplicates). */ + /* We first walk over and find the Collections we actually want to delete + * (ignoring duplicates). */ outliner_tree_traverse( soops, &soops->tree, 0, TSE_SELECTED, collection_find_data_to_edit, &data); @@ -295,8 +296,8 @@ static int collection_delete_exec(bContext *C, wmOperator *op) /* Test in case collection got deleted as part of another one. */ if (BLI_findindex(&bmain->collections, collection) != -1) { - /* We cannot allow to delete collections that are indirectly linked, or that are used by (linked to...) - * other linked scene/collection. */ + /* We cannot allow to delete collections that are indirectly linked, + * or that are used by (linked to...) other linked scene/collection. */ bool skip = false; if (ID_IS_LINKED(collection)) { if (collection->id.tag & LIB_TAG_INDIRECT) { @@ -650,7 +651,8 @@ static int collection_instance_exec(bContext *C, wmOperator *UNUSED(op)) data.collections_to_edit = BLI_gset_ptr_new(__func__); - /* We first walk over and find the Collections we actually want to instance (ignoring duplicates). */ + /* We first walk over and find the Collections we actually want to instance + * (ignoring duplicates). */ outliner_tree_traverse( soops, &soops->tree, 0, TSE_SELECTED, collection_find_data_to_edit, &data); @@ -957,7 +959,8 @@ static int collection_isolate_exec(bContext *C, wmOperator *op) }; data.collections_to_edit = BLI_gset_ptr_new(__func__); - /* Hide all collections before the isolate function - needed in order to support multiple selected collections. */ + /* Hide all collections before the isolate function - + * needed in order to support multiple selected collections. */ if (!extend) { LayerCollection *lc_master = view_layer->layer_collections.first; for (LayerCollection *lc_iter = lc_master->layer_collections.first; lc_iter; diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.c b/source/blender/editors/space_outliner/outliner_dragdrop.c index cff262698fa..49ba397a108 100644 --- a/source/blender/editors/space_outliner/outliner_dragdrop.c +++ b/source/blender/editors/space_outliner/outliner_dragdrop.c @@ -144,7 +144,8 @@ static TreeElement *outliner_drop_insert_find(bContext *C, te_hovered = outliner_find_item_at_y(soops, &soops->tree, view_mval[1]); if (te_hovered) { - /* mouse hovers an element (ignoring x-axis), now find out how to insert the dragged item exactly */ + /* Mouse hovers an element (ignoring x-axis), + * now find out how to insert the dragged item exactly. */ const float margin = UI_UNIT_Y * (1.0f / 4); if (view_mval[1] < (te_hovered->ys + margin)) { @@ -174,7 +175,8 @@ static TreeElement *outliner_drop_insert_find(bContext *C, } } else { - /* mouse doesn't hover any item (ignoring x-axis), so it's either above list bounds or below. */ + /* Mouse doesn't hover any item (ignoring x-axis), + * so it's either above list bounds or below. */ TreeElement *first = soops->tree.first; TreeElement *last = soops->tree.last; diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index 2d33c5db49d..b556f58a02d 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -100,7 +100,7 @@ static void outliner_width(SpaceOutliner *soops, ListBase *lb, int *w) { TreeElement *te = lb->first; while (te) { -// TreeStoreElem *tselem = TREESTORE(te); + // TreeStoreElem *tselem = TREESTORE(te); // XXX fixme... te->xend is not set yet if (!TSELEM_OPEN(tselem, soops)) { @@ -333,7 +333,7 @@ static void hidebutton_base_flag_cb(bContext *C, void *poin, void *poin2) if (depsgraph_changed) { BKE_main_collection_sync_remap(bmain); - DEG_id_tag_update(&ob->id, LIB_TAG_COPIED_ON_WRITE); + DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); DEG_relations_tag_update(bmain); WM_main_add_notifier(NC_OBJECT | ND_DRAW, &ob->id); } @@ -627,6 +627,10 @@ static void outliner_draw_restrictbuts(uiBlock *block, UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK); UI_but_drawflag_enable(bt, UI_BUT_ICON_REVERSE); } + else if ((tselem->type == 0 && te->idcode == ID_OB) && + (te->flag & TE_CHILD_NOT_IN_COLLECTION)) { + /* Don't show restrict columns for children that are not directly inside the collection. */ + } else if (tselem->type == 0 && te->idcode == ID_OB) { PointerRNA ptr; Object *ob = (Object *)tselem->id; @@ -898,7 +902,7 @@ static void outliner_draw_restrictbuts(uiBlock *block, ICON_HIDE_OFF; } bt = uiDefIconBut(block, - UI_BTYPE_TOGGLE, + UI_BTYPE_ICON_TOGGLE, 0, icon, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), @@ -1010,7 +1014,7 @@ static void outliner_draw_userbuts(uiBlock *block, ARegion *ar, SpaceOutliner *s tip = TIP_("Data-block has no users and will be deleted"); } bt = uiDefIconButBitS(block, - UI_BTYPE_TOGGLE, + UI_BTYPE_ICON_TOGGLE, LIB_FAKEUSER, 1, icon, @@ -1045,7 +1049,7 @@ static void outliner_draw_userbuts(uiBlock *block, ARegion *ar, SpaceOutliner *s UI_but_flag_enable(bt, but_flag); bt = uiDefButBitS(block, - UI_BTYPE_TOGGLE, + UI_BTYPE_ICON_TOGGLE, LIB_FAKEUSER, 1, (id->flag & LIB_FAKEUSER) ? "F" : " ", @@ -1561,7 +1565,8 @@ TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te) data.icon = ICON_GROUP; break; } - /* Removed the icons from outliner. Need a better structure with Layers, Palettes and Colors */ + /* Removed the icons from outliner. + * Need a better structure with Layers, Palettes and Colors. */ case TSE_GP_LAYER: { /* indicate whether layer is active */ bGPDlayer *gpl = te->directdata; @@ -2073,7 +2078,10 @@ static void outliner_draw_tree_element(bContext *C, tselem = TREESTORE(te); if (*starty + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && *starty <= ar->v2d.cur.ymax) { - const float alpha_fac = ((te->flag & TE_DISABLED) || draw_grayed_out) ? 0.5f : 1.0f; + const float alpha_fac = ((te->flag & TE_DISABLED) || (te->flag & TE_CHILD_NOT_IN_COLLECTION) || + draw_grayed_out) ? + 0.5f : + 1.0f; const float alpha = 0.5f * alpha_fac; int xmax = ar->v2d.cur.xmax; @@ -2099,7 +2107,8 @@ static void outliner_draw_tree_element(bContext *C, } else if (te->idcode == ID_OB) { Object *ob = (Object *)tselem->id; - Base *base = BKE_view_layer_base_find(view_layer, ob); + Base *base = (te->directdata) ? (Base *)te->directdata : + BKE_view_layer_base_find(view_layer, ob); const bool is_selected = (base != NULL) && ((base->flag & BASE_SELECTED) != 0); if (ob == obact || is_selected) { @@ -2254,26 +2263,6 @@ static void outliner_draw_tree_element(bContext *C, GPU_blend(true); - /* divider */ - { - GPUVertFormat *format = immVertexFormat(); - uint pos = GPU_vertformat_attr_add( - format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); - unsigned char col[4]; - - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - UI_GetThemeColorShade4ubv(TH_BACK, -40, col); - col[3] *= alpha_fac; - - immUniformColor4ubv(col); - immRecti(pos, - tempx - 10.0f * ufac, - *starty + 4.0f * ufac, - tempx - 8.0f * ufac, - *starty + UI_UNIT_Y - 4.0f * ufac); - immUnbindProgram(); - } - MergedIconRow merged = {{0}}; outliner_draw_iconrow(C, block, @@ -2337,17 +2326,28 @@ static void outliner_draw_hierarchy_lines_recursive(unsigned pos, bool draw_grayed_out, int *starty) { - TreeElement *te, *te_vertical_line_last = NULL; - int y1, y2; + TreeElement *te, *te_vertical_line_last = NULL, *te_vertical_line_last_dashed = NULL; + int y1, y2, y1_dashed, y2_dashed; if (BLI_listbase_is_empty(lb)) { return; } + struct { + int steps_num; + int step_len; + int gap_len; + } dash = { + .steps_num = 4, + }; + + dash.step_len = UI_UNIT_X / dash.steps_num; + dash.gap_len = dash.step_len / 2; + const unsigned char grayed_alpha = col[3] / 2; /* For vertical lines between objects. */ - y1 = y2 = *starty; + y1 = y2 = y1_dashed = y2_dashed = *starty; for (te = lb->first; te; te = te->next) { bool draw_childs_grayed_out = draw_grayed_out || (te->flag & TE_DRAGGING); TreeStoreElem *tselem = TREESTORE(te); @@ -2359,15 +2359,30 @@ static void outliner_draw_hierarchy_lines_recursive(unsigned pos, immUniformColor4ubv(col); } - /* Horizontal Line? */ - if (tselem->type == 0 && (te->idcode == ID_OB || te->idcode == ID_SCE)) { - immRecti(pos, startx, *starty, startx + UI_UNIT_X, *starty - 1); + if ((te->flag & TE_CHILD_NOT_IN_COLLECTION) == 0) { + /* Horizontal Line? */ + if (tselem->type == 0 && (te->idcode == ID_OB || te->idcode == ID_SCE)) { + immRecti(pos, startx, *starty, startx + UI_UNIT_X, *starty - U.pixelsize); - /* Vertical Line? */ - if (te->idcode == ID_OB) { - te_vertical_line_last = te; - y2 = *starty; + /* Vertical Line? */ + if (te->idcode == ID_OB) { + te_vertical_line_last = te; + y2 = *starty; + } + y1_dashed = *starty - UI_UNIT_Y; + } + } + else { + BLI_assert(te->idcode == ID_OB); + /* Horizontal line - dashed. */ + int start = startx; + for (int i = 0; i < dash.steps_num; i++) { + immRecti(pos, start, *starty, start + dash.step_len - dash.gap_len, *starty - U.pixelsize); + start += dash.step_len; } + + te_vertical_line_last_dashed = te; + y2_dashed = *starty; } *starty -= UI_UNIT_Y; @@ -2388,7 +2403,19 @@ static void outliner_draw_hierarchy_lines_recursive(unsigned pos, /* Vertical line. */ te = te_vertical_line_last; if ((te != NULL) && (te->parent || lb->first != lb->last)) { - immRecti(pos, startx, y1 + UI_UNIT_Y, startx + 1, y2); + immRecti(pos, startx, y1 + UI_UNIT_Y, startx + U.pixelsize, y2); + } + + /* Children that are not in the collection are always in the end of the subtree. + * This way we can draw their own dashed vertical lines. */ + te = te_vertical_line_last_dashed; + if ((te != NULL) && (te->parent || lb->first != lb->last)) { + const int steps_num = ((y1_dashed + UI_UNIT_Y) - y2_dashed) / dash.step_len; + int start = y1_dashed + UI_UNIT_Y; + for (int i = 0; i < steps_num; i++) { + immRecti(pos, startx, start, startx + U.pixelsize, start - dash.step_len + dash.gap_len); + start -= dash.step_len; + } } } @@ -2472,7 +2499,7 @@ static void outliner_draw_highlights_recursive(unsigned pos, /* selection status */ if (tselem->flag & TSE_SELECTED) { immUniformColor4fv(col_selection); - immRecti(pos, 0, start_y + 1, (int)ar->v2d.cur.xmax, start_y + UI_UNIT_Y - 1); + immRecti(pos, 0, start_y, (int)ar->v2d.cur.xmax, start_y + UI_UNIT_Y); } /* highlights */ @@ -2486,15 +2513,15 @@ static void outliner_draw_highlights_recursive(unsigned pos, if (tselem->flag & TSE_DRAG_BEFORE) { immUniformColor4fv(col); - immRecti(pos, start_x, start_y + UI_UNIT_Y - 1, end_x, start_y + UI_UNIT_Y + 1); + immRecti(pos, start_x, start_y + UI_UNIT_Y, end_x, start_y + UI_UNIT_Y); } else if (tselem->flag & TSE_DRAG_AFTER) { immUniformColor4fv(col); - immRecti(pos, start_x, start_y - 1, end_x, start_y + 1); + immRecti(pos, start_x, start_y, end_x, start_y); } else { immUniformColor3fvAlpha(col, col[3] * 0.5f); - immRecti(pos, start_x, start_y + 1, end_x, start_y + UI_UNIT_Y - 1); + immRecti(pos, start_x, start_y, end_x, start_y + UI_UNIT_Y); } } else { @@ -2503,12 +2530,12 @@ static void outliner_draw_highlights_recursive(unsigned pos, * we don't expand items when searching in the datablocks but we * still want to highlight any filter matches. */ immUniformColor4fv(col_searchmatch); - immRecti(pos, start_x, start_y + 1, end_x, start_y + UI_UNIT_Y - 1); + immRecti(pos, start_x, start_y, end_x, start_y + UI_UNIT_Y); } else if (tselem->flag & TSE_HIGHLIGHTED) { /* mouse hover highlight */ immUniformColor4fv(col_highlight); - immRecti(pos, 0, start_y + 1, end_x, start_y + UI_UNIT_Y - 1); + immRecti(pos, 0, start_y, end_x, start_y + UI_UNIT_Y); } } } @@ -2587,7 +2614,7 @@ static void outliner_draw_tree(bContext *C, // gray hierarchy lines starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y / 2 - OL_Y_OFFSET; - startx = UI_UNIT_X / 2 - 1.0f; + startx = UI_UNIT_X / 2 - (U.pixelsize + 1) / 2; outliner_draw_hierarchy_lines(soops, &soops->tree, startx, &starty); // items themselves @@ -2649,29 +2676,6 @@ static void outliner_back(ARegion *ar) immUnbindProgram(); } -static void outliner_draw_restrictcols(ARegion *ar) -{ - GPU_line_width(1.0f); - - uint pos = GPU_vertformat_attr_add( - immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - immUniformThemeColorShadeAlpha(TH_BACK, -15, -200); - immBegin(GPU_PRIM_LINES, 6); - - immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)ar->v2d.cur.ymax); - immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)ar->v2d.cur.ymin); - - immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)ar->v2d.cur.ymax); - immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)ar->v2d.cur.ymin); - - immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), (int)ar->v2d.cur.ymax); - immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), (int)ar->v2d.cur.ymin); - - immEnd(); - immUnbindProgram(); -} - /* ****************************************************** */ /* Main Entrypoint - Draw contents of Outliner editor */ @@ -2716,7 +2720,7 @@ void draw_outliner(const bContext *C) else { /* width must take into account restriction columns (if visible) * so that entries will still be visible */ - //outliner_width(soops, &soops->tree, &sizex); + // outliner_width(soops, &soops->tree, &sizex); // XXX should use outliner_width instead when te->xend will be set correctly... outliner_rna_width(soops, &soops->tree, &sizex, 0); @@ -2759,13 +2763,10 @@ void draw_outliner(const bContext *C) } else if ((soops->outlinevis == SO_ID_ORPHANS) && has_restrict_icons) { /* draw user toggle columns */ - outliner_draw_restrictcols(ar); outliner_draw_userbuts(block, ar, soops, &soops->tree); } else if (has_restrict_icons) { /* draw restriction columns */ - outliner_draw_restrictcols(ar); - outliner_draw_restrictbuts(block, scene, view_layer, ar, soops, &soops->tree); } diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index 11d01931945..a943e972cf5 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -1296,8 +1296,8 @@ void OUTLINER_OT_scroll_page(wmOperatorType *ot) #if 0 /* find next element that has this name */ -static TreeElement *outliner_find_name(SpaceOutliner *soops, ListBase *lb, char *name, int flags, - TreeElement *prev, int *prevFound) +static TreeElement *outliner_find_name( + SpaceOutliner *soops, ListBase *lb, char *name, int flags, TreeElement *prev, int *prevFound) { TreeElement *te, *tes; @@ -1318,16 +1318,18 @@ static TreeElement *outliner_find_name(SpaceOutliner *soops, ListBase *lb, char } tes = outliner_find_name(soops, &te->subtree, name, flags, prev, prevFound); - if (tes) return tes; + if (tes) + return tes; } /* nothing valid found */ return NULL; } -static void outliner_find_panel(Scene *UNUSED(scene), ARegion *ar, SpaceOutliner *soops, int again, int flags) +static void outliner_find_panel( + Scene *UNUSED(scene), ARegion *ar, SpaceOutliner *soops, int again, int flags) { - ReportList *reports = NULL; // CTX_wm_reports(C); + ReportList *reports = NULL; // CTX_wm_reports(C); TreeElement *te = NULL; TreeElement *last_find; TreeStoreElem *tselem; @@ -1354,10 +1356,10 @@ static void outliner_find_panel(Scene *UNUSED(scene), ARegion *ar, SpaceOutliner else { /* pop up panel - no previous, or user didn't want search after previous */ name[0] = '\0'; -// XXX if (sbutton(name, 0, sizeof(name) - 1, "Find: ") && name[0]) { -// te = outliner_find_name(soops, &soops->tree, name, flags, NULL, &prevFound); -// } -// else return; /* XXX RETURN! XXX */ + // XXX if (sbutton(name, 0, sizeof(name) - 1, "Find: ") && name[0]) { + // te = outliner_find_name(soops, &soops->tree, name, flags, NULL, &prevFound); + // } + // else return; /* XXX RETURN! XXX */ } /* do selection and reveal */ @@ -1374,7 +1376,8 @@ static void outliner_find_panel(Scene *UNUSED(scene), ARegion *ar, SpaceOutliner /* make te->ys center of view */ ytop = (int)(te->ys + BLI_rctf_size_y(&ar->v2d.mask) / 2); - if (ytop > 0) ytop = 0; + if (ytop > 0) + ytop = 0; ar->v2d.cur.ymax = (float)ytop; ar->v2d.cur.ymin = (float)(ytop - BLI_rctf_size_y(&ar->v2d.mask)); @@ -1475,7 +1478,8 @@ void OUTLINER_OT_show_one_level(wmOperatorType *ot) /* Show Hierarchy ----------------------------------------------- */ -/* helper function for tree_element_shwo_hierarchy() - recursively checks whether subtrees have any objects*/ +/* Helper function for tree_element_shwo_hierarchy() - + * recursively checks whether subtrees have any objects. */ static int subtree_has_objects(ListBase *lb) { TreeElement *te; @@ -1630,7 +1634,8 @@ static void tree_element_to_path(TreeElement *te, /* check if we're looking for first ID, or appending to path */ if (*id) { /* just 'append' property to path - * - to prevent memory leaks, we must write to newpath not path, then free old path + swap them + * - to prevent memory leaks, we must write to newpath not path, + * then free old path + swap them. */ if (tse->type == TSE_RNA_PROPERTY) { if (RNA_property_type(prop) == PROP_POINTER) { @@ -1679,7 +1684,8 @@ static void tree_element_to_path(TreeElement *te, } } else { - /* no ID, so check if entry is RNA-struct, and if that RNA-struct is an ID datablock to extract info from */ + /* no ID, so check if entry is RNA-struct, + * and if that RNA-struct is an ID datablock to extract info from. */ if (tse->type == TSE_RNA_STRUCT) { /* ptr->data not ptr->id.data seems to be the one we want, * since ptr->data is sometimes the owner of this ID? */ @@ -2098,8 +2104,7 @@ static int outliner_orphans_purge_invoke(bContext *C, wmOperator *op, const wmEv /* Tag all IDs having zero users. */ ID *id; - FOREACH_MAIN_ID_BEGIN(bmain, id) - { + FOREACH_MAIN_ID_BEGIN (bmain, id) { outliner_orphans_purge_tag(id, num_tagged); } FOREACH_MAIN_ID_END; @@ -2146,8 +2151,7 @@ static int outliner_orphans_purge_exec(bContext *C, wmOperator *op) if ((num_tagged[INDEX_ID_NULL] = RNA_int_get(op->ptr, "num_deleted")) == 0) { /* Tag all IDs having zero users. */ ID *id; - FOREACH_MAIN_ID_BEGIN(bmain, id) - { + FOREACH_MAIN_ID_BEGIN (bmain, id) { outliner_orphans_purge_tag(id, num_tagged); } FOREACH_MAIN_ID_END; diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h index d382384076b..8211e3005c7 100644 --- a/source/blender/editors/space_outliner/outliner_intern.h +++ b/source/blender/editors/space_outliner/outliner_intern.h @@ -130,6 +130,7 @@ enum { TE_FREE_NAME = (1 << 3), TE_DISABLED = (1 << 4), TE_DRAGGING = (1 << 5), + TE_CHILD_NOT_IN_COLLECTION = (1 << 6), }; /* button events */ @@ -235,10 +236,6 @@ eOLDrawState tree_element_active(struct bContext *C, void outliner_item_do_activate_from_tree_element( struct bContext *C, TreeElement *te, TreeStoreElem *tselem, bool extend, bool recursive); -int outliner_item_do_activate_from_cursor(struct bContext *C, - const int mval[2], - bool extend, - bool recursive); void outliner_item_select(struct SpaceOutliner *soops, const struct TreeElement *te, diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c index bab5ee02916..995f41382cd 100644 --- a/source/blender/editors/space_outliner/outliner_select.c +++ b/source/blender/editors/space_outliner/outliner_select.c @@ -547,10 +547,11 @@ static eOLDrawState tree_element_active_defgroup(bContext *C, WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, ob); } else { - if (ob == OBACT(view_layer)) + if (ob == OBACT(view_layer)) { if (ob->actdef == te->index + 1) { return OL_DRAWSEL_NORMAL; } + } } return OL_DRAWSEL_NONE; } @@ -1028,8 +1029,9 @@ eOLDrawState tree_element_active(bContext *C, const bool handle_all_types) { switch (te->idcode) { - /* Note: ID_OB only if handle_all_type is true, else objects are handled specially to allow multiple - * selection. See do_outliner_item_activate. */ + /** \note #ID_OB only if handle_all_type is true, + * else objects are handled specially to allow multiple selection. + * See #do_outliner_item_activate. */ case ID_OB: if (handle_all_types) { return tree_element_set_active_object(C, scene, view_layer, soops, te, set, false); @@ -1131,8 +1133,8 @@ static void do_outliner_item_activate_tree_element(bContext *C, TSE_SEQUENCE_DUP, TSE_EBONE, TSE_LAYER_COLLECTION)) { - /* Note about TSE_EBONE: In case of a same ID_AR datablock shared among several objects, we do not want - * to switch out of edit mode (see T48328 for details). */ + /* Note about TSE_EBONE: In case of a same ID_AR datablock shared among several objects, + * we do not want to switch out of edit mode (see T48328 for details). */ } else if (tselem->id && OB_DATA_SUPPORT_EDITMODE(te->idcode)) { /* Support edit-mode toggle, keeping the active object as is. */ @@ -1295,10 +1297,11 @@ void outliner_item_do_activate_from_tree_element( * * May expend/collapse branches or activate items. * */ -int outliner_item_do_activate_from_cursor(bContext *C, - const int mval[2], - bool extend, - bool recursive) +static int outliner_item_do_activate_from_cursor(bContext *C, + const int mval[2], + const bool extend, + const bool recursive, + const bool deselect_all) { ARegion *ar = CTX_wm_region(C); SpaceOutliner *soops = CTX_wm_space_outliner(C); @@ -1313,7 +1316,10 @@ int outliner_item_do_activate_from_cursor(bContext *C, } if (!(te = outliner_find_item_at_y(soops, &soops->tree, view_mval[1]))) { - /* skip */ + if (deselect_all) { + outliner_flag_set(&soops->tree, TSE_SELECTED, false); + changed = true; + } } else if (outliner_item_is_co_within_close_toggle(te, view_mval[0])) { outliner_item_toggle_closed(te, extend); @@ -1349,9 +1355,10 @@ int outliner_item_do_activate_from_cursor(bContext *C, /* event can enterkey, then it opens/closes */ static int outliner_item_activate_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - bool extend = RNA_boolean_get(op->ptr, "extend"); - bool recursive = RNA_boolean_get(op->ptr, "recursive"); - return outliner_item_do_activate_from_cursor(C, event->mval, extend, recursive); + const bool extend = RNA_boolean_get(op->ptr, "extend"); + const bool recursive = RNA_boolean_get(op->ptr, "recursive"); + const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all"); + return outliner_item_do_activate_from_cursor(C, event->mval, extend, recursive, deselect_all); } void OUTLINER_OT_item_activate(wmOperatorType *ot) @@ -1364,8 +1371,15 @@ void OUTLINER_OT_item_activate(wmOperatorType *ot) ot->poll = ED_operator_outliner_active; + PropertyRNA *prop; RNA_def_boolean(ot->srna, "extend", true, "Extend", "Extend selection for activation"); RNA_def_boolean(ot->srna, "recursive", false, "Recursive", "Select Objects and their children"); + prop = RNA_def_boolean(ot->srna, + "deselect_all", + false, + "Deselect On Nothing", + "Deselect all when nothing under the cursor"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /* ****************************************************** */ diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index ad4661102bc..0f9efb0d2e1 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -283,7 +283,7 @@ static void unlink_collection_cb(bContext *C, static void unlink_object_cb(bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), - TreeElement *UNUSED(te), + TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem, void *UNUSED(user_data)) @@ -291,6 +291,15 @@ static void unlink_object_cb(bContext *C, Main *bmain = CTX_data_main(C); Object *ob = (Object *)tselem->id; + if (GS(tsep->id->name) == ID_OB) { + /* Parented objects need to find which collection to unlink from. */ + TreeElement *te_parent = te->parent; + while (tsep && GS(tsep->id->name) == ID_OB) { + te_parent = te_parent->parent; + tsep = te_parent ? TREESTORE(te_parent) : NULL; + } + } + if (tsep) { if (GS(tsep->id->name) == ID_GR) { Collection *parent = (Collection *)tsep->id; @@ -452,8 +461,8 @@ static void object_select_cb(bContext *C, Object *ob = (Object *)tselem->id; Base *base = BKE_view_layer_base_find(view_layer, ob); - if (base && ((base->flag & BASE_VISIBLE) != 0)) { - base->flag |= BASE_SELECTED; + if (base) { + ED_object_base_select(base, BA_SELECT); } } @@ -650,7 +659,8 @@ static void singleuser_world_cb(bContext *C, } /** - * \param select_recurse: Set to false for operations which are already recursively operating on their children. + * \param select_recurse: Set to false for operations which are already + * recursively operating on their children. */ void outliner_do_object_operation_ex(bContext *C, ReportList *reports, @@ -738,7 +748,8 @@ static void refreshdrivers_animdata_cb(int UNUSED(event), IdAdtTemplate *iat = (IdAdtTemplate *)tselem->id; FCurve *fcu; - /* loop over drivers, performing refresh (i.e. check graph_buttons.c and rna_fcurve.c for details) */ + /* Loop over drivers, performing refresh + * (i.e. check graph_buttons.c and rna_fcurve.c for details). */ for (fcu = iat->adt->drivers.first; fcu; fcu = fcu->next) { fcu->flag &= ~FCURVE_DISABLED; @@ -1768,7 +1779,8 @@ static int outliner_action_set_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } else if (act->idroot == 0) { - /* hopefully in this case (i.e. library of userless actions), the user knows what they're doing... */ + /* Hopefully in this case (i.e. library of userless actions), + * the user knows what they're doing. */ BKE_reportf(op->reports, RPT_WARNING, "Action '%s' does not specify what data-blocks it can be used on " @@ -1834,8 +1846,8 @@ typedef enum eOutliner_AnimDataOps { OUTLINER_ANIMOP_REFRESH_DRV, OUTLINER_ANIMOP_CLEAR_DRV - //OUTLINER_ANIMOP_COPY_DRIVERS, - //OUTLINER_ANIMOP_PASTE_DRIVERS + // OUTLINER_ANIMOP_COPY_DRIVERS, + // OUTLINER_ANIMOP_PASTE_DRIVERS } eOutliner_AnimDataOps; static const EnumPropertyItem prop_animdata_op_types[] = { @@ -1901,7 +1913,7 @@ static int outliner_animdata_operation_exec(bContext *C, wmOperator *op) soops, datalevel, event, &soops->tree, refreshdrivers_animdata_cb, NULL); WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN, NULL); - //ED_undo_push(C, "Refresh Drivers"); /* no undo needed - shouldn't have any impact? */ + // ED_undo_push(C, "Refresh Drivers"); /* no undo needed - shouldn't have any impact? */ updateDeps = 1; break; diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c index a03d9b6fb6d..4e3fd6037bb 100644 --- a/source/blender/editors/space_outliner/outliner_tree.c +++ b/source/blender/editors/space_outliner/outliner_tree.c @@ -48,6 +48,7 @@ #include "DNA_linestyle_types.h" #include "BLI_blenlib.h" +#include "BLI_listbase.h" #include "BLI_utildefines.h" #include "BLI_mempool.h" #include "BLI_fnmatch.h" @@ -359,12 +360,12 @@ static void outliner_add_object_contents(SpaceOutliner *soops, pchan->temp = (void *)ten; if (pchan->constraints.first) { - //Object *target; + // Object *target; bConstraint *con; TreeElement *ten1; TreeElement *tenla1 = outliner_add_element( soops, &ten->subtree, ob, ten, TSE_CONSTRAINT_BASE, 0); - //char *str; + // char *str; tenla1->name = IFACE_("Constraints"); for (con = pchan->constraints.first; con; con = con->next, const_index++) { @@ -372,9 +373,12 @@ static void outliner_add_object_contents(SpaceOutliner *soops, soops, &tenla1->subtree, ob, tenla1, TSE_CONSTRAINT, const_index); #if 0 /* disabled as it needs to be reworked for recoded constraints system */ target = get_constraint_target(con, &str); - if (str && str[0]) ten1->name = str; - else if (target) ten1->name = target->id.name + 2; - else ten1->name = con->name; + if (str && str[0]) + ten1->name = str; + else if (target) + ten1->name = target->id.name + 2; + else + ten1->name = con->name; #endif ten1->name = con->name; ten1->directdata = con; @@ -422,11 +426,11 @@ static void outliner_add_object_contents(SpaceOutliner *soops, } if (ob->constraints.first) { - //Object *target; + // Object *target; bConstraint *con; TreeElement *ten; TreeElement *tenla = outliner_add_element(soops, &te->subtree, ob, te, TSE_CONSTRAINT_BASE, 0); - //char *str; + // char *str; int a; tenla->name = IFACE_("Constraints"); @@ -434,9 +438,12 @@ static void outliner_add_object_contents(SpaceOutliner *soops, ten = outliner_add_element(soops, &tenla->subtree, ob, tenla, TSE_CONSTRAINT, a); #if 0 /* disabled due to constraints system targets recode... code here needs review */ target = get_constraint_target(con, &str); - if (str && str[0]) ten->name = str; - else if (target) ten->name = target->id.name + 2; - else ten->name = con->name; + if (str && str[0]) + ten->name = str; + else if (target) + ten->name = target->id.name + 2; + else + ten->name = con->name; #endif ten->name = con->name; ten->directdata = con; @@ -647,7 +654,7 @@ static void outliner_add_id_contents(SpaceOutliner *soops, } case ID_AC: { // XXX do we want to be exposing the F-Curves here? - //bAction *act = (bAction *)id; + // bAction *act = (bAction *)id; break; } case ID_AR: { @@ -952,7 +959,7 @@ static TreeElement *outliner_add_element( /* Don't display arrays larger, weak but index is stored as a short, * also the outliner isn't intended for editing such large data-sets. */ - BLI_STATIC_ASSERT(sizeof(te->index) == 2, "Index is no longer short!"); + BLI_STATIC_ASSERT(sizeof(te->index) == 2, "Index is no longer short!") const int tot_limit = SHRT_MAX; int a, tot; @@ -1464,16 +1471,111 @@ static void outliner_make_object_parent_hierarchy(ListBase *lb) BLI_remlink(lb, te); tep = (TreeElement *)ob->parent->id.newid; BLI_addtail(&tep->subtree, te); - // set correct parent pointers - for (te = tep->subtree.first; te; te = te->next) { - te->parent = tep; - } + te->parent = tep; } } te = ten; } } +/** + * For all objects in the tree, lookup the parent in this map, + * and move or add tree elements as needed. + */ +static void outliner_make_object_parent_hierarchy_collections(SpaceOutliner *soops, + GHash *object_tree_elements_hash) +{ + GHashIterator gh_iter; + GHASH_ITER (gh_iter, object_tree_elements_hash) { + Object *child = BLI_ghashIterator_getKey(&gh_iter); + + if (child->parent == NULL) { + continue; + } + + ListBase *child_ob_tree_elements = BLI_ghashIterator_getValue(&gh_iter); + ListBase *parent_ob_tree_elements = BLI_ghash_lookup(object_tree_elements_hash, child->parent); + if (parent_ob_tree_elements == NULL) { + continue; + } + + for (LinkData *link = parent_ob_tree_elements->first; link; link = link->next) { + TreeElement *parent_ob_tree_element = link->data; + TreeElement *parent_ob_collection_tree_element = NULL; + bool found = false; + + /* We always want to remove the child from the direct collection its parent is nested under. + * This is particularly important when dealing with multi-level nesting (grandchildren). */ + parent_ob_collection_tree_element = parent_ob_tree_element->parent; + while (!ELEM(TREESTORE(parent_ob_collection_tree_element)->type, + TSE_VIEW_COLLECTION_BASE, + TSE_LAYER_COLLECTION)) { + parent_ob_collection_tree_element = parent_ob_collection_tree_element->parent; + } + + for (LinkData *link_iter = child_ob_tree_elements->first; link_iter; + link_iter = link_iter->next) { + TreeElement *child_ob_tree_element = link_iter->data; + + if (child_ob_tree_element->parent == parent_ob_collection_tree_element) { + /* Move from the collection subtree into the parent object subtree. */ + BLI_remlink(&parent_ob_collection_tree_element->subtree, child_ob_tree_element); + BLI_addtail(&parent_ob_tree_element->subtree, child_ob_tree_element); + child_ob_tree_element->parent = parent_ob_tree_element; + found = true; + break; + } + } + + if (!found) { + /* We add the child in the tree even if it is not in the collection. + * We deliberately clear its subtree though, to make it less proeminent. */ + TreeElement *child_ob_tree_element = outliner_add_element( + soops, &parent_ob_tree_element->subtree, child, parent_ob_tree_element, 0, 0); + outliner_free_tree(&child_ob_tree_element->subtree); + child_ob_tree_element->flag |= TE_CHILD_NOT_IN_COLLECTION; + BLI_addtail(child_ob_tree_elements, BLI_genericNodeN(child_ob_tree_element)); + } + } + } +} + +/** + * Build a map from Object* to a list of TreeElement* matching the object. + */ +static void outliner_object_tree_elements_lookup_create_recursive(GHash *object_tree_elements_hash, + TreeElement *te_parent) +{ + for (TreeElement *te = te_parent->subtree.first; te; te = te->next) { + TreeStoreElem *tselem = TREESTORE(te); + + if (tselem->type == TSE_LAYER_COLLECTION) { + outliner_object_tree_elements_lookup_create_recursive(object_tree_elements_hash, te); + } + else if (tselem->type == 0 && te->idcode == ID_OB) { + Object *ob = (Object *)tselem->id; + ListBase *tree_elements = BLI_ghash_lookup(object_tree_elements_hash, ob); + + if (tree_elements == NULL) { + tree_elements = MEM_callocN(sizeof(ListBase), __func__); + BLI_ghash_insert(object_tree_elements_hash, ob, tree_elements); + } + + BLI_addtail(tree_elements, BLI_genericNodeN(te)); + outliner_object_tree_elements_lookup_create_recursive(object_tree_elements_hash, te); + } + } +} + +static void outliner_object_tree_elements_lookup_free(GHash *object_tree_elements_hash) +{ + GHASH_FOREACH_BEGIN (ListBase *, tree_elements, object_tree_elements_hash) { + BLI_freelistN(tree_elements); + MEM_freeN(tree_elements); + } + GHASH_FOREACH_END(); +} + /* Sorting ------------------------------------------------------ */ typedef struct tTreeSort { @@ -1502,6 +1604,13 @@ static int treesort_alpha_ob(const void *v1, const void *v2) return -1; } else if (comp == 3) { + /* Among objects first come the ones in the collection, followed by the ones not on it. + * This way we can have the dashed lines in a separate style connecting the former. */ + if ((x1->te->flag & TE_CHILD_NOT_IN_COLLECTION) != + (x2->te->flag & TE_CHILD_NOT_IN_COLLECTION)) { + return (x1->te->flag & TE_CHILD_NOT_IN_COLLECTION) ? 1 : -1; + } + comp = strcmp(x1->name, x2->name); if (comp > 0) { @@ -1515,6 +1624,19 @@ static int treesort_alpha_ob(const void *v1, const void *v2) return 0; } +/* Move children that are not in the collection to the end of the list. */ +static int treesort_child_not_in_collection(const void *v1, const void *v2) +{ + const tTreeSort *x1 = v1, *x2 = v2; + + /* Among objects first come the ones in the collection, followed by the ones not on it. + * This way we can have the dashed lines in a separate style connecting the former. */ + if ((x1->te->flag & TE_CHILD_NOT_IN_COLLECTION) != (x2->te->flag & TE_CHILD_NOT_IN_COLLECTION)) { + return (x1->te->flag & TE_CHILD_NOT_IN_COLLECTION) ? 1 : -1; + } + return 0; +} + /* alphabetical comparator */ static int treesort_alpha(const void *v1, const void *v2) { @@ -1548,15 +1670,20 @@ static int treesort_obtype_alpha(const void *v1, const void *v2) else { /* 2nd we check ob type */ if (x1->idcode == ID_OB && x2->idcode == ID_OB) { - if (((Object *)x1->id)->type > ((Object *)x2->id)->type) return 1; - else if (((Object *)x1->id)->type > ((Object *)x2->id)->type) return -1; - else return 0; + if (((Object *)x1->id)->type > ((Object *)x2->id)->type) + return 1; + else if (((Object *)x1->id)->type > ((Object *)x2->id)->type) + return -1; + else + return 0; } else { int comp = strcmp(x1->name, x2->name); - if (comp > 0) return 1; - else if (comp < 0) return -1; + if (comp > 0) + return 1; + else if (comp < 0) + return -1; return 0; } } @@ -1633,6 +1760,50 @@ static void outliner_sort(ListBase *lb) } } +static void outliner_collections_children_sort(ListBase *lb) +{ + TreeElement *te; + TreeStoreElem *tselem; + + te = lb->last; + if (te == NULL) { + return; + } + tselem = TREESTORE(te); + + /* Sorting rules: only object lists. */ + if (tselem->type == 0 && te->idcode == ID_OB) { + int totelem = BLI_listbase_count(lb); + + if (totelem > 1) { + tTreeSort *tear = MEM_mallocN(totelem * sizeof(tTreeSort), "tree sort array"); + tTreeSort *tp = tear; + + for (te = lb->first; te; te = te->next, tp++) { + tselem = TREESTORE(te); + tp->te = te; + tp->name = te->name; + tp->idcode = te->idcode; + tp->id = tselem->id; + } + + qsort(tear, totelem, sizeof(tTreeSort), treesort_child_not_in_collection); + + BLI_listbase_clear(lb); + tp = tear; + while (totelem--) { + BLI_addtail(lb, tp->te); + tp++; + } + MEM_freeN(tear); + } + } + + for (te = lb->first; te; te = te->next) { + outliner_sort(&te->subtree); + } +} + /* Filtering ----------------------------------------------- */ typedef struct OutlinerTreeElementFocus { @@ -1774,10 +1945,11 @@ static TreeElement *outliner_find_first_desired_element_at_y(const SpaceOutliner } /** - * Store information of current outliner scrolling status to be restored later + * Store information of current outliner scrolling status to be restored later. * - * Finds the top-most collection visible in the outliner and populates the OutlinerTreeElementFocus - * struct to retrieve this element later to make sure it is in the same original position as before filtering + * Finds the top-most collection visible in the outliner and populates the + * #OutlinerTreeElementFocus struct to retrieve this element later to make sure it is in the same + * original position as before filtering. */ static void outliner_store_scrolling_position(SpaceOutliner *soops, ARegion *ar, @@ -2182,12 +2354,28 @@ void outliner_build_tree( bool show_objects = !(soops->filter & SO_FILTER_NO_OBJECT); outliner_add_view_layer(soops, &ten->subtree, ten, view_layer, show_objects); + + if ((soops->filter & SO_FILTER_NO_CHILDREN) == 0) { + GHash *object_tree_elements_hash = BLI_ghash_new( + BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); + outliner_object_tree_elements_lookup_create_recursive(object_tree_elements_hash, ten); + outliner_make_object_parent_hierarchy_collections(soops, object_tree_elements_hash); + outliner_object_tree_elements_lookup_free(object_tree_elements_hash); + BLI_ghash_free(object_tree_elements_hash, NULL, NULL); + } } } if ((soops->flag & SO_SKIP_SORT_ALPHA) == 0) { outliner_sort(&soops->tree); } + else if ((soops->filter & SO_FILTER_NO_CHILDREN) == 0) { + /* We group the children that are in the collection before the ones that are not. + * This way we can try to draw them in a different style altogether. + * We also have to respect the original order of the elements in case alphabetical + * sorting is not enabled. This keep object data and modifiers before its children. */ + outliner_collections_children_sort(&soops->tree); + } outliner_filter_tree(soops, view_layer); outliner_restore_scrolling_position(soops, ar, &focus); diff --git a/source/blender/editors/space_outliner/space_outliner.c b/source/blender/editors/space_outliner/space_outliner.c index 26b97a1cdd9..a8e3129b5b4 100644 --- a/source/blender/editors/space_outliner/space_outliner.c +++ b/source/blender/editors/space_outliner/space_outliner.c @@ -74,8 +74,7 @@ static void outliner_main_region_init(wmWindowManager *wm, ARegion *ar) /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "Outliner", SPACE_OUTLINER, 0); - /* don't pass on view2d mask, it's always set with scrollbar space, hide fails */ - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, NULL, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); /* Add dropboxes */ lb = WM_dropboxmap_find("Outliner", SPACE_OUTLINER, RGN_TYPE_WINDOW); @@ -97,9 +96,8 @@ static void outliner_main_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); /* scrollers */ - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY); - UI_view2d_scrollers_draw(C, v2d, scrollers); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); } diff --git a/source/blender/editors/space_script/CMakeLists.txt b/source/blender/editors/space_script/CMakeLists.txt index 1abc05d2270..0bd2a01a151 100644 --- a/source/blender/editors/space_script/CMakeLists.txt +++ b/source/blender/editors/space_script/CMakeLists.txt @@ -23,8 +23,8 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_script/space_script.c b/source/blender/editors/space_script/space_script.c index e26c0e3cec3..b99c2eaf54e 100644 --- a/source/blender/editors/space_script/space_script.c +++ b/source/blender/editors/space_script/space_script.c @@ -47,7 +47,7 @@ #include "script_intern.h" // own include #include "GPU_framebuffer.h" -//static script_run_python(char *funcname, ) +// static script_run_python(char *funcname, ) /* ******************** default callbacks for script space ***************** */ @@ -116,7 +116,7 @@ static void script_main_region_init(wmWindowManager *wm, ARegion *ar) /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "Script", SPACE_SCRIPT, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } static void script_main_region_draw(const bContext *C, ARegion *ar) @@ -192,9 +192,8 @@ void ED_spacetype_script(void) art->init = script_main_region_init; art->draw = script_main_region_draw; art->listener = script_main_region_listener; - art->keymapflag = - ED_KEYMAP_VIEW2D | ED_KEYMAP_UI | - ED_KEYMAP_FRAMES; // XXX need to further test this ED_KEYMAP_UI is needed for button interaction + /* XXX: Need to further test this ED_KEYMAP_UI is needed for button interaction. */ + art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_UI | ED_KEYMAP_FRAMES; BLI_addhead(&st->regiontypes, art); diff --git a/source/blender/editors/space_sequencer/CMakeLists.txt b/source/blender/editors/space_sequencer/CMakeLists.txt index 8b97f7537f8..4668a9cef90 100644 --- a/source/blender/editors/space_sequencer/CMakeLists.txt +++ b/source/blender/editors/space_sequencer/CMakeLists.txt @@ -20,14 +20,14 @@ set(INC ../../blenkernel ../../blenlib ../../blentranslation - ../../imbuf ../../gpu + ../../imbuf ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/atomic - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index 218804b0ab4..b5bb79fb430 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -334,7 +334,7 @@ static int sequencer_add_scene_strip_exec(bContext *C, wmOperator *op) seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel); seq->type = SEQ_TYPE_SCENE; - seq->blend_mode = SEQ_TYPE_CROSS; /* so alpha adjustment fade to the strip below */ + seq->blend_mode = SEQ_TYPE_ALPHAOVER; seq->scene = sce_seq; @@ -422,7 +422,7 @@ static int sequencer_add_movieclip_strip_exec(bContext *C, wmOperator *op) seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel); seq->type = SEQ_TYPE_MOVIECLIP; - seq->blend_mode = SEQ_TYPE_CROSS; + seq->blend_mode = SEQ_TYPE_ALPHAOVER; seq->clip = clip; id_us_ensure_real(&seq->clip->id); @@ -508,7 +508,7 @@ static int sequencer_add_mask_strip_exec(bContext *C, wmOperator *op) seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel); seq->type = SEQ_TYPE_MASK; - seq->blend_mode = SEQ_TYPE_CROSS; + seq->blend_mode = SEQ_TYPE_ALPHAOVER; seq->mask = mask; id_us_ensure_real(&seq->mask->id); @@ -715,7 +715,7 @@ static int sequencer_add_movie_strip_invoke(bContext *C, WM_event_add_fileselect(C, op); return OPERATOR_RUNNING_MODAL; - //return sequencer_add_movie_strip_exec(C, op); + // return sequencer_add_movie_strip_exec(C, op); } static void sequencer_add_draw(bContext *UNUSED(C), wmOperator *op) @@ -797,7 +797,7 @@ static int sequencer_add_sound_strip_invoke(bContext *C, WM_event_add_fileselect(C, op); return OPERATOR_RUNNING_MODAL; - //return sequencer_add_sound_strip_exec(C, op); + // return sequencer_add_sound_strip_exec(C, op); } void SEQUENCER_OT_sound_strip_add(struct wmOperatorType *ot) @@ -1098,14 +1098,8 @@ static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op) if (seq->type == SEQ_TYPE_COLOR) { SolidColorVars *colvars = (SolidColorVars *)seq->effectdata; RNA_float_get_array(op->ptr, "color", colvars->col); - seq->blend_mode = SEQ_TYPE_CROSS; /* so alpha adjustment fade to the strip below */ - } - else if (seq->type == SEQ_TYPE_ADJUSTMENT) { - seq->blend_mode = SEQ_TYPE_CROSS; - } - else if (seq->type == SEQ_TYPE_TEXT) { - seq->blend_mode = SEQ_TYPE_ALPHAOVER; } + seq->blend_mode = SEQ_TYPE_ALPHAOVER; /* an unset channel is a special case where we automatically go above * the other strips. */ @@ -1180,7 +1174,7 @@ void SEQUENCER_OT_effect_strip_add(struct wmOperatorType *ot) RNA_def_enum(ot->srna, "type", sequencer_prop_effect_types, - SEQ_TYPE_CROSS, + SEQ_TYPE_ALPHAOVER, "Type", "Sequencer effect type"); RNA_def_float_vector(ot->srna, diff --git a/source/blender/editors/space_sequencer/sequencer_buttons.c b/source/blender/editors/space_sequencer/sequencer_buttons.c index 8d9fea2cb98..a6458ee5d31 100644 --- a/source/blender/editors/space_sequencer/sequencer_buttons.c +++ b/source/blender/editors/space_sequencer/sequencer_buttons.c @@ -119,30 +119,3 @@ void sequencer_buttons_register(ARegionType *art) pt->flag |= PNL_DEFAULT_CLOSED; BLI_addtail(&art->paneltypes, pt); } - -/* **************** operator to open/close properties view ************* */ - -static int sequencer_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = sequencer_has_buttons_region(sa); - - if (ar) { - ED_region_toggle_hidden(C, ar); - } - - return OPERATOR_FINISHED; -} - -void SEQUENCER_OT_properties(wmOperatorType *ot) -{ - ot->name = "Properties"; - ot->idname = "SEQUENCER_OT_properties"; - ot->description = "Toggle the properties region visibility"; - - ot->exec = sequencer_properties_toggle_exec; - ot->poll = ED_operator_sequencer_active; - - /* flags */ - ot->flag = 0; -} diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index e2140fba1f6..86bc315b994 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -62,6 +62,8 @@ #include "ED_screen.h" #include "ED_space_api.h" +#include "BIF_glutil.h" + #include "UI_interface.h" #include "UI_resources.h" #include "UI_view2d.h" @@ -280,8 +282,8 @@ static void drawseqwave(View2D *v2d, waveform = sound->waveform; if (waveform->length == 0) { - /* BKE_sound_read_waveform() set an empty SoundWaveform data in case it cannot generate a valid one... - * See T45726. */ + /* BKE_sound_read_waveform() set an empty SoundWaveform data in case it cannot generate a + * valid one. See T45726. */ return; } @@ -459,7 +461,7 @@ static void draw_seq_handle(View2D *v2d, const short direction, unsigned int pos) { - float v1[2], v2[2], v3[2], rx1 = 0, rx2 = 0; //for triangles and rect + float v1[2], v2[2], v3[2], rx1 = 0, rx2 = 0; // for triangles and rect float x1, x2, y1, y2; unsigned int whichsel = 0; @@ -815,7 +817,7 @@ static void draw_seq_strip(const bContext *C, immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); /* get the correct color per strip type*/ - //color3ubv_from_seq(scene, seq, col); + // color3ubv_from_seq(scene, seq, col); color3ubv_from_seq(scene, seq, background_col); if (seq->flag & SEQ_MUTE) { @@ -1186,7 +1188,7 @@ static void sequencer_draw_borders(const SpaceSeq *sseq, const View2D *v2d, cons void sequencer_draw_maskedit(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq) { /* NOTE: sequencer mask editing isnt finished, the draw code is working but editing not, - * for now just disable drawing since the strip frame will likely be offset */ + * for now just disable drawing since the strip frame will likely be offset */ // if (sc->mode == SC_MODE_MASKEDIT) if (0 && sseq->mainb == SEQ_DRAW_IMG_IMBUF) { @@ -1201,13 +1203,19 @@ void sequencer_draw_maskedit(const bContext *C, Scene *scene, ARegion *ar, Space width = (scene->r.size * scene->r.xsch) / 100; height = (scene->r.size * scene->r.ysch) / 100; - ED_mask_draw_region( - mask, ar, - 0, 0, 0, /* TODO */ - width, height, - aspx, aspy, - false, true, - NULL, C); + ED_mask_draw_region(mask, + ar, + 0, + 0, + 0, /* TODO */ + width, + height, + aspx, + aspy, + false, + true, + NULL, + C); } } } @@ -1220,7 +1228,7 @@ static void *sequencer_OCIO_transform_ibuf( void *cache_handle = NULL; bool force_fallback = false; *glsl_used = false; - force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL); + force_fallback |= (ED_draw_imbuf_method(ibuf) != IMAGE_DRAW_METHOD_GLSL); force_fallback |= (ibuf->dither != 0.0f); if (force_fallback) { @@ -1595,7 +1603,8 @@ void sequencer_draw_preview(const bContext *C, /* TODO */ /* sequencer_draw_maskedit(C, scene, ar, sseq); */ - /* Scope is freed in sequencer_check_scopes when ibuf changes and scope image is to be replaced. */ + /* Scope is freed in sequencer_check_scopes when ibuf changes and + * scope image is to be replaced. */ if (ibuf) { IMB_freeImBuf(ibuf); } @@ -1623,9 +1632,7 @@ void drawprefetchseqspace(Scene *scene, ARegion *UNUSED(ar), SpaceSeq *sseq) recty = (render_size * scene->r.ysch) / 100; if (sseq->mainb != SEQ_DRAW_SEQUENCE) { - give_ibuf_prefetch_request( - rectx, recty, (scene->r.cfra), sseq->chanshown, - proxy_size); + give_ibuf_prefetch_request(rectx, recty, (scene->r.cfra), sseq->chanshown, proxy_size); } } #endif @@ -1805,6 +1812,182 @@ static void seq_draw_sfra_efra(Scene *scene, View2D *v2d) GPU_blend(false); } +typedef struct CacheDrawData { + const bContext *C; + uint pos; + float stripe_offs; + float stripe_ht; +} CacheDrawData; + +/* Called as a callback */ +static bool draw_cache_view_cb( + void *userdata, struct Sequence *seq, int cfra, int cache_type, float UNUSED(cost)) +{ + CacheDrawData *drawdata = userdata; + const bContext *C = drawdata->C; + Scene *scene = CTX_data_scene(C); + ARegion *ar = CTX_wm_region(C); + struct View2D *v2d = &ar->v2d; + Editing *ed = scene->ed; + uint pos = drawdata->pos; + + if ((ed->cache_flag & SEQ_CACHE_VIEW_FINAL_OUT) == 0) { + return true; + } + + float stripe_bot, stripe_top, stripe_offs, stripe_ht; + float color[4]; + color[3] = 0.4f; + + switch (cache_type) { + case SEQ_CACHE_STORE_FINAL_OUT: + if (scene->ed->cache_flag & SEQ_CACHE_VIEW_FINAL_OUT) { + color[0] = 1.0f; + color[1] = 0.4f; + color[2] = 0.2f; + stripe_ht = UI_view2d_region_to_view_y(v2d, 4.0f * UI_DPI_FAC * U.pixelsize) - + v2d->cur.ymin; + ; + stripe_bot = UI_view2d_region_to_view_y(v2d, V2D_SCROLL_HEIGHT_TEXT); + stripe_top = stripe_bot + stripe_ht; + break; + } + else { + return false; + } + + case SEQ_CACHE_STORE_RAW: + if (scene->ed->cache_flag & SEQ_CACHE_VIEW_RAW) { + color[0] = 1.0f; + color[1] = 0.1f; + color[2] = 0.02f; + stripe_offs = drawdata->stripe_offs; + stripe_ht = drawdata->stripe_ht; + stripe_bot = seq->machine + SEQ_STRIP_OFSBOTTOM + stripe_offs; + stripe_top = stripe_bot + stripe_ht; + break; + } + else { + return false; + } + + case SEQ_CACHE_STORE_PREPROCESSED: + if (scene->ed->cache_flag & SEQ_CACHE_VIEW_PREPROCESSED) { + color[0] = 0.1f; + color[1] = 0.1f; + color[2] = 0.75f; + stripe_offs = drawdata->stripe_offs; + stripe_ht = drawdata->stripe_ht; + stripe_bot = seq->machine + SEQ_STRIP_OFSBOTTOM + (stripe_offs + stripe_ht) + stripe_offs; + stripe_top = stripe_bot + stripe_ht; + break; + } + else { + return false; + } + + case SEQ_CACHE_STORE_COMPOSITE: + if (scene->ed->cache_flag & SEQ_CACHE_VIEW_COMPOSITE) { + color[0] = 1.0f; + color[1] = 0.6f; + color[2] = 0.0f; + stripe_offs = drawdata->stripe_offs; + stripe_ht = drawdata->stripe_ht; + stripe_top = seq->machine + SEQ_STRIP_OFSTOP - stripe_offs; + stripe_bot = stripe_top - stripe_ht; + break; + } + else { + return false; + } + } + + immUniformColor4f(color[0], color[1], color[2], color[3]); + immRectf(pos, cfra, stripe_bot, cfra + 1, stripe_top); + + return false; +} + +static void draw_cache_view(const bContext *C) +{ + Scene *scene = CTX_data_scene(C); + ARegion *ar = CTX_wm_region(C); + struct View2D *v2d = &ar->v2d; + + if ((scene->ed->cache_flag & SEQ_CACHE_VIEW_ENABLE) == 0) { + return; + } + + GPU_blend(true); + uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + float stripe_bot, stripe_top, stripe_offs; + float stripe_ht = UI_view2d_region_to_view_y(v2d, 4.0f * UI_DPI_FAC * U.pixelsize) - + v2d->cur.ymin; + + if (scene->ed->cache_flag & SEQ_CACHE_VIEW_FINAL_OUT) { + stripe_bot = UI_view2d_region_to_view_y(v2d, V2D_SCROLL_HEIGHT_TEXT); + stripe_top = stripe_bot + stripe_ht; + float bg_color[4] = {1.0f, 0.4f, 0.2f, 0.1f}; + + immUniformColor4f(bg_color[0], bg_color[1], bg_color[2], bg_color[3]); + immRectf(pos, scene->r.sfra, stripe_bot, scene->r.efra, stripe_top); + } + + for (Sequence *seq = scene->ed->seqbasep->first; seq != NULL; seq = seq->next) { + if (seq->type == SEQ_TYPE_SOUND_RAM) { + continue; + } + + if (seq->startdisp > v2d->cur.xmax || seq->enddisp < v2d->cur.xmin) { + continue; + } + + CLAMP_MAX(stripe_ht, 0.2f); + stripe_offs = UI_view2d_region_to_view_y(v2d, 1.0f) - v2d->cur.ymin; + CLAMP_MIN(stripe_offs, stripe_ht / 2); + + stripe_bot = seq->machine + SEQ_STRIP_OFSBOTTOM + stripe_offs; + stripe_top = stripe_bot + stripe_ht; + + if (scene->ed->cache_flag & SEQ_CACHE_VIEW_RAW) { + float bg_color[4] = {1.0f, 0.1f, 0.02f, 0.1f}; + immUniformColor4f(bg_color[0], bg_color[1], bg_color[2], bg_color[3]); + immRectf(pos, seq->startdisp, stripe_bot, seq->enddisp, stripe_top); + } + + stripe_bot += stripe_ht + stripe_offs; + stripe_top = stripe_bot + stripe_ht; + + if (scene->ed->cache_flag & SEQ_CACHE_VIEW_PREPROCESSED) { + float bg_color[4] = {0.1f, 0.1f, 0.75f, 0.1f}; + immUniformColor4f(bg_color[0], bg_color[1], bg_color[2], bg_color[3]); + immRectf(pos, seq->startdisp, stripe_bot, seq->enddisp, stripe_top); + } + + stripe_top = seq->machine + SEQ_STRIP_OFSTOP - stripe_offs; + stripe_bot = stripe_top - stripe_ht; + + if (scene->ed->cache_flag & SEQ_CACHE_VIEW_COMPOSITE) { + float bg_color[4] = {1.0f, 0.6f, 0.0f, 0.1f}; + immUniformColor4f(bg_color[0], bg_color[1], bg_color[2], bg_color[3]); + immRectf(pos, seq->startdisp, stripe_bot, seq->enddisp, stripe_top); + } + } + + CacheDrawData userdata; + userdata.C = C; + userdata.pos = pos; + userdata.stripe_offs = stripe_offs; + userdata.stripe_ht = stripe_ht; + + BKE_sequencer_cache_iterate(scene, &userdata, draw_cache_view_cb); + + immUnbindProgram(); + GPU_blend(false); +} + /* Draw Timeline/Strip Editor Mode for Sequencer */ void draw_timeline_seq(const bContext *C, ARegion *ar) { @@ -1813,7 +1996,7 @@ void draw_timeline_seq(const bContext *C, ARegion *ar) SpaceSeq *sseq = CTX_wm_space_seq(C); View2D *v2d = &ar->v2d; View2DScrollers *scrollers; - short unit = 0, cfra_flag = 0; + short cfra_flag = 0; float col[3]; /* clear and setup matrix */ @@ -1853,6 +2036,7 @@ void draw_timeline_seq(const bContext *C, ARegion *ar) if (ed) { /* draw the data */ draw_seq_strips(C, ed, ar); + draw_cache_view(C); /* text draw cached (for sequence names), in pixelspace now */ UI_view2d_text_cache_draw(ar); @@ -1903,12 +2087,15 @@ void draw_timeline_seq(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); /* scrollers */ - unit = (sseq->flag & SEQ_DRAWFRAMES) ? V2D_UNIT_FRAMES : V2D_UNIT_SECONDS; - scrollers = UI_view2d_scrollers_calc( - C, v2d, NULL, unit, V2D_GRID_CLAMP, V2D_UNIT_VALUES, V2D_GRID_CLAMP); - UI_view2d_scrollers_draw(C, v2d, scrollers); + scrollers = UI_view2d_scrollers_calc(v2d, NULL); + UI_view2d_scrollers_draw(v2d, scrollers); UI_view2d_scrollers_free(scrollers); + /* scale numbers */ + UI_view2d_draw_scale_x__discrete_frames_or_seconds( + ar, v2d, &v2d->hor, scene, !(sseq->flag & SEQ_DRAWFRAMES)); + UI_view2d_draw_scale_y__block(ar, v2d, &v2d->vert); + /* draw current frame number-indicator on top of scrollers */ if ((sseq->flag & SEQ_NO_DRAW_CFRANUM) == 0) { UI_view2d_view_orthoSpecial(ar, v2d, 1); diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index cf07e252404..94437d4871a 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -759,8 +759,8 @@ static Sequence *cut_seq_hard(Scene *scene, Sequence *seq, ListBase *new_seq_lis /* First Strip! */ /* strips with extended stillfames before */ - /* Precaution, needed because the length saved on-disk may not match the length saved in the blend file, - * or our code may have minor differences reading file length between versions. + /* Precaution, needed because the length saved on-disk may not match the length saved in the + * blend file, or our code may have minor differences reading file length between versions. * This causes hard-cut to fail, see: T47862 */ if (seq->type != SEQ_TYPE_META) { BKE_sequence_reload_new_file(scene, seq, true); @@ -1036,22 +1036,22 @@ static void set_filter_seq(Scene *scene) Sequence *seq; Editing *ed = BKE_sequencer_editing_get(scene, false); + if (ed == NULL) + return; - if (ed == NULL) return; - - if (okee("Set Deinterlace") == 0) return; + if (okee("Set Deinterlace") == 0) + return; - SEQP_BEGIN (ed, seq) - { + SEQP_BEGIN (ed, seq) { if (seq->flag & SELECT) { if (seq->type == SEQ_TYPE_MOVIE) { seq->flag |= SEQ_FILTERY; BKE_sequence_reload_new_file(scene, seq, false); BKE_sequence_calc(scene, seq); } - } - } SEQ_END; + } + SEQ_END; } #endif @@ -1228,7 +1228,8 @@ bool sequencer_edit_poll(bContext *C) bool sequencer_strip_poll(bContext *C) { Editing *ed; - return (((ed = BKE_sequencer_editing_get(CTX_data_scene(C), false)) != NULL) && (ed->act_seq != NULL)); + return (((ed = BKE_sequencer_editing_get(CTX_data_scene(C), false)) != NULL) && + (ed->act_seq != NULL)); } #endif @@ -1547,7 +1548,9 @@ static bool sequencer_slip_recursively(Scene *scene, SlipData *data, int offset) seq->enddisp = data->ts[i].enddisp + offset; } - /* effects are only added if we they are in a metastrip. In this case, dependent strips will just be transformed and we can skip calculating for effects + /* effects are only added if we they are in a meta-strip. + * In this case, dependent strips will just be transformed and + * we can skip calculating for effects. * This way we can avoid an extra loop just for effects*/ if (!(seq->type & SEQ_TYPE_EFFECT)) { BKE_sequence_calc(scene, seq); @@ -2886,9 +2889,7 @@ static int sequencer_view_all_preview_exec(bContext *C, wmOperator *UNUSED(op)) /* Apply aspect, dosnt need to be that accurate */ imgwidth = (int)(imgwidth * (scene->r.xasp / scene->r.yasp)); - if (((imgwidth >= width) || (imgheight >= height)) && - ((width > 0) && (height > 0))) - { + if (((imgwidth >= width) || (imgheight >= height)) && ((width > 0) && (height > 0))) { /* Find the zoom value that will fit the image in the image space */ zoomX = ((float)width) / ((float)imgwidth); zoomY = ((float)height) / ((float)imgheight); @@ -2965,10 +2966,14 @@ void SEQUENCER_OT_view_zoom_ratio(wmOperatorType *ot) #if 0 static const EnumPropertyItem view_type_items[] = { - {SEQ_VIEW_SEQUENCE, "SEQUENCER", ICON_SEQ_SEQUENCER, "Sequencer", ""}, - {SEQ_VIEW_PREVIEW, "PREVIEW", ICON_SEQ_PREVIEW, "Image Preview", ""}, - {SEQ_VIEW_SEQUENCE_PREVIEW, "SEQUENCER_PREVIEW", ICON_SEQ_SEQUENCER, "Sequencer and Image Preview", ""}, - {0, NULL, 0, NULL, NULL}, + {SEQ_VIEW_SEQUENCE, "SEQUENCER", ICON_SEQ_SEQUENCER, "Sequencer", ""}, + {SEQ_VIEW_PREVIEW, "PREVIEW", ICON_SEQ_PREVIEW, "Image Preview", ""}, + {SEQ_VIEW_SEQUENCE_PREVIEW, + "SEQUENCER_PREVIEW", + ICON_SEQ_SEQUENCER, + "Sequencer and Image Preview", + ""}, + {0, NULL, 0, NULL, NULL}, }; #endif @@ -3169,7 +3174,8 @@ static Sequence *sequence_find_parent(Scene *scene, Sequence *child) Sequence *parent = NULL; Sequence *seq; - if (ed == NULL) return NULL; + if (ed == NULL) + return NULL; for (seq = ed->seqbasep->first; seq; seq = seq->next) { if ((seq != child) && seq_is_parent(seq, child)) { @@ -3885,7 +3891,7 @@ void SEQUENCER_OT_change_effect_type(struct wmOperatorType *ot) ot->prop = RNA_def_enum(ot->srna, "type", sequencer_prop_effect_types, - SEQ_TYPE_CROSS, + SEQ_TYPE_ALPHAOVER, "Type", "Sequencer effect type"); } diff --git a/source/blender/editors/space_sequencer/sequencer_intern.h b/source/blender/editors/space_sequencer/sequencer_intern.h index a051071ab61..dd04260d80e 100644 --- a/source/blender/editors/space_sequencer/sequencer_intern.h +++ b/source/blender/editors/space_sequencer/sequencer_intern.h @@ -42,9 +42,6 @@ struct bContext; struct rctf; struct wmOperator; -/* space_sequencer.c */ -struct ARegion *sequencer_has_buttons_region(struct ScrArea *sa); - /* sequencer_draw.c */ void draw_timeline_seq(const struct bContext *C, struct ARegion *ar); void sequencer_draw_preview(const struct bContext *C, @@ -94,7 +91,7 @@ int seq_effect_find_selected(struct Scene *scene, /* operator helpers */ bool sequencer_edit_poll(struct bContext *C); /* UNUSED */ -//bool sequencer_strip_poll(struct bContext *C); +// bool sequencer_strip_poll(struct bContext *C); bool sequencer_strip_has_path_poll(struct bContext *C); bool sequencer_view_preview_poll(struct bContext *C); bool sequencer_view_strips_poll(struct bContext *C); @@ -210,7 +207,6 @@ struct ImBuf *make_histogram_view_from_ibuf(struct ImBuf *ibuf); /* sequencer_buttons.c */ void sequencer_buttons_register(struct ARegionType *art); -void SEQUENCER_OT_properties(struct wmOperatorType *ot); /* sequencer_modifiers.c */ void SEQUENCER_OT_strip_modifier_add(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_sequencer/sequencer_ops.c b/source/blender/editors/space_sequencer/sequencer_ops.c index 6adca28a3fa..b0bb775de83 100644 --- a/source/blender/editors/space_sequencer/sequencer_ops.c +++ b/source/blender/editors/space_sequencer/sequencer_ops.c @@ -109,9 +109,6 @@ void sequencer_operatortypes(void) WM_operatortype_append(SEQUENCER_OT_image_strip_add); WM_operatortype_append(SEQUENCER_OT_effect_strip_add); - /* sequencer_buttons.c */ - WM_operatortype_append(SEQUENCER_OT_properties); - /* sequencer_modifiers.c */ WM_operatortype_append(SEQUENCER_OT_strip_modifier_add); WM_operatortype_append(SEQUENCER_OT_strip_modifier_remove); diff --git a/source/blender/editors/space_sequencer/sequencer_select.c b/source/blender/editors/space_sequencer/sequencer_select.c index a59a3b830e3..f40514e7574 100644 --- a/source/blender/editors/space_sequencer/sequencer_select.c +++ b/source/blender/editors/space_sequencer/sequencer_select.c @@ -60,8 +60,8 @@ static void select_surrounding_handles(Scene *scene, Sequence *test) /* XXX BRIN neighbor = find_neighboring_sequence(scene, test, SEQ_SIDE_LEFT, -1); if (neighbor) { - /* Only select neighbor handle if matching handle from test seq is also selected, or if neighbor - * was not selected at all up till now. + /* Only select neighbor handle if matching handle from test seq is also selected, + * or if neighbor was not selected at all up till now. * Otherwise, we get odd mismatch when shift-alt-rmb selecting neighbor strips... */ if (!(neighbor->flag & SELECT) || (test->flag & SEQ_LEFTSEL)) { neighbor->flag |= SEQ_RIGHTSEL; @@ -318,6 +318,7 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, const wmEvent *e Scene *scene = CTX_data_scene(C); Editing *ed = BKE_sequencer_editing_get(scene, false); const bool extend = RNA_boolean_get(op->ptr, "extend"); + const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all"); const bool linked_handle = RNA_boolean_get(op->ptr, "linked_handle"); const bool linked_time = RNA_boolean_get(op->ptr, "linked_time"); int left_right = RNA_enum_get(op->ptr, "left_right"); @@ -330,7 +331,7 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, const wmEvent *e return OPERATOR_CANCELLED; } - marker = find_nearest_marker(SCE_MARKERS, 1); //XXX - dummy function for now + marker = find_nearest_marker(SCE_MARKERS, 1); // XXX - dummy function for now seq = find_nearest_seq(scene, v2d, &hand, event->mval); @@ -401,15 +402,13 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, const wmEvent *e } } else { - // seq = find_nearest_seq(scene, v2d, &hand, mval); - act_orig = ed->act_seq; - if (extend == 0 && linked_handle == 0) { - ED_sequencer_deselect_all(scene); - } - if (seq) { + if (!extend && !linked_handle) { + ED_sequencer_deselect_all(scene); + } + BKE_sequencer_active_set(scene, seq); if ((seq->type == SEQ_TYPE_IMAGE) || (seq->type == SEQ_TYPE_MOVIE)) { @@ -427,8 +426,8 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, const wmEvent *e if (linked_handle) { if (!ELEM(hand, SEQ_SIDE_LEFT, SEQ_SIDE_RIGHT)) { /* First click selects the strip and its adjacent handles (if valid). - * Second click selects the strip, both of its handles and its adjacent handles (if valid). - */ + * Second click selects the strip, + * both of its handles and its adjacent handles (if valid). */ const bool is_striponly_selected = ((seq->flag & SEQ_ALLSEL) == SELECT); if (!extend) { @@ -535,25 +534,10 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, const wmEvent *e select_linked_time(ed->seqbasep, seq); } } - } - - /* marker transform */ -#if 0 // XXX probably need to redo this differently for 2.5 - if (marker) { - int mval[2], xo, yo; -// getmouseco_areawin(mval); - xo = mval[0]; - yo = mval[1]; - - while (get_mbut()) { -// getmouseco_areawin(mval); - if (abs(mval[0] - xo) + abs(mval[1] - yo) > 4) { - transform_markers('g', 0); - return; - } + else if (deselect_all) { + ED_sequencer_deselect_all(scene); } } -#endif WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene); @@ -584,7 +568,14 @@ void SEQUENCER_OT_select(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ + PropertyRNA *prop; RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection"); + prop = RNA_def_boolean(ot->srna, + "deselect_all", + false, + "Deselect On Nothing", + "Deselect all when nothing under the cursor"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); RNA_def_boolean( ot->srna, "linked_handle", 0, "Linked Handle", "Select handles next to the active strip"); /* for animation this is an enum but atm having an enum isn't useful for us */ diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c index 35c031e8bc8..2b0c29a02ad 100644 --- a/source/blender/editors/space_sequencer/space_sequencer.c +++ b/source/blender/editors/space_sequencer/space_sequencer.c @@ -68,34 +68,6 @@ static void sequencer_scopes_tag_refresh(ScrArea *sa) /* ******************** manage regions ********************* */ -ARegion *sequencer_has_buttons_region(ScrArea *sa) -{ - ARegion *ar, *arnew; - - ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); - if (ar) { - return ar; - } - - /* add subdiv level; after header */ - ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); - - /* is error! */ - if (ar == NULL) { - return NULL; - } - - arnew = MEM_callocN(sizeof(ARegion), "buttons for sequencer"); - - BLI_insertlinkafter(&sa->regionbase, ar, arnew); - arnew->regiontype = RGN_TYPE_UI; - arnew->alignment = RGN_ALIGN_RIGHT; - - arnew->flag = RGN_FLAG_HIDDEN; - - return arnew; -} - static ARegion *sequencer_find_region(ScrArea *sa, short type) { ARegion *ar = NULL; @@ -496,15 +468,15 @@ static void sequencer_main_region_init(wmWindowManager *wm, ARegion *ar) #if 0 keymap = WM_keymap_ensure(wm->defaultconf, "Mask Editing", 0, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); #endif keymap = WM_keymap_ensure(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "Sequencer", SPACE_SEQ, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); /* add drop boxes */ lb = WM_dropboxmap_find("Sequencer", SPACE_SEQ, RGN_TYPE_WINDOW); @@ -642,15 +614,15 @@ static void sequencer_preview_region_init(wmWindowManager *wm, ARegion *ar) #if 0 keymap = WM_keymap_ensure(wm->defaultconf, "Mask Editing", 0, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); #endif keymap = WM_keymap_ensure(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "SequencerPreview", SPACE_SEQ, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } static void sequencer_preview_region_draw(const bContext *C, ARegion *ar) @@ -723,8 +695,6 @@ static void sequencer_preview_region_listener(wmWindow *UNUSED(win), case NC_ANIMATION: switch (wmn->data) { case ND_KEYFRAME: - /* Otherwise, often prevents seeing immediately effects of keyframe editing... */ - BKE_sequencer_cache_cleanup(); ED_region_tag_redraw(ar); break; } @@ -757,7 +727,7 @@ static void sequencer_buttons_region_init(wmWindowManager *wm, ARegion *ar) wmKeyMap *keymap; keymap = WM_keymap_ensure(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); ED_region_panels_init(wm, ar); } diff --git a/source/blender/editors/space_statusbar/CMakeLists.txt b/source/blender/editors/space_statusbar/CMakeLists.txt index 39957c6792c..ad4c060a1f6 100644 --- a/source/blender/editors/space_statusbar/CMakeLists.txt +++ b/source/blender/editors/space_statusbar/CMakeLists.txt @@ -25,8 +25,8 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_text/CMakeLists.txt b/source/blender/editors/space_text/CMakeLists.txt index f5db86ac4c2..740fc9948ef 100644 --- a/source/blender/editors/space_text/CMakeLists.txt +++ b/source/blender/editors/space_text/CMakeLists.txt @@ -25,8 +25,8 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 9232d0322ab..24f282ff920 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -132,16 +132,18 @@ static void text_listener(wmWindow *UNUSED(win), /* check if active text was changed, no need to redraw if text isn't active * (reference == NULL) means text was unlinked, should update anyway for this * case -- no way to know was text active before unlinking or not */ - if (wmn->reference && wmn->reference != st->text) + if (wmn->reference && wmn->reference != st->text) { break; + } switch (wmn->data) { case ND_DISPLAY: ED_area_tag_redraw(sa); break; case ND_CURSOR: - if (st->text && st->text == wmn->reference) + if (st->text && st->text == wmn->reference) { text_scroll_to_cursor__area(st, sa, true); + } ED_area_tag_redraw(sa); break; @@ -161,16 +163,18 @@ static void text_listener(wmWindow *UNUSED(win), ED_area_tag_redraw(sa); break; case NA_SELECTED: - if (st->text && st->text == wmn->reference) + if (st->text && st->text == wmn->reference) { text_scroll_to_cursor__area(st, sa, true); + } break; } break; case NC_SPACE: - if (wmn->data == ND_SPACE_TEXT) + if (wmn->data == ND_SPACE_TEXT) { ED_area_tag_redraw(sa); + } break; } } @@ -219,8 +223,6 @@ static void text_operatortypes(void) WM_operatortype_append(TEXT_OT_line_break); WM_operatortype_append(TEXT_OT_insert); - WM_operatortype_append(TEXT_OT_properties); - WM_operatortype_append(TEXT_OT_find); WM_operatortype_append(TEXT_OT_find_set_selected); WM_operatortype_append(TEXT_OT_replace); @@ -271,9 +273,9 @@ static void text_main_region_init(wmWindowManager *wm, ARegion *ar) /* own keymap */ keymap = WM_keymap_ensure(wm->defaultconf, "Text Generic", SPACE_TEXT, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "Text", SPACE_TEXT, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); /* add drop boxes */ lb = WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW); @@ -285,7 +287,7 @@ static void text_main_region_draw(const bContext *C, ARegion *ar) { /* draw entirely, view changes should be handled here */ SpaceText *st = CTX_wm_space_text(C); - //View2D *v2d = &ar->v2d; + // View2D *v2d = &ar->v2d; /* clear and setup matrix */ UI_ThemeClearColor(TH_BACK); @@ -392,7 +394,7 @@ static void text_properties_region_init(wmWindowManager *wm, ARegion *ar) /* own keymaps */ keymap = WM_keymap_ensure(wm->defaultconf, "Text Generic", SPACE_TEXT, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); } static void text_properties_region_draw(const bContext *C, ARegion *ar) diff --git a/source/blender/editors/space_text/text_autocomplete.c b/source/blender/editors/space_text/text_autocomplete.c index 10303aeba7c..243642b2e8c 100644 --- a/source/blender/editors/space_text/text_autocomplete.c +++ b/source/blender/editors/space_text/text_autocomplete.c @@ -56,24 +56,29 @@ int text_do_suggest_select(SpaceText *st, ARegion *ar) int tgti, *top; int mval[2] = {0, 0}; - if (!st || !st->text) + if (!st || !st->text) { return 0; - if (!texttool_text_is_active(st->text)) + } + if (!texttool_text_is_active(st->text)) { return 0; + } first = texttool_suggest_first(); last = texttool_suggest_last(); /* sel = texttool_suggest_selected(); */ /* UNUSED */ top = texttool_suggest_top(); - if (!last || !first) + if (!last || !first) { return 0; + } /* Count the visible lines to the cursor */ - for (tmp = st->text->curl, l = -st->top; tmp; tmp = tmp->prev, l++) + for (tmp = st->text->curl, l = -st->top; tmp; tmp = tmp->prev, l++) { ; - if (l < 0) + } + if (l < 0) { return 0; + } text_update_character_width(st); @@ -90,22 +95,27 @@ int text_do_suggest_select(SpaceText *st, ARegion *ar) // XXX getmouseco_areawin(mval); - if (mval[0] < x || x + w < mval[0] || mval[1] < y - h || y < mval[1]) + if (mval[0] < x || x + w < mval[0] || mval[1] < y - h || y < mval[1]) { return 0; + } /* Work out which of the items is at the top of the visible list */ - for (i = 0, item = first; i < *top && item->next; i++, item = item->next) + for (i = 0, item = first; i < *top && item->next; i++, item = item->next) { ; + } /* Work out the target item index in the visible list */ tgti = (y - mval[1] - 4) / st->lheight_dpi; - if (tgti < 0 || tgti > SUGG_LIST_SIZE) + if (tgti < 0 || tgti > SUGG_LIST_SIZE) { return 1; + } - for (i = tgti; i > 0 && item->next; i--, item = item->next) + for (i = tgti; i > 0 && item->next; i--, item = item->next) { ; - if (item) + } + if (item) { texttool_suggest_select(item); + } return 1; } @@ -123,10 +133,12 @@ void text_pop_suggest_list(void) item = item->next; i++; } - if (i > *top + SUGG_LIST_SIZE - 1) + if (i > *top + SUGG_LIST_SIZE - 1) { *top = i - SUGG_LIST_SIZE + 1; - else if (i < *top) + } + else if (i < *top) { *top = i; + } } /* -------------------------------------------------------------------- */ @@ -179,8 +191,8 @@ static GHash *text_autocomplete_build(Text *text) } if ((i_start != i_end) && - /* check we're at the beginning of a line or that the previous char is not an identifier - * this prevents digits from being added */ + /* Check we're at the beginning of a line or that the previous char is not an + * identifier this prevents digits from being added. */ ((i_start < 1) || !text_check_identifier_unicode(BLI_str_utf8_as_unicode(&linep->line[i_start - 1])))) { char *str_sub = &linep->line[i_start]; @@ -235,10 +247,12 @@ static void get_suggest_prefix(Text *text, int offset) int i, len; const char *line; - if (!text) + if (!text) { return; - if (!texttool_text_is_active(text)) + } + if (!texttool_text_is_active(text)) { return; + } line = text->curl->line; i = text_find_identifier_start(line, text->curc + offset); @@ -252,14 +266,17 @@ static void confirm_suggestion(Text *text, TextUndoBuf *utxt) int i, over = 0; const char *line; - if (!text) + if (!text) { return; - if (!texttool_text_is_active(text)) + } + if (!texttool_text_is_active(text)) { return; + } sel = texttool_suggest_selected(); - if (!sel) + if (!sel) { return; + } line = text->curl->line; i = text_find_identifier_start(line, text->curc /* - skipleft */); @@ -324,17 +341,20 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e (void)text; if (st->doplugins && texttool_text_is_active(st->text)) { - if (texttool_suggest_first()) + if (texttool_suggest_first()) { tools |= TOOL_SUGG_LIST; - if (texttool_docs_get()) + } + if (texttool_docs_get()) { tools |= TOOL_DOCUMENT; + } } switch (event->type) { case LEFTMOUSE: if (event->val == KM_PRESS) { - if (text_do_suggest_select(st, ar)) + if (text_do_suggest_select(st, ar)) { swallow = 1; + } else { if (tools & TOOL_SUGG_LIST) { texttool_suggest_clear(); @@ -380,8 +400,9 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e texttool_docs_clear(); doc_scroll = 0; } - else + else { draw = swallow = 0; + } retval = OPERATOR_CANCELLED; } break; @@ -510,8 +531,9 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e case UPARROWKEY: if (event->val == KM_PRESS) { if (tools & TOOL_DOCUMENT) { - if (doc_scroll > 0) + if (doc_scroll > 0) { doc_scroll--; + } swallow = 1; draw = 1; } diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index dadb86f439b..cdd691fe879 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -107,7 +107,8 @@ static void txt_format_text(SpaceText *st) { TextLine *linep; - if (!st->text) return; + if (!st->text) + return; for (linep = st->text->lines.first; linep; linep = linep->next) txt_format_line(st, linep, 0); @@ -203,10 +204,12 @@ void wrap_offset( *offl = *offc = 0; - if (!st->text) + if (!st->text) { return; - if (!st->wordwrap) + } + if (!st->wordwrap) { return; + } text = st->text; @@ -218,9 +221,10 @@ void wrap_offset( /* Line before top */ if (linep == linein) { - if (lines <= i) + if (lines <= i) { /* no visible part of line */ return; + } } if (i - lines < 0) { @@ -249,8 +253,9 @@ void wrap_offset( ch = linep->line[j]; if (ch == '\t') { chars = st->tabnumber - i % st->tabnumber; - if (linep == linein && i < cursin) + if (linep == linein && i < cursin) { cursin += chars - 1; + } ch = ' '; } else { @@ -280,14 +285,16 @@ void wrap_offset( else if (ch == ' ' || ch == '-') { end = i + 1; chop = 0; - if (linep == linein && i >= cursin) + if (linep == linein && i >= cursin) { return; + } } i += columns; } } - if (linep == linein) + if (linep == linein) { break; + } linep = linep->next; } } @@ -301,10 +308,12 @@ void wrap_offset_in_line( *offl = *offc = 0; - if (!st->text) + if (!st->text) { return; - if (!st->wordwrap) + } + if (!st->wordwrap) { return; + } max = wrap_width(st, ar); @@ -321,12 +330,14 @@ void wrap_offset_in_line( ch = linein->line[j]; if (ch == '\t') { chars = st->tabnumber - i % st->tabnumber; - if (i < cursin) + if (i < cursin) { cursin += chars - 1; + } ch = ' '; } - else + else { chars = 1; + } while (chars--) { if (i + columns - start > max) { @@ -351,8 +362,9 @@ void wrap_offset_in_line( else if (ch == ' ' || ch == '-') { end = i + 1; chop = 0; - if (i >= cursin) + if (i >= cursin) { return; + } } i += columns; } @@ -364,10 +376,12 @@ int text_get_char_pos(const SpaceText *st, const char *line, int cur) int a = 0, i; for (i = 0; i < cur && line[i]; i += BLI_str_utf8_size_safe(line + i)) { - if (line[i] == '\t') + if (line[i] == '\t') { a += st->tabnumber - a % st->tabnumber; - else + } + else { a += BLI_str_utf8_char_width_safe(line + i); + } } return a; } @@ -378,15 +392,18 @@ static const char *txt_utf8_forward_columns(const char *str, int columns, int *p const char *p = str; while (*p) { col = BLI_str_utf8_char_width(p); - if (columns - col < 0) + if (columns - col < 0) { break; + } columns -= col; p += BLI_str_utf8_size_safe(p); - if (columns == 0) + if (columns == 0) { break; + } } - if (padding) + if (padding) { *padding = *p ? columns : 0; + } return p; } @@ -413,8 +430,9 @@ static int text_draw_wrapped(const SpaceText *st, flatten_string(st, &fs, str); str = fs.buf; max = w / st->cwidth; - if (max < 8) + if (max < 8) { max = 8; + } basex = x; lines = 1; @@ -443,8 +461,9 @@ static int text_draw_wrapped(const SpaceText *st, /* Draw the visible portion of text on the overshot line */ for (a = fstart, ma = mstart; ma < mend; a++, ma += BLI_str_utf8_size_safe(str + ma)) { if (use_syntax) { - if (fmt_prev != format[a]) + if (fmt_prev != format[a]) { format_draw_color(tdc, fmt_prev = format[a]); + } } x += text_font_draw_character_utf8(tdc, x, y, str + ma); fpos++; @@ -457,8 +476,9 @@ static int text_draw_wrapped(const SpaceText *st, mend = txt_utf8_forward_columns(str + mend, max, &padding) - str; end = (wrap += max - padding); - if (y <= clip_min_y) + if (y <= clip_min_y) { break; + } } else if (str[mi] == ' ' || str[mi] == '-') { wrap = i + 1; @@ -470,8 +490,9 @@ static int text_draw_wrapped(const SpaceText *st, for (a = fstart, ma = mstart; str[ma] && y > clip_min_y; a++, ma += BLI_str_utf8_size_safe(str + ma)) { if (use_syntax) { - if (fmt_prev != format[a]) + if (fmt_prev != format[a]) { format_draw_color(tdc, fmt_prev = format[a]); + } } x += text_font_draw_character_utf8(tdc, x, y, str + ma); @@ -505,12 +526,14 @@ static void text_draw(const SpaceText *st, padding = w - cshift; in = str; } - else if (format) + else if (format) { format++; + } } if (in) { - if (maxwidth && w + columns > cshift + maxwidth) + if (maxwidth && w + columns > cshift + maxwidth) { break; + } amount++; } @@ -529,8 +552,9 @@ static void text_draw(const SpaceText *st, char fmt_prev = 0xff; for (a = 0; a < amount; a++) { - if (format[a] != fmt_prev) + if (format[a] != fmt_prev) { format_draw_color(tdc, fmt_prev = format[a]); + } x += text_font_draw_character_utf8(tdc, x, y, in + str_shift); str_shift += BLI_str_utf8_size_safe(in + str_shift); } @@ -576,8 +600,9 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar) int full_update = 0, nlines = 0; Text *txt = st->text; - if (!st->drawcache) + if (!st->drawcache) { text_drawcache_init(st); + } text_update_character_width(st); @@ -617,10 +642,12 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar) nlines = BLI_listbase_count(&txt->lines); size = sizeof(int) * nlines; - if (fp) + if (fp) { fp = MEM_reallocN(fp, size); - else + } + else { fp = MEM_callocN(size, "text drawcache line_height"); + } drawcache->valid_tail = drawcache->valid_head = 0; old_tail = fp + drawcache->nlines - drawcache->valid_tail; @@ -629,8 +656,9 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar) drawcache->total_lines = 0; - if (st->showlinenrs) + if (st->showlinenrs) { st->linenrs_tot = integer_digits_i(nlines); + } while (line) { if (drawcache->valid_head) { /* we're inside valid head lines */ @@ -663,8 +691,9 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar) if (full_update || drawcache->update_flag) { nlines = BLI_listbase_count(&txt->lines); - if (st->showlinenrs) + if (st->showlinenrs) { st->linenrs_tot = integer_digits_i(nlines); + } } drawcache->total_lines = nlines; @@ -691,8 +720,9 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar) void text_drawcache_tag_update(SpaceText *st, int full) { /* this happens if text editor ops are caled from python */ - if (st == NULL) + if (st == NULL) { return; + } if (st->drawcache) { DrawCache *drawcache = (DrawCache *)st->drawcache; @@ -720,10 +750,12 @@ void text_drawcache_tag_update(SpaceText *st, int full) /* quick cache recalculation is also used in delete operator, * which could merge lines which are adjacent to current selection lines * expand recalculate area to this lines */ - if (drawcache->valid_head > 0) + if (drawcache->valid_head > 0) { drawcache->valid_head--; - if (drawcache->valid_tail > 0) + } + if (drawcache->valid_tail > 0) { drawcache->valid_tail--; + } } else { drawcache->valid_head = 0; @@ -739,8 +771,9 @@ void text_free_caches(SpaceText *st) DrawCache *drawcache = (DrawCache *)st->drawcache; if (drawcache) { - if (drawcache->line_height) + if (drawcache->line_height) { MEM_freeN(drawcache->line_height); + } MEM_freeN(drawcache); } @@ -803,8 +836,9 @@ int text_get_span_wrap(const SpaceText *st, ARegion *ar, TextLine *from, TextLin /* Look forwards */ while (tmp) { - if (tmp == to) + if (tmp == to) { return ret; + } ret += text_get_visible_lines(st, ar, tmp->line); tmp = tmp->next; } @@ -875,8 +909,9 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back) CLAMP(st->txtbar.ymax, pix_bottom_margin, ar->winy - pix_top_margin); st->pix_per_line = (pix_available > 0) ? (float)ltexth / pix_available : 0; - if (st->pix_per_line < 0.1f) + if (st->pix_per_line < 0.1f) { st->pix_per_line = 0.1f; + } curl_off = text_get_span_wrap(st, ar, st->text->lines.first, st->text->curl); sell_off = text_get_span_wrap(st, ar, st->text->lines.first, st->text->sell); @@ -989,18 +1024,23 @@ static void draw_documentation(const SpaceText *st, ARegion *ar) int i, br, lines; int boxw, boxh, l, x, y /* , top */ /* UNUSED */; - if (!st || !st->text) return; - if (!texttool_text_is_active(st->text)) return; + if (!st || !st->text) + return; + if (!texttool_text_is_active(st->text)) + return; docs = texttool_docs_get(); - if (!docs) return; + if (!docs) + return; text_draw_context_init(st, &tdc); /* Count the visible lines to the cursor */ - for (tmp = st->text->curl, l = -st->top; tmp; tmp = tmp->prev, l++) ; - if (l < 0) return; + for (tmp = st->text->curl, l = -st->top; tmp; tmp = tmp->prev, l++) + ; + if (l < 0) + return; if (st->showlinenrs) { x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET + TEXTXLOC - 4; @@ -1017,7 +1057,8 @@ static void draw_documentation(const SpaceText *st, ARegion *ar) boxh = (DOC_HEIGHT + 1) * (st->lheight_dpi + TXT_LINE_SPACING); /* Draw panel */ - uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); + uint pos = GPU_vertformat_attr_add( + immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); immUniformThemeColor(TH_BACK); @@ -1044,9 +1085,12 @@ static void draw_documentation(const SpaceText *st, ARegion *ar) UI_FontThemeColor(tdc.font_id, TH_TEXT); - i = 0; br = DOC_WIDTH; lines = 0; // XXX -doc_scroll; + i = 0; + br = DOC_WIDTH; + lines = 0; // XXX -doc_scroll; for (p = docs; *p; p++) { - if (*p == '\r' && *(++p) != '\n') *(--p) = '\n'; /* Fix line endings */ + if (*p == '\r' && *(++p) != '\n') + *(--p) = '\n'; /* Fix line endings */ if (*p == ' ' || *p == '\t') br = i; else if (*p == '\n') { @@ -1055,7 +1099,9 @@ static void draw_documentation(const SpaceText *st, ARegion *ar) y -= st->lheight_dpi; text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, NULL); } - i = 0; br = DOC_WIDTH; lines++; + i = 0; + br = DOC_WIDTH; + lines++; } buf[i++] = *p; if (i == DOC_WIDTH) { /* Reached the width, go to last break and wrap there */ @@ -1065,9 +1111,12 @@ static void draw_documentation(const SpaceText *st, ARegion *ar) text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, NULL); } p -= i - br - 1; /* Rewind pointer to last break */ - i = 0; br = DOC_WIDTH; lines++; + i = 0; + br = DOC_WIDTH; + lines++; } - if (lines >= DOC_HEIGHT) break; + if (lines >= DOC_HEIGHT) + break; } } #endif @@ -1083,16 +1132,19 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc const int lheight = st->lheight_dpi + TXT_LINE_SPACING; const int margin_x = 2; - if (!st->text) + if (!st->text) { return; - if (!texttool_text_is_active(st->text)) + } + if (!texttool_text_is_active(st->text)) { return; + } first = texttool_suggest_first(); last = texttool_suggest_last(); - if (!first || !last) + if (!first || !last) { return; + } text_pop_suggest_list(); sel = texttool_suggest_selected(); @@ -1114,8 +1166,9 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc boxw = SUGG_LIST_WIDTH * st->cwidth + 20; boxh = SUGG_LIST_SIZE * lheight + 8; - if (x + boxw > ar->winx) + if (x + boxw > ar->winx) { x = MAX2(0, ar->winx - boxw); + } /* not needed but stands out nicer */ UI_draw_box_shadow(220, x, y - boxh, x + boxw, y); @@ -1132,8 +1185,9 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc immUnbindProgram(); /* Set the top 'item' of the visible list */ - for (i = 0, item = first; i < *top && item->next; i++, item = item->next) + for (i = 0, item = first; i < *top && item->next; i++, item = item->next) { ; + } for (i = 0; i < SUGG_LIST_SIZE && item; i++, item = item->next) { int len = txt_utf8_forward_columns(item->name, SUGG_LIST_WIDTH, NULL) - item->name; @@ -1158,8 +1212,9 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc format_draw_color(tdc, item->type); text_draw(st, tdc, str, 0, 0, x + margin_x, y - 1, NULL); - if (item == last) + if (item == last) { break; + } } } @@ -1292,8 +1347,9 @@ static void draw_text_decoration(SpaceText *st, ARegion *ar) y += TXT_LINE_SPACING; w = st->cwidth; - if (ch == '\t') + if (ch == '\t') { w *= st->tabnumber - (vselc + st->left) % st->tabnumber; + } immRecti(pos, x, y - lheight - 1, x + w, y - lheight + 1); } @@ -1317,16 +1373,19 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi char ch; // showsyntax must be on or else the format string will be null - if (!text->curl || !st->showsyntax) + if (!text->curl || !st->showsyntax) { return; + } startl = text->curl; startc = text->curc; b = text_check_bracket(startl->line[startc]); - if (b == 0 && startc > 0) + if (b == 0 && startc > 0) { b = text_check_bracket(startl->line[--startc]); - if (b == 0) + } + if (b == 0) { return; + } linep = startl; c = startc; @@ -1338,8 +1397,9 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi /* Don't highlight backets if syntax HL is off or bracket in string or comment. */ if (!linep->format || linep->format[fc] == FMT_TYPE_STRING || - linep->format[fc] == FMT_TYPE_COMMENT) + linep->format[fc] == FMT_TYPE_COMMENT) { return; + } if (b > 0) { /* opening bracket, search forward for close */ @@ -1365,8 +1425,9 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi fc++; c += BLI_str_utf8_size_safe(linep->line + c); } - if (endl) + if (endl) { break; + } linep = linep->next; c = 0; fc = 0; @@ -1375,8 +1436,9 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi else { /* closing bracket, search backward for open */ fc--; - if (c > 0) + if (c > 0) { c -= linep->line + c - BLI_str_prev_char_utf8(linep->line + c); + } while (linep) { while (fc >= 0) { if (linep->format && linep->format[fc] != FMT_TYPE_STRING && @@ -1395,27 +1457,34 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi } } fc--; - if (c > 0) + if (c > 0) { c -= linep->line + c - BLI_str_prev_char_utf8(linep->line + c); + } } - if (endl) + if (endl) { break; + } linep = linep->prev; if (linep) { - if (linep->format) + if (linep->format) { fc = strlen(linep->format) - 1; - else + } + else { fc = -1; - if (linep->len) + } + if (linep->len) { c = BLI_str_prev_char_utf8(linep->line + linep->len) - linep->line; - else + } + else { fc = -1; + } } } } - if (!endl || endc == -1) + if (!endl || endc == -1) { return; + } UI_FontThemeColor(tdc->font_id, TH_HILITE); x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET; @@ -1465,8 +1534,9 @@ void draw_text_main(SpaceText *st, ARegion *ar) int margin_column_x; /* if no text, nothing to do */ - if (!text) + if (!text) { return; + } /* dpi controlled line height and font size */ st->lheight_dpi = (U.widget_unit * st->lheight) / 20; @@ -1483,8 +1553,9 @@ void draw_text_main(SpaceText *st, ARegion *ar) text_update_drawcache(st, ar); /* make sure all the positional pointers exist */ - if (!text->curl || !text->sell || !text->lines.first || !text->lines.last) + if (!text->curl || !text->sell || !text->lines.first || !text->lines.last) { txt_clean_text(text); + } /* update rects for scroll */ calc_text_rcts(st, ar, &scroll, &back); /* scroll will hold the entire bar size */ @@ -1494,8 +1565,9 @@ void draw_text_main(SpaceText *st, ARegion *ar) tmp = text->lines.first; lineno = 0; for (i = 0; i < st->top && tmp; i++) { - if (st->showsyntax && !tmp->format) + if (st->showsyntax && !tmp->format) { tft->format_line(st, tmp, false); + } if (st->wordwrap) { int lines = text_get_visible_lines_no(st, lineno); @@ -1548,8 +1620,9 @@ void draw_text_main(SpaceText *st, ARegion *ar) UI_FontThemeColor(tdc.font_id, TH_TEXT); for (i = 0; y > clip_min_y && i < st->viewlines && tmp; i++, tmp = tmp->next) { - if (st->showsyntax && !tmp->format) + if (st->showsyntax && !tmp->format) { tft->format_line(st, tmp, false); + } if (st->showlinenrs && !wrap_skip) { /* draw line number */ @@ -1639,8 +1712,9 @@ void text_scroll_to_cursor(SpaceText *st, ARegion *ar, const bool center) Text *text; int i, x, winx = ar->winx; - if (ELEM(NULL, st, st->text, st->text->curl)) + if (ELEM(NULL, st, st->text, st->text->curl)) { return; + } text = st->text; @@ -1689,10 +1763,12 @@ void text_scroll_to_cursor(SpaceText *st, ARegion *ar, const bool center) } } - if (st->top < 0) + if (st->top < 0) { st->top = 0; - if (st->left < 0) + } + if (st->left < 0) { st->left = 0; + } st->scroll_accum[0] = 0.0f; st->scroll_accum[1] = 0.0f; @@ -1703,8 +1779,9 @@ void text_scroll_to_cursor__area(SpaceText *st, ScrArea *sa, const bool center) { ARegion *ar; - if (ELEM(NULL, st, st->text, st->text->curl)) + if (ELEM(NULL, st, st->text, st->text->curl)) { return; + } ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); diff --git a/source/blender/editors/space_text/text_format.c b/source/blender/editors/space_text/text_format.c index 0a885fc5875..8c102dc009e 100644 --- a/source/blender/editors/space_text/text_format.c +++ b/source/blender/editors/space_text/text_format.c @@ -79,8 +79,9 @@ int flatten_string(const SpaceText *st, FlattenString *fs, const char *in) i = st->tabnumber - (total % st->tabnumber); total += i; - while (i--) + while (i--) { flatten_string_append(fs, " ", r, 1); + } in++; } @@ -99,10 +100,12 @@ int flatten_string(const SpaceText *st, FlattenString *fs, const char *in) void flatten_string_free(FlattenString *fs) { - if (fs->buf != fs->fixedbuf) + if (fs->buf != fs->fixedbuf) { MEM_freeN(fs->buf); - if (fs->accum != fs->fixedaccum) + } + if (fs->accum != fs->fixedaccum) { MEM_freeN(fs->accum); + } } /* takes a string within fs->buf and returns its length */ @@ -121,14 +124,16 @@ int text_check_format_len(TextLine *line, unsigned int len) if (strlen(line->format) < len) { MEM_freeN(line->format); line->format = MEM_mallocN(len + 2, "SyntaxFormat"); - if (!line->format) + if (!line->format) { return 0; + } } } else { line->format = MEM_mallocN(len + 2, "SyntaxFormat"); - if (!line->format) + if (!line->format) { return 0; + } } return 1; diff --git a/source/blender/editors/space_text/text_format_lua.c b/source/blender/editors/space_text/text_format_lua.c index b82e8aec122..347d46a4234 100644 --- a/source/blender/editors/space_text/text_format_lua.c +++ b/source/blender/editors/space_text/text_format_lua.c @@ -48,31 +48,33 @@ static int txtfmt_lua_find_keyword(const char *string) /* Keep aligned args for readability. */ /* clang-format off */ - if (STR_LITERAL_STARTSWITH(string, "and", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "break", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "do", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "else", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "elseif", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "end", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "for", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "function", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "if", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "in", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "local", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "not", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "or", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "repeat", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "return", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "then", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "until", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "while", len)) i = len; - else i = 0; + if (STR_LITERAL_STARTSWITH(string, "and", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "break", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "do", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "else", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "elseif", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "end", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "for", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "function", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "if", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "in", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "local", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "not", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "or", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "repeat", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "return", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "then", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "until", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "while", len)) { i = len; + } else { i = 0; +} /* clang-format on */ /* If next source char is an identifier (eg. 'i' in "definite") no match */ - if (i == 0 || text_check_identifier(string[i])) + if (i == 0 || text_check_identifier(string[i])) { return -1; + } return i; } @@ -94,41 +96,43 @@ static int txtfmt_lua_find_specialvar(const char *string) /* Keep aligned args for readability. */ /* clang-format off */ - if (STR_LITERAL_STARTSWITH(string, "assert", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "collectgarbage", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "dofile", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "error", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "_G", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "getfenv", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "getmetatable", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "__index", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ipairs", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "load", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "loadfile", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "loadstring", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "next", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pairs", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pcall", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "print", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "rawequal", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "rawget", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "rawset", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "select", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "setfenv", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "setmetatable", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tonumber", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tostring", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "type", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "unpack", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "_VERSION", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "xpcall", len)) i = len; - else i = 0; + if (STR_LITERAL_STARTSWITH(string, "assert", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "collectgarbage", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "dofile", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "error", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "_G", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "getfenv", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "getmetatable", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "__index", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ipairs", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "load", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "loadfile", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "loadstring", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "next", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pairs", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pcall", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "print", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "rawequal", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "rawget", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "rawset", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "select", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "setfenv", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "setmetatable", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tonumber", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tostring", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "type", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "unpack", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "_VERSION", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "xpcall", len)) { i = len; + } else { i = 0; +} /* clang-format on */ /* If next source char is an identifier (eg. 'i' in "definite") no match */ - if (i == 0 || text_check_identifier(string[i])) + if (i == 0 || text_check_identifier(string[i])) { return -1; + } return i; } @@ -136,20 +140,25 @@ static int txtfmt_lua_find_bool(const char *string) { int i, len; - if (STR_LITERAL_STARTSWITH(string, "nil", len)) + if (STR_LITERAL_STARTSWITH(string, "nil", len)) { i = len; - else if (STR_LITERAL_STARTSWITH(string, "true", len)) + } + else if (STR_LITERAL_STARTSWITH(string, "true", len)) { i = len; - else if (STR_LITERAL_STARTSWITH(string, "false", len)) + } + else if (STR_LITERAL_STARTSWITH(string, "false", len)) { i = len; - else + } + else { i = 0; + } /* clang-format on */ /* If next source char is an identifier (eg. 'i' in "Nonetheless") no match */ - if (i == 0 || text_check_identifier(string[i])) + if (i == 0 || text_check_identifier(string[i])) { return -1; + } return i; } @@ -160,9 +169,10 @@ static char txtfmt_lua_format_identifier(const char *str) /* Keep aligned args for readability. */ /* clang-format off */ - if ((txtfmt_lua_find_specialvar(str)) != -1) fmt = FMT_TYPE_SPECIAL; - else if ((txtfmt_lua_find_keyword(str)) != -1) fmt = FMT_TYPE_KEYWORD; - else fmt = FMT_TYPE_DEFAULT; + if ((txtfmt_lua_find_specialvar(str)) != -1) { fmt = FMT_TYPE_SPECIAL; + } else if ((txtfmt_lua_find_keyword(str)) != -1) { fmt = FMT_TYPE_KEYWORD; + } else { fmt = FMT_TYPE_DEFAULT; +} /* clang-format on */ @@ -211,8 +221,9 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_ *fmt = prev; fmt++; str++; - if (*str == '\0') + if (*str == '\0') { break; + } *fmt = prev; fmt++; str += BLI_str_utf8_size_safe(str); @@ -236,8 +247,9 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_ } else { find = (cont & FMT_CONT_QUOTEDOUBLE) ? '"' : '\''; - if (*str == find) + if (*str == find) { cont = 0; + } *fmt = FMT_TYPE_STRING; } @@ -304,8 +316,9 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_ /* Special vars(v) or built-in keywords(b) */ /* keep in sync with 'txtfmt_osl_format_identifier()' */ - if ((i = txtfmt_lua_find_specialvar(str)) != -1) prev = FMT_TYPE_SPECIAL; - else if ((i = txtfmt_lua_find_keyword(str)) != -1) prev = FMT_TYPE_KEYWORD; + if ((i = txtfmt_lua_find_specialvar(str)) != -1) { prev = FMT_TYPE_SPECIAL; + } else if ((i = txtfmt_lua_find_keyword(str)) != -1) { prev = FMT_TYPE_KEYWORD; +} /* clang-format on */ diff --git a/source/blender/editors/space_text/text_format_osl.c b/source/blender/editors/space_text/text_format_osl.c index 8473b3f80ce..fb9ddcb09cb 100644 --- a/source/blender/editors/space_text/text_format_osl.c +++ b/source/blender/editors/space_text/text_format_osl.c @@ -40,37 +40,39 @@ static int txtfmt_osl_find_builtinfunc(const char *string) /* list is from * https://github.com/imageworks/OpenShadingLanguage/raw/master/src/doc/osl-languagespec.pdf */ - if (STR_LITERAL_STARTSWITH(string, "break", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "closure", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "color", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "continue", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "do", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "else", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "emit", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "float", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "for", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "if", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "illuminance", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "illuminate", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "int", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "matrix", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "normal", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "output", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "point", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "public", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "return", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "string", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "struct", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "vector", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "void", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "while", len)) i = len; - else i = 0; + if (STR_LITERAL_STARTSWITH(string, "break", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "closure", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "color", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "continue", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "do", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "else", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "emit", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "float", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "for", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "if", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "illuminance", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "illuminate", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "int", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "matrix", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "normal", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "output", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "point", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "public", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "return", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "string", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "struct", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "vector", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "void", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "while", len)) { i = len; + } else { i = 0; +} /* clang-format on */ /* If next source char is an identifier (eg. 'i' in "definite") no match */ - if (i == 0 || text_check_identifier(string[i])) + if (i == 0 || text_check_identifier(string[i])) { return -1; + } return i; } @@ -84,49 +86,51 @@ static int txtfmt_osl_find_reserved(const char *string) /* list is from... * https://github.com/imageworks/OpenShadingLanguage/raw/master/src/doc/osl-languagespec.pdf */ - if (STR_LITERAL_STARTSWITH(string, "bool", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "case", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "catch", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "char", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "const", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "delete", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "default", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "double", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "enum", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "extern", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "false", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "friend", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "goto", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "inline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "long", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "new", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "operator", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "private", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "protected", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "short", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "signed", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sizeof", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "static", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "switch", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "template", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "this", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "throw", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "true", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "try", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "typedef", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "uniform", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "union", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "unsigned", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "varying", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "virtual", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "volatile", len)) i = len; - else i = 0; + if (STR_LITERAL_STARTSWITH(string, "bool", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "case", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "catch", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "char", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "const", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "delete", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "default", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "double", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "enum", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "extern", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "false", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "friend", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "goto", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "inline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "long", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "new", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "operator", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "private", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "protected", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "short", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "signed", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sizeof", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "static", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "switch", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "template", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "this", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "throw", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "true", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "try", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "typedef", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "uniform", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "union", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "unsigned", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "varying", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "virtual", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "volatile", len)) { i = len; + } else { i = 0; +} /* clang-format on */ /* If next source char is an identifier (eg. 'i' in "definite") no match */ - if (i == 0 || text_check_identifier(string[i])) + if (i == 0 || text_check_identifier(string[i])) { return -1; + } return i; } @@ -145,17 +149,19 @@ static int txtfmt_osl_find_specialvar(const char *string) /* clang-format off */ /* OSL shader types */ - if (STR_LITERAL_STARTSWITH(string, "shader", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "surface", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "volume", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "displacement", len)) i = len; - else i = 0; + if (STR_LITERAL_STARTSWITH(string, "shader", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "surface", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "volume", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "displacement", len)) { i = len; + } else { i = 0; +} /* clang-format on */ /* If next source char is an identifier (eg. 'i' in "definite") no match */ - if (i == 0 || text_check_identifier(string[i])) + if (i == 0 || text_check_identifier(string[i])) { return -1; + } return i; } @@ -183,11 +189,12 @@ static char txtfmt_osl_format_identifier(const char *str) /* Keep aligned args for readability. */ /* clang-format off */ - if ((txtfmt_osl_find_specialvar(str)) != -1) fmt = FMT_TYPE_SPECIAL; - else if ((txtfmt_osl_find_builtinfunc(str)) != -1) fmt = FMT_TYPE_KEYWORD; - else if ((txtfmt_osl_find_reserved(str)) != -1) fmt = FMT_TYPE_RESERVED; - else if ((txtfmt_osl_find_preprocessor(str)) != -1) fmt = FMT_TYPE_DIRECTIVE; - else fmt = FMT_TYPE_DEFAULT; + if ((txtfmt_osl_find_specialvar(str)) != -1) { fmt = FMT_TYPE_SPECIAL; + } else if ((txtfmt_osl_find_builtinfunc(str)) != -1) { fmt = FMT_TYPE_KEYWORD; + } else if ((txtfmt_osl_find_reserved(str)) != -1) { fmt = FMT_TYPE_RESERVED; + } else if ((txtfmt_osl_find_preprocessor(str)) != -1) { fmt = FMT_TYPE_DIRECTIVE; + } else { fmt = FMT_TYPE_DEFAULT; +} /* clang-format on */ @@ -236,8 +243,9 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_ *fmt = prev; fmt++; str++; - if (*str == '\0') + if (*str == '\0') { break; + } *fmt = prev; fmt++; str += BLI_str_utf8_size_safe(str); @@ -261,8 +269,9 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_ } else { find = (cont & FMT_CONT_QUOTEDOUBLE) ? '"' : '\''; - if (*str == find) + if (*str == find) { cont = 0; + } *fmt = FMT_TYPE_STRING; } @@ -314,10 +323,11 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_ /* Special vars(v) or built-in keywords(b) */ /* keep in sync with 'txtfmt_osl_format_identifier()' */ - if ((i = txtfmt_osl_find_specialvar(str)) != -1) prev = FMT_TYPE_SPECIAL; - else if ((i = txtfmt_osl_find_builtinfunc(str)) != -1) prev = FMT_TYPE_KEYWORD; - else if ((i = txtfmt_osl_find_reserved(str)) != -1) prev = FMT_TYPE_RESERVED; - else if ((i = txtfmt_osl_find_preprocessor(str)) != -1) prev = FMT_TYPE_DIRECTIVE; + if ((i = txtfmt_osl_find_specialvar(str)) != -1) { prev = FMT_TYPE_SPECIAL; + } else if ((i = txtfmt_osl_find_builtinfunc(str)) != -1) { prev = FMT_TYPE_KEYWORD; + } else if ((i = txtfmt_osl_find_reserved(str)) != -1) { prev = FMT_TYPE_RESERVED; + } else if ((i = txtfmt_osl_find_preprocessor(str)) != -1) { prev = FMT_TYPE_DIRECTIVE; +} /* clang-format on */ diff --git a/source/blender/editors/space_text/text_format_pov.c b/source/blender/editors/space_text/text_format_pov.c index 8064f4e69e2..a5e1a3845cf 100644 --- a/source/blender/editors/space_text/text_format_pov.c +++ b/source/blender/editors/space_text/text_format_pov.c @@ -48,39 +48,40 @@ static int txtfmt_pov_find_keyword(const char *string) int i, len; /* Language Directives */ - if (STR_LITERAL_STARTSWITH(string, "deprecated", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "persistent", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "statistics", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "version", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "warning", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "declare", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "default", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "include", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "append", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "elseif", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "debug", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "break", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "else", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "error", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fclose", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fopen", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ifndef", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ifdef", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "patch", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "local", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "macro", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "range", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "read", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "render", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "switch", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "undef", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "while", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "write", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "case", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "end", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "for", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "if", len)) i = len; - else i = 0; + if (STR_LITERAL_STARTSWITH(string, "deprecated", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "persistent", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "statistics", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "version", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "warning", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "declare", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "default", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "include", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "append", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "elseif", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "debug", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "break", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "else", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "error", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fclose", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fopen", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ifndef", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ifdef", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "patch", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "local", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "macro", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "range", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "read", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "render", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "switch", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "undef", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "while", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "write", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "case", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "end", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "for", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "if", len)) { i = len; + } else { i = 0; +} /* clang-format on */ @@ -100,145 +101,146 @@ static int txtfmt_pov_find_reserved_keywords(const char *string) /* clang-format off */ /* Float Functions */ - if (STR_LITERAL_STARTSWITH(string, "conserve_energy", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "max_intersections", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "dimension_size", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "bitwise_and", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "bitwise_or", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "bitwise_xor", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "file_exists", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "precompute", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "dimensions", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "clipped_by", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "shadowless", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "turb_depth", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "reciprocal", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "quaternion", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "phong_size", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tesselate", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "save_file", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "load_file", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "max_trace", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "transform", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "translate", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "direction", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "roughness", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "metallic", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "gts_load", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "gts_save", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "location", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "altitude", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "function", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "evaluate", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "inverse", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "collect", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "target", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "albedo", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "rotate", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "matrix", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "look_at", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "jitter", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "angle", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "right", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "scale", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "child", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "crand", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "blink", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "defined", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "degrees", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "inside", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "radians", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "vlength", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "select", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "floor", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "strcmp", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "strlen", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tessel", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sturm", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "abs", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "acosh", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "prod", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "with", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "acos", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "asc", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "asinh", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "asin", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "atan2", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "atand", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "atanh", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "atan", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ceil", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "warp", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cosh", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "log", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "max", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "min", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "mod", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pow", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "rand", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "seed", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "form", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sinh", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sqrt", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tanh", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "vdot", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sin", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sqr", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sum", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pwr", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tan", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "val", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cos", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "div", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "exp", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "int", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sky", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "up", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ln", len)) i = len; + if (STR_LITERAL_STARTSWITH(string, "conserve_energy", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "max_intersections", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "dimension_size", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "bitwise_and", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "bitwise_or", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "bitwise_xor", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "file_exists", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "precompute", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "dimensions", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "clipped_by", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "shadowless", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "turb_depth", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "reciprocal", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "quaternion", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "phong_size", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tesselate", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "save_file", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "load_file", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "max_trace", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "transform", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "translate", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "direction", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "roughness", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "metallic", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "gts_load", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "gts_save", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "location", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "altitude", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "function", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "evaluate", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "inverse", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "collect", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "target", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "albedo", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "rotate", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "matrix", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "look_at", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "jitter", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "angle", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "right", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "scale", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "child", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "crand", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "blink", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "defined", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "degrees", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "inside", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "radians", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "vlength", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "select", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "floor", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "strcmp", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "strlen", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tessel", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sturm", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "abs", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "acosh", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "prod", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "with", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "acos", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "asc", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "asinh", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "asin", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "atan2", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "atand", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "atanh", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "atan", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ceil", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "warp", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cosh", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "log", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "max", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "min", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "mod", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pow", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "rand", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "seed", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "form", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sinh", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sqrt", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tanh", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "vdot", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sin", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sqr", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sum", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pwr", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tan", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "val", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cos", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "div", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "exp", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "int", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sky", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "up", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ln", len)) { i = len; /* Color Identifiers */ - else if (STR_LITERAL_STARTSWITH(string, "transmit", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "filter", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "srgbft", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "srgbf", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "srgbt", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "rgbft", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "gamma", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "green", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "blue", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "gray", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "srgb", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sRGB", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "SRGB", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "rgbf", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "rgbt", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "rgb", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "red", len)) i = len; + } else if (STR_LITERAL_STARTSWITH(string, "transmit", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "filter", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "srgbft", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "srgbf", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "srgbt", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "rgbft", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "gamma", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "green", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "blue", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "gray", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "srgb", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sRGB", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "SRGB", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "rgbf", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "rgbt", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "rgb", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "red", len)) { i = len; /* Color Spaces */ - else if (STR_LITERAL_STARTSWITH(string, "pov", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "hsl", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "hsv", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "xyl", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "xyv", len)) i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pov", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "hsl", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "hsv", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "xyl", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "xyv", len)) { i = len; /* Vector Functions */ - else if (STR_LITERAL_STARTSWITH(string, "vaxis_rotate", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "vturbulence", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "min_extent", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "vnormalize", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "max_extent", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "vrotate", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "vcross", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "trace", len)) i = len; + } else if (STR_LITERAL_STARTSWITH(string, "vaxis_rotate", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "vturbulence", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "min_extent", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "vnormalize", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "max_extent", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "vrotate", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "vcross", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "trace", len)) { i = len; /* String Functions */ - else if (STR_LITERAL_STARTSWITH(string, "file_time", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "datetime", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "concat", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "strlwr", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "strupr", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "substr", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "vstr", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "chr", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "str", len)) i = len; - else i = 0; + } else if (STR_LITERAL_STARTSWITH(string, "file_time", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "datetime", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "concat", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "strlwr", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "strupr", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "substr", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "vstr", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "chr", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "str", len)) { i = len; + } else { i = 0; +} /* clang-format on */ @@ -259,221 +261,222 @@ static int txtfmt_pov_find_reserved_builtins(const char *string) /* clang-format off */ /* Language Keywords */ - if (STR_LITERAL_STARTSWITH(string, "reflection_exponent", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "area_illumination", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "all_intersections", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cutaway_textures", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "smooth_triangle", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "lommel_seeliger", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "falloff_angle", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "aa_threshold", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "hypercomplex", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "major_radius", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "max_distance", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "max_iteration", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "colour_space", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "color_space", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "iridescence", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "subsurface", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "scattering", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "absorption", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "water_level", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "reflection", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "max_extent", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "oren_nayar", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "refraction", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "hierarchy", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "radiosity", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tolerance", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "interior", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "toroidal", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "emission", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "material", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "internal", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "photons", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "arc_angle", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "minnaert", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "texture", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "array", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "black_hole", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "component", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "composite", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "coords", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cube", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "dist_exp", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "exterior", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "file_gamma", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "flatness", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "planet", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "screw", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "keep", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "flip", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "move", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "roll", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "look_at", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "metric", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "offset", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "orientation", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pattern", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "precision", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "width", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "repeat", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "bend", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "size", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "alpha", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "slice", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "smooth", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "solid", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "all", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "now", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pot", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "type", len)) i = len; + if (STR_LITERAL_STARTSWITH(string, "reflection_exponent", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "area_illumination", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "all_intersections", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cutaway_textures", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "smooth_triangle", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "lommel_seeliger", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "falloff_angle", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "aa_threshold", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "hypercomplex", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "major_radius", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "max_distance", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "max_iteration", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "colour_space", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "color_space", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "iridescence", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "subsurface", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "scattering", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "absorption", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "water_level", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "reflection", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "max_extent", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "oren_nayar", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "refraction", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "hierarchy", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "radiosity", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tolerance", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "interior", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "toroidal", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "emission", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "material", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "internal", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "photons", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "arc_angle", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "minnaert", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "texture", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "array", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "black_hole", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "component", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "composite", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "coords", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cube", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "dist_exp", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "exterior", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "file_gamma", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "flatness", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "planet", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "screw", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "keep", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "flip", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "move", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "roll", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "look_at", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "metric", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "offset", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "orientation", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pattern", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "precision", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "width", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "repeat", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "bend", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "size", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "alpha", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "slice", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "smooth", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "solid", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "all", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "now", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pot", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "type", len)) { i = len; /* Animation Options */ - else if (STR_LITERAL_STARTSWITH(string, "global_settings", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "input_file_name", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "initial_clock", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "initial_frame", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "frame_number", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "image_height", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "image_width", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "final_clock", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "final_frame", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "clock_delta", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "clock_on", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "clock", len)) i = len; + } else if (STR_LITERAL_STARTSWITH(string, "global_settings", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "input_file_name", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "initial_clock", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "initial_frame", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "frame_number", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "image_height", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "image_width", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "final_clock", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "final_frame", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "clock_delta", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "clock_on", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "clock", len)) { i = len; /* Spline Identifiers */ - else if (STR_LITERAL_STARTSWITH(string, "extended_x_spline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "general_x_spline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "quadratic_spline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "basic_x_spline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "natural_spline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "linear_spline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "bezier_spline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "akima_spline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cubic_spline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sor_spline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tcb_spline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "linear_sweep", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "conic_sweep", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "b_spline", len)) i = len; + } else if (STR_LITERAL_STARTSWITH(string, "extended_x_spline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "general_x_spline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "quadratic_spline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "basic_x_spline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "natural_spline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "linear_spline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "bezier_spline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "akima_spline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cubic_spline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sor_spline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tcb_spline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "linear_sweep", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "conic_sweep", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "b_spline", len)) { i = len; /* Patterns */ - else if (STR_LITERAL_STARTSWITH(string, "pigment_pattern", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "image_pattern", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "density_file", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cylindrical", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "proportion", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "triangular", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "image_map", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "proximity", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "spherical", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "bump_map", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "wrinkles", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "average", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "voronoi", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "masonry", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "binary", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "boxed", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "bozo", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "brick", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "bumps", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cells", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "checker", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "crackle", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cubic", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "dents", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "facets", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "gradient", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "granite", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "hexagon", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "julia", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "leopard", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "magnet", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "mandel", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "marble", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "onion", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pavement", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "planar", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "quilted", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "radial", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ripples", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "slope", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "spiral1", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "spiral2", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "spotted", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "square", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tile2", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tiling", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tiles", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "waves", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "wood", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "agate", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "aoi", len)) i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pigment_pattern", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "image_pattern", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "density_file", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cylindrical", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "proportion", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "triangular", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "image_map", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "proximity", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "spherical", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "bump_map", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "wrinkles", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "average", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "voronoi", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "masonry", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "binary", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "boxed", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "bozo", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "brick", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "bumps", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cells", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "checker", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "crackle", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cubic", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "dents", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "facets", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "gradient", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "granite", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "hexagon", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "julia", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "leopard", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "magnet", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "mandel", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "marble", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "onion", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pavement", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "planar", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "quilted", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "radial", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ripples", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "slope", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "spiral1", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "spiral2", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "spotted", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "square", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tile2", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tiling", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tiles", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "waves", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "wood", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "agate", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "aoi", len)) { i = len; /* Objects */ - else if (STR_LITERAL_STARTSWITH(string, "superellipsoid", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "bicubic_patch", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "julia_fractal", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "height_field", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cubic_spline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sphere_sweep", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "light_group", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "light_source", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "intersection", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "isosurface", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "background", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sky_sphere", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cylinder", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "difference", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "brilliance", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "parametric", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "interunion", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "intermerge", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "polynomial", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "displace", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "specular", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ambient", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "diffuse", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "polygon", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "quadric", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "quartic", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "rainbow", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sphere", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "spline", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "prism", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "camera", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "galley", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cubic", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "phong", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cone", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "blob", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "box", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "disc", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fog", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "lathe", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "merge", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "mesh2", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "mesh", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "object", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ovus", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "lemon", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "plane", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "poly", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "irid", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sor", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "text", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "torus", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "triangle", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "union", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "colour", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "color", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "media", len)) i = len; + } else if (STR_LITERAL_STARTSWITH(string, "superellipsoid", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "bicubic_patch", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "julia_fractal", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "height_field", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cubic_spline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sphere_sweep", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "light_group", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "light_source", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "intersection", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "isosurface", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "background", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sky_sphere", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cylinder", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "difference", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "brilliance", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "parametric", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "interunion", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "intermerge", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "polynomial", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "displace", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "specular", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ambient", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "diffuse", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "polygon", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "quadric", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "quartic", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "rainbow", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sphere", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "spline", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "prism", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "camera", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "galley", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cubic", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "phong", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cone", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "blob", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "box", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "disc", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fog", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "lathe", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "merge", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "mesh2", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "mesh", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "object", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ovus", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "lemon", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "plane", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "poly", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "irid", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sor", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "text", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "torus", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "triangle", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "union", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "colour", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "color", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "media", len)) { i = len; /* Built-in Vectors */ - else if (STR_LITERAL_STARTSWITH(string, "t", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "u", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "v", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "x", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "y", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "z", len)) i = len; - else i = 0; + } else if (STR_LITERAL_STARTSWITH(string, "t", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "u", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "v", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "x", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "y", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "z", len)) { i = len; + } else { i = 0; +} /* clang-format off */ @@ -497,202 +500,203 @@ static int txtfmt_pov_find_specialvar(const char *string) { int i, len; /* Modifiers */ - if (STR_LITERAL_STARTSWITH(string, "dispersion_samples", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "projected_through", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "double_illuminate", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "expand_thresholds", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "media_interaction", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "media_attenuation", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "low_error_factor", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "recursion_limit", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "interior_texture", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "max_trace_level", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "gray_threshold", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pretrace_start", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "normal_indices", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "normal_vectors", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "vertex_vectors", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "noise_generator", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "irid_wavelength", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "number_of_waves", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ambient_light", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "inside_vector", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "face_indices", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "texture_list", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "max_gradient", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "uv_indices", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "uv_vectors", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fade_distance", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "global_lights", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "no_bump_scale", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pretrace_end", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "no_radiosity", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "no_reflection", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "assumed_gamma", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "scallop_wave", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "triangle_wave", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "nearest_count", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "maximum_reuse", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "minimum_reuse", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "always_sample", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "translucency", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "eccentricity", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "contained_by", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "inside_point", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "adc_bailout", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "density_map", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "split_union", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "mm_per_unit", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "agate_turb", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "bounded_by", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "brick_size", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "hf_gray_16", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "dispersion", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "extinction", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "thickness", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "color_map", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "colour_map", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cubic_wave", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fade_colour", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fade_power", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fade_color", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "normal_map", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pigment_map", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "quick_color", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "quick_colour", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "material_map", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pass_through", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "interpolate", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "texture_map", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "error_bound", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "brightness", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "use_color", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "use_alpha", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "use_colour", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "use_index", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "uv_mapping", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "importance", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "max_sample", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "intervals", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sine_wave", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "slope_map", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "poly_wave", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "no_shadow", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ramp_wave", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "precision", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "original", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "accuracy", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "map_type", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "no_image", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "distance", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "autostop", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "caustics", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "octaves", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "aa_level", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "frequency", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fog_offset", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "modulation", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "outbound", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "no_cache", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pigment", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "charset", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "inbound", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "outside", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "inner", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "turbulence", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "threshold", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "accuracy", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "polarity", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "bump_size", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "circular", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "control0", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "control1", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "maximal", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "minimal", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fog_type", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fog_alt", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "samples", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "origin", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "amount", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "adaptive", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "exponent", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "strength", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "density", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fresnel", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "albinos", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "finish", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "method", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "omega", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fixed", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "spacing", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "u_steps", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "v_steps", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "offset", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "hollow", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "gather", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "lambda", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "mortar", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "cubic", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "count", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "once", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "orient", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "normal", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "phase", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ratio", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "open", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ior", len)) i = len; + if (STR_LITERAL_STARTSWITH(string, "dispersion_samples", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "projected_through", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "double_illuminate", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "expand_thresholds", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "media_interaction", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "media_attenuation", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "low_error_factor", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "recursion_limit", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "interior_texture", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "max_trace_level", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "gray_threshold", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pretrace_start", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "normal_indices", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "normal_vectors", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "vertex_vectors", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "noise_generator", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "irid_wavelength", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "number_of_waves", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ambient_light", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "inside_vector", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "face_indices", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "texture_list", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "max_gradient", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "uv_indices", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "uv_vectors", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fade_distance", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "global_lights", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "no_bump_scale", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pretrace_end", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "no_radiosity", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "no_reflection", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "assumed_gamma", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "scallop_wave", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "triangle_wave", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "nearest_count", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "maximum_reuse", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "minimum_reuse", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "always_sample", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "translucency", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "eccentricity", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "contained_by", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "inside_point", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "adc_bailout", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "density_map", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "split_union", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "mm_per_unit", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "agate_turb", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "bounded_by", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "brick_size", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "hf_gray_16", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "dispersion", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "extinction", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "thickness", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "color_map", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "colour_map", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cubic_wave", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fade_colour", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fade_power", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fade_color", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "normal_map", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pigment_map", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "quick_color", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "quick_colour", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "material_map", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pass_through", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "interpolate", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "texture_map", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "error_bound", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "brightness", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "use_color", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "use_alpha", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "use_colour", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "use_index", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "uv_mapping", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "importance", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "max_sample", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "intervals", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sine_wave", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "slope_map", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "poly_wave", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "no_shadow", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ramp_wave", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "precision", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "original", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "accuracy", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "map_type", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "no_image", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "distance", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "autostop", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "caustics", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "octaves", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "aa_level", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "frequency", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fog_offset", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "modulation", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "outbound", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "no_cache", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pigment", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "charset", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "inbound", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "outside", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "inner", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "turbulence", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "threshold", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "accuracy", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "polarity", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "bump_size", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "circular", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "control0", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "control1", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "maximal", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "minimal", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fog_type", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fog_alt", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "samples", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "origin", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "amount", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "adaptive", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "exponent", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "strength", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "density", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fresnel", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "albinos", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "finish", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "method", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "omega", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fixed", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "spacing", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "u_steps", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "v_steps", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "offset", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "hollow", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "gather", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "lambda", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "mortar", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "cubic", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "count", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "once", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "orient", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "normal", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "phase", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ratio", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "open", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ior", len)) { i = len; /* Light Types and options*/ - else if (STR_LITERAL_STARTSWITH(string, "area_light", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "looks_like", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fade_power", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tightness", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "spotlight", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "parallel", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "point_at", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "falloff", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "radius", len)) i = len; + } else if (STR_LITERAL_STARTSWITH(string, "area_light", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "looks_like", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fade_power", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tightness", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "spotlight", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "parallel", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "point_at", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "falloff", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "radius", len)) { i = len; /* Camera Types and options*/ - else if (STR_LITERAL_STARTSWITH(string, "omni_directional_stereo", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "lambert_cylindrical", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "miller_cylindrical", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "lambert_azimuthal", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ultra_wide_angle", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "camera_direction", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "camera_location ", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "van_der_grinten", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "aitoff_hammer", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "smyth_craster", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "orthographic", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "camera_right", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "blur_samples", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "plate_carree", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "camera_type", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "perspective", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "mesh_camera", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "focal_point", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "balthasart", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "confidence", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "parallaxe", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "hobo_dyer", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "camera_up", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "panoramic", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "eckert_vi", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "eckert_iv", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "mollweide", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "aperture", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "behrmann", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "variance", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "stereo", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "icosa", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tetra", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "octa", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "mercator", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "omnimax", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fisheye", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "edwards", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "peters", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "gall", len)) i = len; - else i = 0; + } else if (STR_LITERAL_STARTSWITH(string, "omni_directional_stereo", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "lambert_cylindrical", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "miller_cylindrical", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "lambert_azimuthal", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ultra_wide_angle", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "camera_direction", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "camera_location ", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "van_der_grinten", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "aitoff_hammer", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "smyth_craster", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "orthographic", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "camera_right", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "blur_samples", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "plate_carree", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "camera_type", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "perspective", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "mesh_camera", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "focal_point", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "balthasart", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "confidence", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "parallaxe", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "hobo_dyer", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "camera_up", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "panoramic", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "eckert_vi", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "eckert_iv", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "mollweide", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "aperture", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "behrmann", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "variance", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "stereo", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "icosa", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tetra", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "octa", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "mercator", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "omnimax", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fisheye", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "edwards", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "peters", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "gall", len)) { i = len; + } else { i = 0; +} /* If next source char is an identifier (eg. 'i' in "definite") no match */ return (i == 0 || text_check_identifier(string[i])) ? -1 : i; @@ -706,43 +710,44 @@ static int txtfmt_pov_find_bool(const char *string) /* clang-format off */ /* Built-in Constants */ - if (STR_LITERAL_STARTSWITH(string, "unofficial", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "false", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "no", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "off", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "true", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "yes", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "on", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pi", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tau", len)) i = len; + if (STR_LITERAL_STARTSWITH(string, "unofficial", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "false", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "no", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "off", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "true", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "yes", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "on", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pi", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tau", len)) { i = len; /* Encodings */ - else if (STR_LITERAL_STARTSWITH(string, "sint16be", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sint16le", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sint32be", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sint32le", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "uint16be", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "uint16le", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "bt2020", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "bt709", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sint8", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "uint8", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ascii", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "utf8", len)) i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sint16be", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sint16le", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sint32be", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sint32le", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "uint16be", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "uint16le", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "bt2020", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "bt709", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sint8", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "uint8", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ascii", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "utf8", len)) { i = len; /* Filetypes */ - else if (STR_LITERAL_STARTSWITH(string, "tiff", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "df3", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "exr", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "gif", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "hdr", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "iff", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "jpeg", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pgm", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "png", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ppm", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sys", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tga", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ttf", len)) i = len; - else i = 0; + } else if (STR_LITERAL_STARTSWITH(string, "tiff", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "df3", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "exr", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "gif", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "hdr", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "iff", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "jpeg", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pgm", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "png", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ppm", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sys", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tga", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ttf", len)) { i = len; + } else { i = 0; +} /* clang-format on */ @@ -757,11 +762,12 @@ static char txtfmt_pov_format_identifier(const char *str) /* Keep aligned args for readability. */ /* clang-format off */ - if ((txtfmt_pov_find_specialvar(str)) != -1) fmt = FMT_TYPE_SPECIAL; - else if ((txtfmt_pov_find_keyword(str)) != -1) fmt = FMT_TYPE_KEYWORD; - else if ((txtfmt_pov_find_reserved_keywords(str)) != -1) fmt = FMT_TYPE_RESERVED; - else if ((txtfmt_pov_find_reserved_builtins(str)) != -1) fmt = FMT_TYPE_DIRECTIVE; - else fmt = FMT_TYPE_DEFAULT; + if ((txtfmt_pov_find_specialvar(str)) != -1) { fmt = FMT_TYPE_SPECIAL; + } else if ((txtfmt_pov_find_keyword(str)) != -1) { fmt = FMT_TYPE_KEYWORD; + } else if ((txtfmt_pov_find_reserved_keywords(str)) != -1) { fmt = FMT_TYPE_RESERVED; + } else if ((txtfmt_pov_find_reserved_builtins(str)) != -1) { fmt = FMT_TYPE_DIRECTIVE; + } else { fmt = FMT_TYPE_DEFAULT; +} /* clang-format on */ @@ -810,8 +816,9 @@ static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_ *fmt = prev; fmt++; str++; - if (*str == '\0') + if (*str == '\0') { break; + } *fmt = prev; fmt++; str += BLI_str_utf8_size_safe(str); @@ -835,8 +842,9 @@ static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_ } else { find = (cont & FMT_CONT_QUOTEDOUBLE) ? '"' : '\''; - if (*str == find) + if (*str == find) { cont = 0; + } *fmt = FMT_TYPE_STRING; } @@ -897,10 +905,11 @@ static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_ /* Special vars(v) or built-in keywords(b) */ /* keep in sync with 'txtfmt_pov_format_identifier()' */ - if ((i = txtfmt_pov_find_specialvar(str)) != -1) prev = FMT_TYPE_SPECIAL; - else if ((i = txtfmt_pov_find_keyword(str)) != -1) prev = FMT_TYPE_KEYWORD; - else if ((i = txtfmt_pov_find_reserved_keywords(str)) != -1) prev = FMT_TYPE_RESERVED; - else if ((i = txtfmt_pov_find_reserved_builtins(str)) != -1) prev = FMT_TYPE_DIRECTIVE; + if ((i = txtfmt_pov_find_specialvar(str)) != -1) { prev = FMT_TYPE_SPECIAL; + } else if ((i = txtfmt_pov_find_keyword(str)) != -1) { prev = FMT_TYPE_KEYWORD; + } else if ((i = txtfmt_pov_find_reserved_keywords(str)) != -1) { prev = FMT_TYPE_RESERVED; + } else if ((i = txtfmt_pov_find_reserved_builtins(str)) != -1) { prev = FMT_TYPE_DIRECTIVE; +} /* clang-format on */ diff --git a/source/blender/editors/space_text/text_format_pov_ini.c b/source/blender/editors/space_text/text_format_pov_ini.c index 0dbf2b1bdd3..04f4b992cc6 100644 --- a/source/blender/editors/space_text/text_format_pov_ini.c +++ b/source/blender/editors/space_text/text_format_pov_ini.c @@ -49,49 +49,50 @@ static int txtfmt_ini_find_keyword(const char *string) /* clang-format off */ /* Language Directives */ - if (STR_LITERAL_STARTSWITH(string, "deprecated", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "statistics", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "declare", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "default", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "version", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "warning", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "include", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fclose", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ifndef", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "append", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "elseif", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "debug", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "error", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "fopen", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ifdef", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "local", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "macro", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "range", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "render", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "break", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "switch", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "undef", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "while", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "write", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "case", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "else", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "read", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "end", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "for", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "if", len)) i = len; - - else if (STR_LITERAL_STARTSWITH(string, "I", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "S", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "A", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Q", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "U", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "F", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "C", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "N", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "P", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "T", len)) i = len; - - else i = 0; + if (STR_LITERAL_STARTSWITH(string, "deprecated", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "statistics", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "declare", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "default", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "version", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "warning", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "include", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fclose", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ifndef", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "append", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "elseif", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "debug", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "error", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "fopen", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ifdef", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "local", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "macro", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "range", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "render", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "break", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "switch", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "undef", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "while", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "write", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "case", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "else", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "read", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "end", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "for", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "if", len)) { i = len; + + } else if (STR_LITERAL_STARTSWITH(string, "I", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "S", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "A", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Q", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "U", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "F", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "C", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "N", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "P", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "T", len)) { i = len; + + } else { i = 0; +} /* clang-format on */ @@ -110,200 +111,201 @@ static int txtfmt_ini_find_reserved(const char *string) * list is from... * http://www.povray.org/documentation/view/3.7.0/212/ */ - if (STR_LITERAL_STARTSWITH(string, "RenderCompleteSoundEnabled", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Create_Continue_Trace_Log", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ParseErrorSoundEnabled", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "RenderErrorSoundEnabled", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "HideWhenMainMinimized", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Antialias_Confidence", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "RenderCompleteSound", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ParseErrorSound", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "RenderErrorSound", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "UseExtensions", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ReadWriteSourceDir", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "NormalPositionLeft", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "NormalPositionTop", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "NormalPositionRight", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "NormalPositionBottom", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Pre_Scene_Command", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Pre_Frame_Command", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Post_Scene_Command", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Post_Frame_Command", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "User_Abort_Command", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Fatal_Error_Command", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "NormalPositionX", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "NormalPositionY", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Pre_Scene_Return", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Pre_Frame_Return", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Post_Scene_Return", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Post_Frame_Return", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "User_Abort_Return", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Fatal_Error_Return", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Antialias_Threshold", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Antialias_Gamma", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Antialias_Depth", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "input_file_name", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Subset_Start_Frame", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Subset_End_Frame", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "UseToolbar", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "UseTooltips", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Frame_Step", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Cyclic_Animation", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Field_Render", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Odd_Field", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "final_clock", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "final_frame", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "frame_number", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "initial_clock", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "initial_frame", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "image_height", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "image_width", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Start_Column", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Start_Row", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "End_Column", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "End_Row", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Test_Abort_Count", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Test_Abort", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Continue_Trace", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Bounding_Method", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Create_Ini", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Display_Gamma", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Display", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Version", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Pause_When_Done", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Verbose", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Preview_Start_Size", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Preview_End_Size", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Output_to_File", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Input_File_Name", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Output_File_Name", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Output_File_Type", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Output_Alpha", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Bits_Per_Color", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Compression", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Dither_Method", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Include_Header", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Library_Path", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Debug_Console", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Fatal_Console", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Render_Console", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Statistic_Console", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Warning_Console", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Warning_Level", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "All_Console", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Debug_File", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Fatal_File", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Render_File", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Statistic_File", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Warning_File", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "All_File", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Quality", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Bounding_Threshold", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Bounding", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Light_Buffer", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Vista_Buffer", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Remove_Bounds", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Split_Unions", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Antialias", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Glare_Desaturation", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Sampling_Method", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Stochastic_Seed", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Jitter_Amount", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Jitter", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Antialias_Depth", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "CheckNewVersion", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "RunCount", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "CommandLine", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "TextColour", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "WarningColour", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ErrorColour", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "BackgroundColour", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "DropToEditor", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "LastRenderName", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "LastRenderPath", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "LastQueuePath", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "SecondaryINISection", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "BetaVersionNo64", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "LastBitmapName", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "LastBitmapPath", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "LastINIPath", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "SecondaryINIFile", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "BackgroundFile", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "SaveSettingsOnExit", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "TileBackground", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "HideNewUserHelp", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "SendSystemInfo", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ItsAboutTime", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "LastPath", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Band0Width", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Band1Width", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Band2Width", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Band3Width", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Band4Width", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ShowCmd", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Transparency", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Use8BitMode", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "MakeActive", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "KeepAboveMain", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "AutoClose", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "PreserveBitmap", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "FontSize", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "FontWeight", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "KeepMessages", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "AlertSound", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Completion", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Priority", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "DutyCycle", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "AlertOnCompletion", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "AutoRender", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "PreventSleep", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "NoShelloutWait", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "SystemNoActive", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "NoShellOuts", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "VideoSource", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "SceneFile", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "OutputFile", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "IniOutputFile", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "CurrentDirectory", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "SourceFile", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Rendering", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "RenderwinClose", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Append_File", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Warning Level", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "clock_delta", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "clock_on", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "clock", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Height", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Width", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Dither", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Flags", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "Font", len)) i = len; + if (STR_LITERAL_STARTSWITH(string, "RenderCompleteSoundEnabled", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Create_Continue_Trace_Log", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ParseErrorSoundEnabled", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "RenderErrorSoundEnabled", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "HideWhenMainMinimized", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Antialias_Confidence", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "RenderCompleteSound", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ParseErrorSound", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "RenderErrorSound", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "UseExtensions", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ReadWriteSourceDir", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "NormalPositionLeft", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "NormalPositionTop", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "NormalPositionRight", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "NormalPositionBottom", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Pre_Scene_Command", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Pre_Frame_Command", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Post_Scene_Command", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Post_Frame_Command", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "User_Abort_Command", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Fatal_Error_Command", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "NormalPositionX", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "NormalPositionY", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Pre_Scene_Return", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Pre_Frame_Return", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Post_Scene_Return", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Post_Frame_Return", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "User_Abort_Return", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Fatal_Error_Return", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Antialias_Threshold", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Antialias_Gamma", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Antialias_Depth", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "input_file_name", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Subset_Start_Frame", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Subset_End_Frame", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "UseToolbar", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "UseTooltips", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Frame_Step", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Cyclic_Animation", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Field_Render", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Odd_Field", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "final_clock", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "final_frame", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "frame_number", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "initial_clock", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "initial_frame", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "image_height", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "image_width", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Start_Column", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Start_Row", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "End_Column", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "End_Row", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Test_Abort_Count", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Test_Abort", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Continue_Trace", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Bounding_Method", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Create_Ini", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Display_Gamma", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Display", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Version", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Pause_When_Done", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Verbose", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Preview_Start_Size", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Preview_End_Size", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Output_to_File", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Input_File_Name", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Output_File_Name", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Output_File_Type", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Output_Alpha", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Bits_Per_Color", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Compression", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Dither_Method", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Include_Header", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Library_Path", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Debug_Console", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Fatal_Console", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Render_Console", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Statistic_Console", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Warning_Console", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Warning_Level", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "All_Console", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Debug_File", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Fatal_File", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Render_File", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Statistic_File", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Warning_File", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "All_File", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Quality", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Bounding_Threshold", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Bounding", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Light_Buffer", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Vista_Buffer", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Remove_Bounds", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Split_Unions", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Antialias", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Glare_Desaturation", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Sampling_Method", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Stochastic_Seed", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Jitter_Amount", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Jitter", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Antialias_Depth", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "CheckNewVersion", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "RunCount", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "CommandLine", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "TextColour", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "WarningColour", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ErrorColour", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "BackgroundColour", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "DropToEditor", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "LastRenderName", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "LastRenderPath", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "LastQueuePath", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "SecondaryINISection", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "BetaVersionNo64", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "LastBitmapName", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "LastBitmapPath", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "LastINIPath", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "SecondaryINIFile", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "BackgroundFile", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "SaveSettingsOnExit", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "TileBackground", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "HideNewUserHelp", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "SendSystemInfo", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ItsAboutTime", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "LastPath", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Band0Width", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Band1Width", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Band2Width", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Band3Width", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Band4Width", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ShowCmd", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Transparency", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Use8BitMode", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "MakeActive", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "KeepAboveMain", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "AutoClose", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "PreserveBitmap", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "FontSize", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "FontWeight", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "KeepMessages", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "AlertSound", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Completion", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Priority", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "DutyCycle", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "AlertOnCompletion", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "AutoRender", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "PreventSleep", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "NoShelloutWait", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "SystemNoActive", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "NoShellOuts", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "VideoSource", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "SceneFile", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "OutputFile", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "IniOutputFile", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "CurrentDirectory", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "SourceFile", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Rendering", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "RenderwinClose", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Append_File", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Warning Level", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "clock_delta", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "clock_on", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "clock", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Height", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Width", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Dither", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Flags", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "Font", len)) { i = len; /* Filetypes */ - else if (STR_LITERAL_STARTSWITH(string, "df3", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "exr", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "gif", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "hdr", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "iff", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "jpeg", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pgm", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "png", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "ppm", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sys", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tga", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tiff", len)) i = len; + } else if (STR_LITERAL_STARTSWITH(string, "df3", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "exr", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "gif", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "hdr", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "iff", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "jpeg", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pgm", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "png", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "ppm", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sys", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tga", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tiff", len)) { i = len; /* Encodings */ - else if (STR_LITERAL_STARTSWITH(string, "ascii", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "utf8", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "uint8", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "uint16be", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "uint16le", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sint8", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sint16be", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sint16le", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sint32be", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "sint32le", len)) i = len; - - else i = 0; + } else if (STR_LITERAL_STARTSWITH(string, "ascii", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "utf8", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "uint8", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "uint16be", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "uint16le", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sint8", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sint16be", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sint16le", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sint32be", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "sint32le", len)) { i = len; + + } else { i = 0; +} /* clang-format on */ @@ -319,21 +321,22 @@ static int txtfmt_ini_find_bool(const char *string) /* clang-format off */ /* Built-in Constants */ - if (STR_LITERAL_STARTSWITH(string, "false", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "no", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "off", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "true", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "yes", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "on", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pi", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "tau", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "%o", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "%s", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "%n", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "%k", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "%h", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "%w", len)) i = len; - else i = 0; + if (STR_LITERAL_STARTSWITH(string, "false", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "no", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "off", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "true", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "yes", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "on", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pi", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "tau", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "%o", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "%s", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "%n", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "%k", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "%h", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "%w", len)) { i = len; + } else { i = 0; +} /* clang-format on */ @@ -344,12 +347,15 @@ static int txtfmt_ini_find_bool(const char *string) static char txtfmt_pov_ini_format_identifier(const char *str) { char fmt; - if ((txtfmt_ini_find_keyword(str)) != -1) + if ((txtfmt_ini_find_keyword(str)) != -1) { fmt = FMT_TYPE_KEYWORD; - else if ((txtfmt_ini_find_reserved(str)) != -1) + } + else if ((txtfmt_ini_find_reserved(str)) != -1) { fmt = FMT_TYPE_RESERVED; - else + } + else { fmt = FMT_TYPE_DEFAULT; + } return fmt; } @@ -395,8 +401,9 @@ static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool *fmt = prev; fmt++; str++; - if (*str == '\0') + if (*str == '\0') { break; + } *fmt = prev; fmt++; str += BLI_str_utf8_size_safe(str); @@ -420,8 +427,9 @@ static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool } else { find = (cont & FMT_CONT_QUOTEDOUBLE) ? '"' : '\''; - if (*str == find) + if (*str == find) { cont = 0; + } *fmt = FMT_TYPE_STRING; } @@ -475,8 +483,9 @@ static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool /* Special vars(v) or built-in keywords(b) */ /* keep in sync with 'txtfmt_ini_format_identifier()' */ - if ((i = txtfmt_ini_find_keyword(str)) != -1) prev = FMT_TYPE_KEYWORD; - else if ((i = txtfmt_ini_find_reserved(str)) != -1) prev = FMT_TYPE_RESERVED; + if ((i = txtfmt_ini_find_keyword(str)) != -1) { prev = FMT_TYPE_KEYWORD; + } else if ((i = txtfmt_ini_find_reserved(str)) != -1) { prev = FMT_TYPE_RESERVED; +} /* clang-format on */ diff --git a/source/blender/editors/space_text/text_format_py.c b/source/blender/editors/space_text/text_format_py.c index 68e42335546..98eeee61c3a 100644 --- a/source/blender/editors/space_text/text_format_py.c +++ b/source/blender/editors/space_text/text_format_py.c @@ -58,43 +58,45 @@ static int txtfmt_py_find_builtinfunc(const char *string) /* Keep aligned args for readability. */ /* clang-format off */ - if (STR_LITERAL_STARTSWITH(string, "and", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "as", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "assert", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "async", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "await", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "break", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "continue", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "del", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "elif", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "else", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "except", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "finally", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "for", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "from", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "global", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "if", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "import", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "in", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "is", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "lambda", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "nonlocal", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "not", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "or", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "pass", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "raise", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "return", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "try", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "while", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "with", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "yield", len)) i = len; - else i = 0; + if (STR_LITERAL_STARTSWITH(string, "and", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "as", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "assert", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "async", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "await", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "break", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "continue", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "del", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "elif", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "else", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "except", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "finally", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "for", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "from", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "global", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "if", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "import", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "in", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "is", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "lambda", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "nonlocal", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "not", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "or", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "pass", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "raise", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "return", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "try", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "while", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "with", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "yield", len)) { i = len; + } else { i = 0; +} /* clang-format on */ /* If next source char is an identifier (eg. 'i' in "definite") no match */ - if (i == 0 || text_check_identifier(string[i])) + if (i == 0 || text_check_identifier(string[i])) { return -1; + } return i; } @@ -112,15 +114,17 @@ static int txtfmt_py_find_specialvar(const char *string) /* Keep aligned args for readability. */ /* clang-format off */ - if (STR_LITERAL_STARTSWITH(string, "def", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "class", len)) i = len; - else i = 0; + if (STR_LITERAL_STARTSWITH(string, "def", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "class", len)) { i = len; + } else { i = 0; +} /* clang-format on */ /* If next source char is an identifier (eg. 'i' in "definite") no match */ - if (i == 0 || text_check_identifier(string[i])) + if (i == 0 || text_check_identifier(string[i])) { return -1; + } return i; } @@ -151,16 +155,18 @@ static int txtfmt_py_find_bool(const char *string) /* Keep aligned args for readability. */ /* clang-format off */ - if (STR_LITERAL_STARTSWITH(string, "None", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "True", len)) i = len; - else if (STR_LITERAL_STARTSWITH(string, "False", len)) i = len; - else i = 0; + if (STR_LITERAL_STARTSWITH(string, "None", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "True", len)) { i = len; + } else if (STR_LITERAL_STARTSWITH(string, "False", len)) { i = len; + } else { i = 0; +} /* clang-format on */ /* If next source char is an identifier (eg. 'i' in "Nonetheless") no match */ - if (i == 0 || text_check_identifier(string[i])) + if (i == 0 || text_check_identifier(string[i])) { return -1; + } return i; } @@ -171,10 +177,11 @@ static char txtfmt_py_format_identifier(const char *str) /* Keep aligned args for readability. */ /* clang-format off */ - if ((txtfmt_py_find_specialvar(str)) != -1) fmt = FMT_TYPE_SPECIAL; - else if ((txtfmt_py_find_builtinfunc(str)) != -1) fmt = FMT_TYPE_KEYWORD; - else if ((txtfmt_py_find_decorator(str)) != -1) fmt = FMT_TYPE_RESERVED; - else fmt = FMT_TYPE_DEFAULT; + if ((txtfmt_py_find_specialvar(str)) != -1) { fmt = FMT_TYPE_SPECIAL; + } else if ((txtfmt_py_find_builtinfunc(str)) != -1) { fmt = FMT_TYPE_KEYWORD; + } else if ((txtfmt_py_find_decorator(str)) != -1) { fmt = FMT_TYPE_RESERVED; + } else { fmt = FMT_TYPE_DEFAULT; +} /* clang-format on */ return fmt; @@ -222,8 +229,9 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const bool do_n *fmt = prev; fmt++; str++; - if (*str == '\0') + if (*str == '\0') { break; + } *fmt = prev; fmt++; str += BLI_str_utf8_size_safe(str); @@ -247,8 +255,9 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const bool do_n } else { find = (cont & FMT_CONT_QUOTEDOUBLE) ? '"' : '\''; - if (*str == find) + if (*str == find) { cont = FMT_CONT_NOP; + } } *fmt = FMT_TYPE_STRING; @@ -311,9 +320,10 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const bool do_n /* Special vars(v) or built-in keywords(b) */ /* keep in sync with 'txtfmt_py_format_identifier()' */ - if ((i = txtfmt_py_find_specialvar(str)) != -1) prev = FMT_TYPE_SPECIAL; - else if ((i = txtfmt_py_find_builtinfunc(str)) != -1) prev = FMT_TYPE_KEYWORD; - else if ((i = txtfmt_py_find_decorator(str)) != -1) prev = FMT_TYPE_DIRECTIVE; + if ((i = txtfmt_py_find_specialvar(str)) != -1) { prev = FMT_TYPE_SPECIAL; + } else if ((i = txtfmt_py_find_builtinfunc(str)) != -1) { prev = FMT_TYPE_KEYWORD; + } else if ((i = txtfmt_py_find_decorator(str)) != -1) { prev = FMT_TYPE_DIRECTIVE; +} /* clang-format on */ diff --git a/source/blender/editors/space_text/text_header.c b/source/blender/editors/space_text/text_header.c index 435a6fd67de..e2d2bb5ed64 100644 --- a/source/blender/editors/space_text/text_header.c +++ b/source/blender/editors/space_text/text_header.c @@ -45,15 +45,17 @@ static ARegion *text_has_properties_region(ScrArea *sa) ARegion *ar, *arnew; ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); - if (ar) + if (ar) { return ar; + } /* add subdiv level; after header */ ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); /* is error! */ - if (ar == NULL) + if (ar == NULL) { return NULL; + } arnew = MEM_callocN(sizeof(ARegion), "properties region"); @@ -71,29 +73,6 @@ static bool text_properties_poll(bContext *C) return (CTX_wm_space_text(C) != NULL); } -static int text_properties_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = text_has_properties_region(sa); - - if (ar) - ED_region_toggle_hidden(C, ar); - - return OPERATOR_FINISHED; -} - -void TEXT_OT_properties(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Toggle Sidebar"; - ot->description = "Toggle the properties region visibility"; - ot->idname = "TEXT_OT_properties"; - - /* api callbacks */ - ot->exec = text_properties_exec; - ot->poll = text_properties_poll; -} - static int text_text_search_exec(bContext *C, wmOperator *UNUSED(op)) { ScrArea *sa = CTX_wm_area(C); @@ -101,8 +80,9 @@ static int text_text_search_exec(bContext *C, wmOperator *UNUSED(op)) SpaceText *st = CTX_wm_space_text(C); if (ar) { - if (ar->flag & RGN_FLAG_HIDDEN) + if (ar->flag & RGN_FLAG_HIDDEN) { ED_region_toggle_hidden(C, ar); + } /* cannot send a button activate yet for case when region wasn't visible yet */ /* flag gets checked and cleared in main draw callback */ @@ -195,13 +175,30 @@ void TEXT_OT_start_find(wmOperatorType *ot) uiPopupMenu *pup; pup = UI_popup_menu_begin(C, IFACE_("Text"), ICON_NONE); - uiItemEnumO(layout, "TEXT_OT_move", CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Top of File"), - 0, "type", FILE_TOP); - uiItemEnumO(layout, "TEXT_OT_move", CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Bottom of File"), - 0, "type", FILE_BOTTOM); - uiItemEnumO(layout, "TEXT_OT_move", CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Page Up"), 0, "type", PREV_PAGE); - uiItemEnumO(layout, "TEXT_OT_move", CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Page Down"), - 0, "type", NEXT_PAGE); + uiItemEnumO(layout, + "TEXT_OT_move", + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Top of File"), + 0, + "type", + FILE_TOP); + uiItemEnumO(layout, + "TEXT_OT_move", + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Bottom of File"), + 0, + "type", + FILE_BOTTOM); + uiItemEnumO(layout, + "TEXT_OT_move", + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Page Up"), + 0, + "type", + PREV_PAGE); + uiItemEnumO(layout, + "TEXT_OT_move", + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Page Down"), + 0, + "type", + NEXT_PAGE); UI_popup_menu_end(C, pup); } #endif diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h index cf28f3d317c..aab5069f919 100644 --- a/source/blender/editors/space_text/text_intern.h +++ b/source/blender/editors/space_text/text_intern.h @@ -145,8 +145,6 @@ void TEXT_OT_selection_set(struct wmOperatorType *ot); void TEXT_OT_cursor_set(struct wmOperatorType *ot); void TEXT_OT_line_number(struct wmOperatorType *ot); -void TEXT_OT_properties(struct wmOperatorType *ot); - /* find = find indicated text */ void TEXT_OT_find(struct wmOperatorType *ot); void TEXT_OT_find_set_selected(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index c069fc600e8..7b6e0ff8771 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -61,6 +61,83 @@ static void txt_screen_clamp(SpaceText *st, ARegion *ar); +/************************ util ***************************/ + +/** + * Tests if the given character represents a start of a new line or the + * indentation part of a line. + * \param c: The current character. + * \param r_last_state: A pointer to a flag representing the last state. The + * flag may be modified. + */ +static void test_line_start(char c, bool *r_last_state) +{ + if (c == '\n') { + *r_last_state = true; + } + else if (!ELEM(c, '\t', ' ')) { + *r_last_state = false; + } +} + +/** + * This function converts the indentation tabs from a buffer to spaces. + * \param buf: A pointer to a cstring. + * \param tab_size: The size, in spaces, of the tab character. + */ +static char *buf_tabs_to_spaces(const char *in_buf, const int tab_size) +{ + /* Get the number of tab characters in buffer. */ + bool line_start = true; + int num_tabs = 0; + + for (int in_offset = 0; in_buf[in_offset]; in_offset++) { + /* Verify if is an indentation whitespace character. */ + test_line_start(in_buf[in_offset], &line_start); + + if (in_buf[in_offset] == '\t' && line_start) { + num_tabs++; + } + } + + /* Allocate output before with extra space for expanded tabs. */ + const int out_size = strlen(in_buf) + num_tabs * (tab_size - 1); + char *out_buf = MEM_mallocN(out_size * sizeof(char), __func__); + + /* Fill output buffer. */ + int spaces_until_tab = 0; + int out_offset = 0; + line_start = true; + + for (int in_offset = 0; in_buf[in_offset]; in_offset++) { + /* Verify if is an indentation whitespace character. */ + test_line_start(in_buf[in_offset], &line_start); + + if (in_buf[in_offset] == '\t' && line_start) { + /* Calculate tab size so it fills until next indentation. */ + int num_spaces = tab_size - (spaces_until_tab % tab_size); + spaces_until_tab = 0; + + /* Write to buffer. */ + memset(&out_buf[out_offset], ' ', num_spaces); + out_offset += num_spaces; + } + else { + if (in_buf[in_offset] == ' ') { + spaces_until_tab++; + } + else if (in_buf[in_offset] == '\n') { + spaces_until_tab = 0; + } + + out_buf[out_offset++] = in_buf[in_offset]; + } + } + + out_buf[out_offset] = '\0'; + return out_buf; +} + /************************ poll ***************************/ BLI_INLINE int text_pixel_x_to_column(SpaceText *st, const int x) @@ -78,8 +155,9 @@ static bool text_edit_poll(bContext *C) { Text *text = CTX_data_edit_text(C); - if (!text) + if (!text) { return 0; + } if (ID_IS_LINKED(text)) { // BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data"); @@ -94,8 +172,9 @@ bool text_space_edit_poll(bContext *C) SpaceText *st = CTX_wm_space_text(C); Text *text = CTX_data_edit_text(C); - if (!st || !text) + if (!st || !text) { return 0; + } if (ID_IS_LINKED(text)) { // BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data"); @@ -111,11 +190,13 @@ static bool text_region_edit_poll(bContext *C) Text *text = CTX_data_edit_text(C); ARegion *ar = CTX_wm_region(C); - if (!st || !text) + if (!st || !text) { return 0; + } - if (!ar || ar->regiontype != RGN_TYPE_WINDOW) + if (!ar || ar->regiontype != RGN_TYPE_WINDOW) { return 0; + } if (ID_IS_LINKED(text)) { // BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data"); @@ -129,8 +210,9 @@ static bool text_region_edit_poll(bContext *C) void text_update_line_edited(TextLine *line) { - if (!line) + if (!line) { return; + } /* we just free format here, and let it rebuild during draw */ if (line->format) { @@ -143,8 +225,9 @@ void text_update_edited(Text *text) { TextLine *line; - for (line = text->lines.first; line; line = line->next) + for (line = text->lines.first; line; line = line->next) { text_update_line_edited(line); + } } /******************* new operator *********************/ @@ -226,13 +309,15 @@ static int text_open_exec(bContext *C, wmOperator *op) text = BKE_text_load_ex(bmain, str, BKE_main_blendfile_path(bmain), internal); if (!text) { - if (op->customdata) + if (op->customdata) { MEM_freeN(op->customdata); + } return OPERATOR_CANCELLED; } - if (!op->customdata) + if (!op->customdata) { text_open_init(C, op); + } /* hook into UI */ pprop = op->customdata; @@ -266,8 +351,9 @@ static int text_open_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(e Text *text = CTX_data_edit_text(C); const char *path = (text && text->name) ? text->name : BKE_main_blendfile_path(bmain); - if (RNA_struct_property_is_set(op->ptr, "filepath")) + if (RNA_struct_property_is_set(op->ptr, "filepath")) { return text_open_exec(C, op); + } text_open_init(C, op); RNA_string_set(op->ptr, "filepath", path); @@ -299,7 +385,7 @@ void TEXT_OT_open(wmOperatorType *ot) FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); //XXX TODO, relative_path + FILE_SORT_ALPHA); // XXX TODO, relative_path RNA_def_boolean( ot->srna, "internal", 0, "Make internal", "Make text file internal after loading"); } @@ -323,8 +409,9 @@ static int text_reload_exec(bContext *C, wmOperator *op) } #ifdef WITH_PYTHON - if (text->compiled) + if (text->compiled) { BPY_text_free_code(text); + } #endif text_update_edited(text); @@ -446,8 +533,9 @@ static bool text_save_poll(bContext *C) { Text *text = CTX_data_edit_text(C); - if (!text_edit_poll(C)) + if (!text_edit_poll(C)) { return 0; + } return (text->name != NULL && !(text->flags & TXT_ISMEM)); } @@ -532,13 +620,15 @@ static int text_save_as_exec(bContext *C, wmOperator *op) Text *text = CTX_data_edit_text(C); char str[FILE_MAX]; - if (!text) + if (!text) { return OPERATOR_CANCELLED; + } RNA_string_get(op->ptr, "filepath", str); - if (text->name) + if (text->name) { MEM_freeN(text->name); + } text->name = BLI_strdup(str); text->flags &= ~TXT_ISMEM; @@ -556,15 +646,19 @@ static int text_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE Text *text = CTX_data_edit_text(C); const char *str; - if (RNA_struct_property_is_set(op->ptr, "filepath")) + if (RNA_struct_property_is_set(op->ptr, "filepath")) { return text_save_as_exec(C, op); + } - if (text->name) + if (text->name) { str = text->name; - else if (text->flags & TXT_ISMEM) + } + else if (text->flags & TXT_ISMEM) { str = text->id.name + 2; - else + } + else { str = BKE_main_blendfile_path(bmain); + } RNA_string_set(op->ptr, "filepath", str); WM_event_add_fileselect(C, op); @@ -591,7 +685,7 @@ void TEXT_OT_save_as(wmOperatorType *ot) FILE_SAVE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); //XXX TODO, relative_path + FILE_SORT_ALPHA); // XXX TODO, relative_path } /******************* run script operator *********************/ @@ -689,9 +783,10 @@ static int text_refresh_pyconstraints_exec(bContext *UNUSED(C), wmOperator *UNUS for (con = pchan->constraints.first; con; con = con->next) { if (con->type == CONSTRAINT_TYPE_PYTHON) { bPythonConstraint *data = con->data; - if (data->text == text) BPY_pyconstraint_update(ob, con); + if (data->text == text) { + BPY_pyconstraint_update(ob, con); + } update = 1; - } } } @@ -699,7 +794,9 @@ static int text_refresh_pyconstraints_exec(bContext *UNUSED(C), wmOperator *UNUS for (con = ob->constraints.first; con; con = con->next) { if (con->type == CONSTRAINT_TYPE_PYTHON) { bPythonConstraint *data = con->data; - if (data->text == text) BPY_pyconstraint_update(ob, con); + if (data->text == text) { + BPY_pyconstraint_update(ob, con); + } update = 1; } } @@ -737,12 +834,21 @@ static int text_paste_exec(bContext *C, wmOperator *op) buf = WM_clipboard_text_get(selection, &buf_len); - if (!buf) + if (!buf) { return OPERATOR_CANCELLED; + } text_drawcache_tag_update(CTX_wm_space_text(C), 0); TextUndoBuf *utxt = ED_text_undo_push_init(C); + + /* Convert clipboard content indentation to spaces if specified */ + if (text->flags & TXT_TABSTOSPACES) { + char *new_buf = buf_tabs_to_spaces(buf, TXT_TABSIZE); + MEM_freeN(buf); + buf = new_buf; + } + txt_insert_buf(text, utxt, buf); text_update_edited(text); @@ -752,8 +858,9 @@ static int text_paste_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); /* run the script while editing, evil but useful */ - if (CTX_wm_space_text(C)->live_edit) + if (CTX_wm_space_text(C)->live_edit) { text_run_script(C, NULL); + } return OPERATOR_FINISHED; } @@ -821,8 +928,9 @@ static void txt_copy_clipboard(Text *text) { char *buf; - if (!txt_has_sel(text)) + if (!txt_has_sel(text)) { return; + } buf = txt_sel_to_buf(text); @@ -870,8 +978,9 @@ static int text_cut_exec(bContext *C, wmOperator *UNUSED(op)) WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); /* run the script while editing, evil but useful */ - if (CTX_wm_space_text(C)->live_edit) + if (CTX_wm_space_text(C)->live_edit) { text_run_script(C, NULL); + } return OPERATOR_FINISHED; } @@ -994,8 +1103,9 @@ static int text_line_break_exec(bContext *C, wmOperator *UNUSED(op)) } if (text->curl) { - if (text->curl->prev) + if (text->curl->prev) { text_update_line_edited(text->curl->prev); + } text_update_line_edited(text->curl); } @@ -1127,8 +1237,9 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op) flatten_string_free(&fs); MEM_freeN(tmp->line); - if (tmp->format) + if (tmp->format) { MEM_freeN(tmp->format); + } /* Put new_line in the tmp->line spot still need to try and set the curc correctly. */ tmp->line = new_line; @@ -1156,8 +1267,9 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op) /* a + 0 we already know to be ' ' char... */ for (j = 1; (j < tab_len) && (a + j < text_check_line_len) && (text_check_line[a + j] == ' '); - j++) + j++) { ; + } if (j == tab_len) { /* We found a set of spaces that can be replaced by a tab... */ @@ -1200,8 +1312,9 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op) #endif MEM_freeN(tmp->line); - if (tmp->format) + if (tmp->format) { MEM_freeN(tmp->format); + } /* Put new_line in the tmp->line spot * still need to try and set the curc correctly. */ @@ -1341,8 +1454,9 @@ static int move_lines_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); /* run the script while editing, evil but useful */ - if (CTX_wm_space_text(C)->live_edit) + if (CTX_wm_space_text(C)->live_edit) { text_run_script(C, NULL); + } return OPERATOR_FINISHED; } @@ -1431,14 +1545,16 @@ static int text_get_cursor_rel(SpaceText *st, ARegion *ar, TextLine *linein, int if (found) { /* exact cursor position was found, check if it's */ /* still on needed line (hasn't been wrapped) */ - if (selc > endj && !chop) + if (selc > endj && !chop) { selc = endj; + } loop = 0; break; } - if (chop) + if (chop) { endj = j; + } start = end; end += max; @@ -1452,8 +1568,9 @@ static int text_get_cursor_rel(SpaceText *st, ARegion *ar, TextLine *linein, int } } else if (ch == '\0') { - if (!found) + if (!found) { selc = linein->len; + } loop = 0; break; } @@ -1551,8 +1668,9 @@ static int cursor_skip_find_line( *linep = (*linep)->prev; } else { /* moving bottom */ - if (*rell - visible_lines < 0) + if (*rell - visible_lines < 0) { break; + } if (!(*linep)->next) { *rell = visible_lines - 1; @@ -1616,14 +1734,16 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *ar, const bool sel) *charp = endj; if (j >= oldc) { - if (ch == '\0') + if (ch == '\0') { *charp = txt_utf8_column_to_offset((*linep)->line, start); + } loop = 0; break; } - if (chop) + if (chop) { endj = j; + } start = end; end += max; @@ -1644,8 +1764,9 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *ar, const bool sel) } } - if (!sel) + if (!sel) { txt_pop_sel(text); + } } static void txt_wrap_move_eol(SpaceText *st, ARegion *ar, const bool sel) @@ -1694,14 +1815,17 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *ar, const bool sel) if (i + columns - start > max) { end = MIN2(end, i); - if (chop) + if (chop) { endj = BLI_str_prev_char_utf8((*linep)->line + j) - (*linep)->line; + } if (endj >= oldc) { - if (ch == '\0') + if (ch == '\0') { *charp = (*linep)->len; - else + } + else { *charp = endj; + } loop = 0; break; } @@ -1724,8 +1848,9 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *ar, const bool sel) } } - if (!sel) + if (!sel) { txt_pop_sel(text); + } } static void txt_wrap_move_up(SpaceText *st, ARegion *ar, const bool sel) @@ -1764,8 +1889,9 @@ static void txt_wrap_move_up(SpaceText *st, ARegion *ar, const bool sel) } } - if (!sel) + if (!sel) { txt_pop_sel(text); + } } static void txt_wrap_move_down(SpaceText *st, ARegion *ar, const bool sel) @@ -1802,8 +1928,9 @@ static void txt_wrap_move_down(SpaceText *st, ARegion *ar, const bool sel) } } - if (!sel) + if (!sel) { txt_pop_sel(text); + } } /* Moves the cursor vertically by the specified number of lines. @@ -1830,8 +1957,9 @@ static void cursor_skip(SpaceText *st, ARegion *ar, Text *text, int lines, const int rell, relc; /* find line and offsets inside it needed to set cursor position */ - if (cursor_skip_find_line(st, ar, lines, linep, charp, &rell, &relc)) + if (cursor_skip_find_line(st, ar, lines, linep, charp, &rell, &relc)) { *charp = text_get_cursor_rel(st, ar, *linep, rell, relc); + } } else { while (lines > 0 && (*linep)->next) { @@ -1844,11 +1972,13 @@ static void cursor_skip(SpaceText *st, ARegion *ar, Text *text, int lines, const } } - if (*charp > (*linep)->len) + if (*charp > (*linep)->len) { *charp = (*linep)->len; + } - if (!sel) + if (!sel) { txt_pop_sel(text); + } } static int text_move_cursor(bContext *C, int type, bool select) @@ -1858,28 +1988,33 @@ static int text_move_cursor(bContext *C, int type, bool select) ARegion *ar = CTX_wm_region(C); /* ensure we have the right region, it's optional */ - if (ar && ar->regiontype != RGN_TYPE_WINDOW) + if (ar && ar->regiontype != RGN_TYPE_WINDOW) { ar = NULL; + } switch (type) { case LINE_BEGIN: if (!select) { txt_sel_clear(text); } - if (st && st->wordwrap && ar) + if (st && st->wordwrap && ar) { txt_wrap_move_bol(st, ar, select); - else + } + else { txt_move_bol(text, select); + } break; case LINE_END: if (!select) { txt_sel_clear(text); } - if (st && st->wordwrap && ar) + if (st && st->wordwrap && ar) { txt_wrap_move_eol(st, ar, select); - else + } + else { txt_move_eol(text, select); + } break; case FILE_TOP: @@ -1925,31 +2060,39 @@ static int text_move_cursor(bContext *C, int type, bool select) break; case PREV_LINE: - if (st && st->wordwrap && ar) + if (st && st->wordwrap && ar) { txt_wrap_move_up(st, ar, select); - else + } + else { txt_move_up(text, select); + } break; case NEXT_LINE: - if (st && st->wordwrap && ar) + if (st && st->wordwrap && ar) { txt_wrap_move_down(st, ar, select); - else + } + else { txt_move_down(text, select); + } break; case PREV_PAGE: - if (st) + if (st) { cursor_skip(st, ar, st->text, -st->viewlines, select); - else + } + else { cursor_skip(NULL, NULL, text, -10, select); + } break; case NEXT_PAGE: - if (st) + if (st) { cursor_skip(st, ar, st->text, st->viewlines, select); - else + } + else { cursor_skip(NULL, NULL, text, 10, select); + } break; } @@ -2018,12 +2161,15 @@ static int text_jump_exec(bContext *C, wmOperator *op) int line = RNA_int_get(op->ptr, "line"); short nlines = txt_get_span(text->lines.first, text->lines.last) + 1; - if (line < 1) + if (line < 1) { txt_move_toline(text, 1, 0); - else if (line > nlines) + } + else if (line > nlines) { txt_move_toline(text, nlines - 1, 0); - else + } + else { txt_move_toline(text, line - 1, 0); + } text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text); @@ -2076,10 +2222,12 @@ static int text_delete_exec(bContext *C, wmOperator *op) /* behavior could be changed here, * but for now just don't jump words when we have a selection */ if (txt_has_sel(text)) { - if (type == DEL_PREV_WORD) + if (type == DEL_PREV_WORD) { type = DEL_PREV_CHAR; - else if (type == DEL_NEXT_WORD) + } + else if (type == DEL_NEXT_WORD) { type = DEL_NEXT_CHAR; + } } TextUndoBuf *utxt = ED_text_undo_push_init(C); @@ -2135,8 +2283,9 @@ static int text_delete_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); /* run the script while editing, evil but useful */ - if (st->live_edit) + if (st->live_edit) { text_run_script(C, NULL); + } return OPERATOR_FINISHED; } @@ -2246,8 +2395,9 @@ static int text_scroll_exec(bContext *C, wmOperator *op) int lines = RNA_int_get(op->ptr, "lines"); - if (lines == 0) + if (lines == 0) { return OPERATOR_CANCELLED; + } txt_screen_skip(st, ar, lines * U.wheellinescroll); @@ -2304,8 +2454,9 @@ static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event) } else { st->left += scroll_steps[0]; - if (st->left < 0) + if (st->left < 0) { st->left = 0; + } } ED_area_tag_redraw(CTX_wm_area(C)); @@ -2331,8 +2482,9 @@ static int text_scroll_modal(bContext *C, wmOperator *op, const wmEvent *event) switch (event->type) { case MOUSEMOVE: - if (tsc->zone == SCROLLHANDLE_BAR) + if (tsc->zone == SCROLLHANDLE_BAR) { text_scroll_apply(C, op, event); + } break; case LEFTMOUSE: case RIGHTMOUSE: @@ -2362,8 +2514,9 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, const wmEvent *event) SpaceText *st = CTX_wm_space_text(C); TextScroll *tsc; - if (RNA_struct_property_is_set(op->ptr, "lines")) + if (RNA_struct_property_is_set(op->ptr, "lines")) { return text_scroll_exec(C, op); + } tsc = MEM_callocN(sizeof(TextScroll), "TextScroll"); tsc->first = 1; @@ -2425,11 +2578,13 @@ static bool text_region_scroll_poll(bContext *C) Text *text = CTX_data_edit_text(C); ARegion *ar = CTX_wm_region(C); - if (!st || !text) + if (!st || !text) { return 0; + } - if (!ar || ar->regiontype != RGN_TYPE_WINDOW) + if (!ar || ar->regiontype != RGN_TYPE_WINDOW) { return 0; + } return 1; } @@ -2442,8 +2597,9 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *ev const int *mval = event->mval; int zone = -1; - if (RNA_struct_property_is_set(op->ptr, "lines")) + if (RNA_struct_property_is_set(op->ptr, "lines")) { return text_scroll_exec(C, op); + } /* verify we are in the right zone */ if (mval[0] > st->txtbar.xmin && mval[0] < st->txtbar.xmax) { @@ -2452,10 +2608,12 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *ev zone = SCROLLHANDLE_BAR; } else if (mval[1] > TXT_SCROLL_SPACE && mval[1] < ar->winy - TXT_SCROLL_SPACE) { - if (mval[1] < st->txtbar.ymin) + if (mval[1] < st->txtbar.ymin) { zone = SCROLLHANDLE_MIN_OUTSIDE; - else + } + else { zone = SCROLLHANDLE_MAX_OUTSIDE; + } } } @@ -2539,13 +2697,16 @@ static int flatten_column_to_offset(SpaceText *st, const char *str, int index) int i = 0, j = 0, col; while (*(str + j)) { - if (str[j] == '\t') + if (str[j] == '\t') { col = st->tabnumber - i % st->tabnumber; - else + } + else { col = BLI_str_utf8_char_width_safe(str + j); + } - if (i + col > index) + if (i + col > index) { break; + } i += col; j += BLI_str_utf8_size_safe(str + j); @@ -2632,18 +2793,21 @@ static void text_cursor_set_to_pos_wrapped( if (found) { /* exact cursor position was found, check if it's still on needed line * (hasn't been wrapped) */ - if (charp > endj && !chop && ch != '\0') + if (charp > endj && !chop && ch != '\0') { charp = endj; + } break; } - if (chop) + if (chop) { endj = j; + } start = end; end += max; - if (j < linep->len) + if (j < linep->len) { y--; + } chop = true; if (y == 0 && i + columns - start > x) { @@ -2704,13 +2868,16 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, con text_update_character_width(st); y = (ar->winy - 2 - y) / (st->lheight_dpi + TXT_LINE_SPACING); - if (st->showlinenrs) + if (st->showlinenrs) { x -= TXT_OFFSET + TEXTXLOC; - else + } + else { x -= TXT_OFFSET; + } - if (x < 0) + if (x < 0) { x = 0; + } x = text_pixel_x_to_column(st, x) + st->left; if (st->wordwrap) { @@ -2734,25 +2901,30 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, con if (y > 0) { while (y-- != 0) { - if ((*linep)->next) + if ((*linep)->next) { *linep = (*linep)->next; + } } } else if (y < 0) { while (y++ != 0) { - if ((*linep)->prev) + if ((*linep)->prev) { *linep = (*linep)->prev; + } } } w = flatten_width(st, (*linep)->line); - if (x < w) + if (x < w) { *charp = flatten_column_to_offset(st, (*linep)->line, x); - else + } + else { *charp = (*linep)->len; + } } - if (!sel) + if (!sel) { txt_pop_sel(text); + } } static void text_cursor_timer_ensure(bContext *C, SetSelection *ssel) @@ -2839,8 +3011,9 @@ static int text_set_selection_invoke(bContext *C, wmOperator *op, const wmEvent SpaceText *st = CTX_wm_space_text(C); SetSelection *ssel; - if (event->mval[0] >= st->txtbar.xmin) + if (event->mval[0] >= st->txtbar.xmin) { return OPERATOR_PASS_THROUGH; + } op->customdata = MEM_callocN(sizeof(SetSelection), "SetCursor"); ssel = op->customdata; @@ -2919,8 +3092,9 @@ static int text_cursor_set_invoke(bContext *C, wmOperator *op, const wmEvent *ev { SpaceText *st = CTX_wm_space_text(C); - if (event->mval[0] >= st->txtbar.xmin) + if (event->mval[0] >= st->txtbar.xmin) { return OPERATOR_PASS_THROUGH; + } RNA_int_set(op->ptr, "x", event->mval[0]); RNA_int_set(op->ptr, "y", event->mval[1]); @@ -2959,18 +3133,23 @@ static int text_line_number_invoke(bContext *C, wmOperator *UNUSED(op), const wm text_update_character_width(st); - if (!st->showlinenrs) + if (!st->showlinenrs) { return OPERATOR_PASS_THROUGH; + } - if (!(mval[0] > 2 && mval[0] < (TXT_OFFSET + TEXTXLOC) && mval[1] > 2 && mval[1] < ar->winy - 2)) + if (!(mval[0] > 2 && mval[0] < (TXT_OFFSET + TEXTXLOC) && mval[1] > 2 && + mval[1] < ar->winy - 2)) { return OPERATOR_PASS_THROUGH; + } - if (!(event->ascii >= '0' && event->ascii <= '9')) + if (!(event->ascii >= '0' && event->ascii <= '9')) { return OPERATOR_PASS_THROUGH; + } time = PIL_check_seconds_timer(); - if (last_jump < time - 1) + if (last_jump < time - 1) { jump_to = 0; + } jump_to *= 10; jump_to += (int)(event->ascii - '0'); @@ -3028,8 +3207,9 @@ static int text_insert_exec(bContext *C, wmOperator *op) MEM_freeN(str); - if (!done) + if (!done) { return OPERATOR_CANCELLED; + } text_update_line_edited(text->curl); @@ -3072,8 +3252,9 @@ static int text_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event) ret = text_insert_exec(C, op); /* run the script while editing, evil but useful */ - if (ret == OPERATOR_FINISHED && CTX_wm_space_text(C)->live_edit) + if (ret == OPERATOR_FINISHED && CTX_wm_space_text(C)->live_edit) { text_run_script(C, NULL); + } return ret; } @@ -3116,21 +3297,25 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode) int found = 0; char *tmp; - if (!st->findstr[0]) + if (!st->findstr[0]) { return OPERATOR_CANCELLED; + } flags = st->flags; - if (flags & ST_FIND_ALL) + if (flags & ST_FIND_ALL) { flags &= ~ST_FIND_WRAP; + } /* Replace current */ if (mode != TEXT_FIND && txt_has_sel(text)) { tmp = txt_sel_to_buf(text); - if (flags & ST_MATCH_CASE) + if (flags & ST_MATCH_CASE) { found = STREQ(st->findstr, tmp); - else + } + else { found = BLI_strcasecmp(st->findstr, tmp) == 0; + } if (found) { if (mode == TEXT_REPLACE) { @@ -3155,17 +3340,20 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode) WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text); } else if (flags & ST_FIND_ALL) { - if (text->id.next) + if (text->id.next) { text = st->text = text->id.next; - else + } + else { text = st->text = bmain->texts.first; + } txt_move_toline(text, 0, 0); text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text); } else { - if (!found) + if (!found) { BKE_reportf(op->reports, RPT_ERROR, "Text not found: %s", st->findstr); + } } return OPERATOR_FINISHED; @@ -3222,8 +3410,9 @@ static int text_find_set_selected_exec(bContext *C, wmOperator *op) BLI_strncpy(st->findstr, tmp, ST_MAX_FIND_STR); MEM_freeN(tmp); - if (!st->findstr[0]) + if (!st->findstr[0]) { return OPERATOR_FINISHED; + } return text_find_and_replace(C, op, TEXT_FIND); } diff --git a/source/blender/editors/space_topbar/CMakeLists.txt b/source/blender/editors/space_topbar/CMakeLists.txt index 71e61a07ff7..d56e1da334d 100644 --- a/source/blender/editors/space_topbar/CMakeLists.txt +++ b/source/blender/editors/space_topbar/CMakeLists.txt @@ -25,8 +25,8 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/space_topbar/space_topbar.c b/source/blender/editors/space_topbar/space_topbar.c index 46a86bcbc86..8b290009a97 100644 --- a/source/blender/editors/space_topbar/space_topbar.c +++ b/source/blender/editors/space_topbar/space_topbar.c @@ -71,10 +71,6 @@ static SpaceLink *topbar_new(const ScrArea *UNUSED(area), const Scene *UNUSED(sc ar->alignment = RGN_ALIGN_RIGHT | RGN_SPLIT_PREV; /* main regions */ - ar = MEM_callocN(sizeof(ARegion), "right aligned main region for topbar"); - BLI_addtail(&stopbar->regionbase, ar); - ar->regiontype = RGN_TYPE_WINDOW; - ar->alignment = RGN_ALIGN_RIGHT; ar = MEM_callocN(sizeof(ARegion), "main region of topbar"); BLI_addtail(&stopbar->regionbase, ar); ar->regiontype = RGN_TYPE_WINDOW; diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt index 279c6913064..dc375958eb4 100644 --- a/source/blender/editors/space_view3d/CMakeLists.txt +++ b/source/blender/editors/space_view3d/CMakeLists.txt @@ -28,10 +28,10 @@ set(INC ../../makesdna ../../makesrna ../../render/extern/include - ../../windowmanager ../../depsgraph - ../../../../intern/guardedalloc + ../../windowmanager ../../../../intern/glew-mx + ../../../../intern/guardedalloc ../../../../intern/smoke/extern ) @@ -64,7 +64,6 @@ set(SRC view3d_project.c view3d_select.c view3d_snap.c - view3d_toolbar.c view3d_utils.c view3d_view.c view3d_walk.c diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index c304642c4c3..638c77fc3cb 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -348,51 +348,6 @@ void draw_object_select_id(Depsgraph *depsgraph, GPU_matrix_set(rv3d->viewmat); } -void draw_object_depth(RegionView3D *rv3d, Object *ob) -{ - GPU_matrix_mul(ob->obmat); - GPU_depth_test(true); - - const float(*world_clip_planes)[4] = NULL; - if (rv3d->rflag & RV3D_CLIPPING) { - ED_view3d_clipping_local(rv3d, ob->obmat); - world_clip_planes = rv3d->clip_local; - } - - switch (ob->type) { - case OB_MESH: { - GPUBatch *batch; - - Mesh *me = ob->data; - - if (ob->mode & OB_MODE_EDIT) { - batch = DRW_mesh_batch_cache_get_edit_triangles(me); - } - else { - batch = DRW_mesh_batch_cache_get_surface(me); - } - - DRW_mesh_batch_cache_create_requested(ob, me, NULL, false, true); - - DRW_opengl_context_enable(); - const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : - GPU_SHADER_CFG_DEFAULT; - GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_DEPTH_ONLY, sh_cfg); - if (world_clip_planes != NULL) { - bbs_world_clip_planes_from_rv3d(batch, world_clip_planes); - } - - GPU_batch_draw(batch); - DRW_opengl_context_disable(); - } break; - case OB_CURVE: - case OB_SURF: - break; - } - - GPU_matrix_set(rv3d->viewmat); -} - void ED_draw_object_facemap(Depsgraph *depsgraph, Object *ob, const float col[4], diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 434f379c6fe..9ee7bb3066d 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -82,75 +82,6 @@ /* ******************** manage regions ********************* */ -ARegion *view3d_has_buttons_region(ScrArea *sa) -{ - ARegion *ar, *arnew; - - ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); - if (ar) { - return ar; - } - - /* add subdiv level; after header */ - ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); - - /* is error! */ - if (ar == NULL) { - return NULL; - } - - arnew = MEM_callocN(sizeof(ARegion), "buttons for view3d"); - - BLI_insertlinkafter(&sa->regionbase, ar, arnew); - arnew->regiontype = RGN_TYPE_UI; - arnew->alignment = RGN_ALIGN_RIGHT; - - arnew->flag = RGN_FLAG_HIDDEN; - - return arnew; -} - -ARegion *view3d_has_tools_region(ScrArea *sa) -{ - ARegion *ar, *artool = NULL, *arhead; - - for (ar = sa->regionbase.first; ar; ar = ar->next) { - if (ar->regiontype == RGN_TYPE_TOOLS) { - artool = ar; - } - } - - /* tool region hide/unhide also hides props */ - if (artool) { - return artool; - } - - if (artool == NULL) { - /* add subdiv level; after header */ - for (arhead = sa->regionbase.first; arhead; arhead = arhead->next) { - if (arhead->regiontype == RGN_TYPE_HEADER) { - break; - } - } - - /* is error! */ - if (arhead == NULL) { - return NULL; - } - - artool = MEM_callocN(sizeof(ARegion), "tools for view3d"); - - BLI_insertlinkafter(&sa->regionbase, arhead, artool); - artool->regiontype = RGN_TYPE_TOOLS; - artool->alignment = RGN_ALIGN_LEFT; - artool->flag = RGN_FLAG_HIDDEN; - } - - return artool; -} - -/* ****************************************************** */ - /* function to always find a regionview3d context inside 3D window */ RegionView3D *ED_view3d_context_rv3d(bContext *C) { @@ -331,13 +262,17 @@ static SpaceLink *view3d_new(const ScrArea *UNUSED(sa), const Scene *scene) v3d->overlay.texture_paint_mode_opacity = 1.0f; v3d->overlay.weight_paint_mode_opacity = 1.0f; v3d->overlay.vertex_paint_mode_opacity = 1.0f; + /* Intentionally different to vertex/paint mode, + * we typically want to see shading too. */ + v3d->overlay.sculpt_mode_mask_opacity = 0.75f; + v3d->overlay.edit_flag = V3D_OVERLAY_EDIT_FACES | V3D_OVERLAY_EDIT_SEAMS | V3D_OVERLAY_EDIT_SHARP | V3D_OVERLAY_EDIT_FREESTYLE_EDGE | V3D_OVERLAY_EDIT_FREESTYLE_FACE | V3D_OVERLAY_EDIT_EDGES | V3D_OVERLAY_EDIT_CREASES | V3D_OVERLAY_EDIT_BWEIGHTS | V3D_OVERLAY_EDIT_CU_HANDLES | V3D_OVERLAY_EDIT_CU_NORMALS; - v3d->gridflag = V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_FLOOR; + v3d->gridflag = V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_FLOOR | V3D_SHOW_ORTHO_GRID; v3d->flag = V3D_SELECT_OUTLINE; v3d->flag2 = V3D_SHOW_RECONSTRUCTION | V3D_SHOW_ANNOTATION; @@ -362,6 +297,14 @@ static SpaceLink *view3d_new(const ScrArea *UNUSED(sa), const Scene *scene) v3d->vertex_opacity = 1.0f; v3d->gp_flag |= V3D_GP_SHOW_EDIT_LINES; + /* tool header */ + ar = MEM_callocN(sizeof(ARegion), "tool header for view3d"); + + BLI_addtail(&v3d->regionbase, ar); + ar->regiontype = RGN_TYPE_TOOL_HEADER; + ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP; + ar->flag = RGN_FLAG_HIDDEN | RGN_FLAG_HIDDEN_BY_USER; + /* header */ ar = MEM_callocN(sizeof(ARegion), "header for view3d"); @@ -1189,6 +1132,34 @@ static void view3d_header_region_listener(wmWindow *UNUSED(win), } break; } + + /* From topbar, which ones are needed? split per header? */ + /* Disable for now, re-enable if neede, or remove - campbell. */ +#if 0 + /* context changes */ + switch (wmn->category) { + case NC_WM: + if (wmn->data == ND_HISTORY) { + ED_region_tag_redraw(ar); + } + break; + case NC_SCENE: + if (wmn->data == ND_MODE) { + ED_region_tag_redraw(ar); + } + break; + case NC_SPACE: + if (wmn->data == ND_SPACE_VIEW3D) { + ED_region_tag_redraw(ar); + } + break; + case NC_GPENCIL: + if (wmn->data == ND_DATA) { + ED_region_tag_redraw(ar); + } + break; + } +#endif } static void view3d_header_region_message_subscribe(const struct bContext *UNUSED(C), @@ -1558,6 +1529,17 @@ void ED_spacetype_view3d(void) art->draw = view3d_tools_region_draw; BLI_addhead(&st->regiontypes, art); + /* regions: tool header */ + art = MEM_callocN(sizeof(ARegionType), "spacetype view3d tool header region"); + art->regionid = RGN_TYPE_TOOL_HEADER; + art->prefsizey = HEADERY; + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER; + art->listener = view3d_header_region_listener; + art->init = view3d_header_region_init; + art->draw = view3d_header_region_draw; + art->message_subscribe = view3d_header_region_message_subscribe; + BLI_addhead(&st->regiontypes, art); + /* regions: header */ art = MEM_callocN(sizeof(ARegionType), "spacetype view3d header region"); art->regionid = RGN_TYPE_HEADER; @@ -1566,7 +1548,7 @@ void ED_spacetype_view3d(void) art->listener = view3d_header_region_listener; art->init = view3d_header_region_init; art->draw = view3d_header_region_draw; - art->message_subscribe = view3d_header_region_message_subscribe; + art->message_subscribe = ED_area_do_mgs_subscribe_for_tool_header; BLI_addhead(&st->regiontypes, art); /* regions: hud */ diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c index abe36b1d563..3d3c73ad27c 100644 --- a/source/blender/editors/space_view3d/view3d_buttons.c +++ b/source/blender/editors/space_view3d/view3d_buttons.c @@ -147,9 +147,11 @@ static float compute_scale_factor(const float ve_median, const float median) } } -/* Apply helpers. - * Note: In case we only have one element, copy directly the value instead of applying the diff or scale factor. - * Avoids some glitches when going e.g. from 3 to 0.0001 (see T37327). +/** + * Apply helpers. + * \note In case we only have one element, + * copy directly the value instead of applying the diff or scale factor. + * Avoids some glitches when going e.g. from 3 to 0.0001 (see T37327). */ static void apply_raw_diff(float *val, const int tot, const float ve_median, const float median) { @@ -1064,7 +1066,7 @@ static void v3d_object_dimension_buts(bContext *C, uiLayout *layout, View3D *v3d 0, ""); UI_block_align_begin(block); - const float lim = 10000; + const float lim = FLT_MAX; for (int i = 0; i < 3; i++) { uiBut *but; char text[3] = {'X' + i, ':', '\0'}; @@ -1603,7 +1605,7 @@ void view3d_buttons_register(ARegionType *art) pt = MEM_callocN(sizeof(PanelType), "spacetype view3d panel object"); strcpy(pt->idname, "VIEW3D_PT_transform"); strcpy(pt->label, N_("Transform")); /* XXX C panels unavailable through RNA bpy.types! */ - strcpy(pt->category, "View"); + strcpy(pt->category, "Item"); strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); pt->draw = view3d_panel_transform; pt->poll = view3d_panel_transform_poll; @@ -1612,7 +1614,7 @@ void view3d_buttons_register(ARegionType *art) pt = MEM_callocN(sizeof(PanelType), "spacetype view3d panel vgroup"); strcpy(pt->idname, "VIEW3D_PT_vgroup"); strcpy(pt->label, N_("Vertex Weights")); /* XXX C panels unavailable through RNA bpy.types! */ - strcpy(pt->category, "View"); + strcpy(pt->category, "Item"); strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); pt->draw = view3d_panel_vgroup; pt->poll = view3d_panel_vgroup_poll; @@ -1628,31 +1630,6 @@ void view3d_buttons_register(ARegionType *art) WM_menutype_add(mt); } -static int view3d_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = view3d_has_buttons_region(sa); - - if (ar) { - ED_region_toggle_hidden(C, ar); - } - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_properties(wmOperatorType *ot) -{ - ot->name = "Toggle Sidebar"; - ot->description = "Toggle the properties region visibility"; - ot->idname = "VIEW3D_OT_properties"; - - ot->exec = view3d_properties_toggle_exec; - ot->poll = ED_operator_view3d_active; - - /* flags */ - ot->flag = 0; -} - static int view3d_object_mode_menu(bContext *C, wmOperator *op) { Object *ob = CTX_data_active_object(C); diff --git a/source/blender/editors/space_view3d/view3d_camera_control.c b/source/blender/editors/space_view3d/view3d_camera_control.c index c8059c25e15..0045094542f 100644 --- a/source/blender/editors/space_view3d/view3d_camera_control.c +++ b/source/blender/editors/space_view3d/view3d_camera_control.c @@ -23,10 +23,11 @@ * or other details. * Typical view-control usage: * - * - acquire a view-control (#ED_view3d_cameracontrol_acquire). - * - modify ``rv3d->ofs``, ``rv3d->viewquat``. - * - update the view data (#ED_view3d_cameracontrol_acquire) - within a loop which draws the viewport. - * - finish and release the view-control (#ED_view3d_cameracontrol_release), + * - Acquire a view-control (#ED_view3d_cameracontrol_acquire). + * - Modify ``rv3d->ofs``, ``rv3d->viewquat``. + * - Update the view data (#ED_view3d_cameracontrol_acquire) - + * within a loop which draws the viewport. + * - Finish and release the view-control (#ED_view3d_cameracontrol_release), * either keeping the current view or restoring the initial view. * * Notes: diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 4610111aafa..8c5f1c16438 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -700,7 +700,8 @@ static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *ar, View /* draw */ immUniformThemeColorShade(TH_VIEW_OVERLAY, 100); - /* TODO Was using UI_draw_roundbox_4fv(false, rect.xmin, rect.ymin, rect.xmax, rect.ymax, 2.0f, color). + /* TODO Was using: + * UI_draw_roundbox_4fv(false, rect.xmin, rect.ymin, rect.xmax, rect.ymax, 2.0f, color); * We'll probably need a new imm_draw_line_roundbox_dashed dor that - though in practice the * 2.0f round corner effect was nearly not visible anyway... */ imm_draw_box_wire_2d(shdr_pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax); @@ -757,7 +758,6 @@ void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *ar, View3D *v3d, bool a short flag = v3d->flag; float glalphaclip = U.glalphaclip; - int obcenter_dia = U.obcenter_dia; /* temp set drawtype to solid */ /* Setting these temporarily is not nice */ v3d->flag &= ~V3D_SELECT_OUTLINE; @@ -765,8 +765,6 @@ void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *ar, View3D *v3d, bool a /* not that nice but means we wont zoom into billboards */ U.glalphaclip = alphaoverride ? 0.5f : glalphaclip; - U.obcenter_dia = 0; - /* Tools may request depth outside of regular drawing code. */ UI_Theme_Store(&theme_state); UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW); @@ -796,7 +794,6 @@ void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *ar, View3D *v3d, bool a U.glalphaclip = glalphaclip; v3d->flag = flag; - U.obcenter_dia = obcenter_dia; UI_Theme_Restore(&theme_state); } @@ -967,7 +964,7 @@ static void draw_rotation_guide(const RegionView3D *rv3d) immVertex3fv(pos, end); # if 0 - color[3] = 0.2f + fabsf(rv3d->rot_angle); /* modulate opacity with angle */ + color[3] = 0.2f + fabsf(rv3d->rot_angle); /* modulate opacity with angle */ /* ^^ neat idea, but angle is frame-rate dependent, so it's usually close to 0.2 */ # endif @@ -1450,6 +1447,7 @@ void view3d_main_region_draw(const bContext *C, ARegion *ar) view3d_draw_view(C, ar); + DRW_cache_free_old_batches(bmain); GPU_free_images_old(bmain); GPU_pass_cache_garbage_collect(); @@ -1822,6 +1820,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph, */ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Depsgraph *depsgraph, Scene *scene, + View3DShading *shading_override, int drawtype, Object *camera, int width, @@ -1844,22 +1843,25 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Depsgraph *depsgraph, ar.regiontype = RGN_TYPE_WINDOW; v3d.camera = camera; + View3DShading *source_shading_settings = &scene->display.shading; + if (draw_flags & V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS && shading_override != NULL) { + source_shading_settings = shading_override; + } + memcpy(&v3d.shading, source_shading_settings, sizeof(View3DShading)); v3d.shading.type = drawtype; + + if (drawtype == OB_MATERIAL) { + v3d.shading.flag = V3D_SHADING_SCENE_WORLD | V3D_SHADING_SCENE_LIGHTS; + } + v3d.flag2 = V3D_HIDE_OVERLAYS; - if (draw_flags & V3D_OFSDRAW_USE_GPENCIL) { + if (draw_flags & V3D_OFSDRAW_SHOW_ANNOTATION) { v3d.flag2 |= V3D_SHOW_ANNOTATION; } v3d.shading.background_type = V3D_SHADING_BACKGROUND_WORLD; - if (draw_flags & V3D_OFSDRAW_USE_CAMERA_DOF) { - if (camera->type == OB_CAMERA) { - v3d.fx_settings.dof = &((Camera *)camera->data)->gpu_dof; - v3d.fx_settings.fx_flag |= GPU_FX_FLAG_DOF; - } - } - rv3d.persp = RV3D_CAMOB; copy_m4_m4(rv3d.viewinv, v3d.camera->obmat); diff --git a/source/blender/editors/space_view3d/view3d_draw_legacy.c b/source/blender/editors/space_view3d/view3d_draw_legacy.c index 85bc0fba36b..b0cee18f8e3 100644 --- a/source/blender/editors/space_view3d/view3d_draw_legacy.c +++ b/source/blender/editors/space_view3d/view3d_draw_legacy.c @@ -219,12 +219,6 @@ static void validate_object_select_id(struct Depsgraph *depsgraph, G.f &= ~G_FLAG_BACKBUFSEL; } -void view3d_opengl_read_pixels( - ARegion *ar, int x, int y, int w, int h, int format, int type, void *data) -{ - glReadPixels(ar->winrct.xmin + x, ar->winrct.ymin + y, w, h, format, type, data); -} - /* TODO: Creating, attaching texture, and destroying a framebuffer is quite slow. * Calling this function should be avoided during interactive drawing. */ static void view3d_opengl_read_Z_pixels(GPUViewport *viewport, rcti *rect, void *data) @@ -234,7 +228,6 @@ static void view3d_opengl_read_Z_pixels(GPUViewport *viewport, rcti *rect, void GPUFrameBuffer *tmp_fb = GPU_framebuffer_create(); GPU_framebuffer_texture_attach(tmp_fb, dtxl->depth, 0, 0); GPU_framebuffer_bind(tmp_fb); - glDisable(GL_SCISSOR_TEST); glReadPixels(rect->xmin, rect->ymin, @@ -244,9 +237,7 @@ static void view3d_opengl_read_Z_pixels(GPUViewport *viewport, rcti *rect, void GL_FLOAT, data); - glEnable(GL_SCISSOR_TEST); GPU_framebuffer_restore(); - GPU_framebuffer_free(tmp_fb); } @@ -269,29 +260,11 @@ void ED_view3d_backbuf_depth_validate(ViewContext *vc) { if (vc->v3d->flag & V3D_INVALID_BACKBUF) { ARegion *ar = vc->ar; - RegionView3D *rv3d = ar->regiondata; Object *obact_eval = DEG_get_evaluated_object(vc->depsgraph, vc->obact); if (obact_eval && ((obact_eval->base_flag & BASE_VISIBLE) != 0)) { - GPU_scissor(ar->winrct.xmin, - ar->winrct.ymin, - BLI_rcti_size_x(&ar->winrct), - BLI_rcti_size_y(&ar->winrct)); - - GPU_depth_test(true); - GPU_clear(GPU_DEPTH_BIT); - - if (rv3d->rflag & RV3D_CLIPPING) { - ED_view3d_clipping_set(rv3d); - } - - draw_object_depth(rv3d, obact_eval); - - if (rv3d->rflag & RV3D_CLIPPING) { - ED_view3d_clipping_disable(); - } - - GPU_depth_test(false); + GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0); + DRW_draw_depth_object(vc->ar, viewport, obact_eval); } vc->v3d->flag &= ~V3D_INVALID_BACKBUF; @@ -374,7 +347,7 @@ uint ED_view3d_select_id_read_nearest(struct ViewContext *UNUSED(vc), uint *r_dist) { /* Create region around mouse cursor. This must be square and have an odd - * width, the spiralling algorithm does not work with arbitrary rectangles. */ + * width, the spiraling algorithm does not work with arbitrary rectangles. */ rcti rect; BLI_rcti_init_pt_radius(&rect, mval, *r_dist); rect.xmax += 1; @@ -855,9 +828,15 @@ void ED_view3d_depth_update(ARegion *ar) } if (d->damaged) { - view3d_opengl_read_pixels(ar, 0, 0, d->w, d->h, GL_DEPTH_COMPONENT, GL_FLOAT, d->depths); + GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0); + rcti r = { + .xmin = 0, + .xmax = d->w, + .ymin = 0, + .ymax = d->h, + }; + view3d_opengl_read_Z_pixels(viewport, &r, d->depths); glGetDoublev(GL_DEPTH_RANGE, d->depth_range); - d->damaged = false; } } @@ -943,7 +922,8 @@ void ED_view3d_screen_datamask(const bContext *C, /** * Store values from #RegionView3D, set when drawing. - * This is needed when we draw with to a viewport using a different matrix (offscreen drawing for example). + * This is needed when we draw with to a viewport using a different matrix + * (offscreen drawing for example). * * Values set by #ED_view3d_update_viewmat should be handled here. */ @@ -1015,8 +995,8 @@ void ED_scene_draw_fps(Scene *scene, int xoffset, int *yoffset) if (tot) { fpsi->redrawtime_index = (fpsi->redrawtime_index + 1) % REDRAW_FRAME_AVERAGE; - //fpsi->redrawtime_index++; - //if (fpsi->redrawtime >= REDRAW_FRAME_AVERAGE) { + // fpsi->redrawtime_index++; + // if (fpsi->redrawtime >= REDRAW_FRAME_AVERAGE) { // fpsi->redrawtime = 0; //} diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 1d2d361d868..80153a38128 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -1046,7 +1046,8 @@ static float view3d_ndof_pan_speed_calc(RegionView3D *rv3d) /** * Zoom and pan in the same function since sometimes zoom is interpreted as dolly (pan forward). * - * \param has_zoom: zoom, otherwise dolly, often `!rv3d->is_persp` since it doesn't make sense to dolly in ortho. + * \param has_zoom: zoom, otherwise dolly, + * often `!rv3d->is_persp` since it doesn't make sense to dolly in ortho. */ static void view3d_ndof_pan_zoom(const struct wmNDOFMotionData *ndof, ScrArea *sa, @@ -1068,9 +1069,8 @@ static void view3d_ndof_pan_zoom(const struct wmNDOFMotionData *ndof, /* zoom with Z */ /* Zoom! - * velocity should be proportional to the linear velocity attained by rotational motion of same strength - * [got that?] - * proportional to arclength = radius * angle + * velocity should be proportional to the linear velocity attained by rotational motion + * of same strength [got that?] proportional to `arclength = radius * angle`. */ pan_vec[2] = 0.0f; @@ -1646,7 +1646,8 @@ void viewmove_modal_keymap(wmKeyConfig *keyconf) #if 0 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM); WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM); - WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE); + WM_modalkeymap_add_item( + keymap, LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE); #endif /* assign map to operators */ @@ -1843,7 +1844,8 @@ void viewzoom_modal_keymap(wmKeyConfig *keyconf) } /** - * \param zoom_xy: Optionally zoom to window location (coords compatible w/ #wmEvent.x, y). Use when not NULL. + * \param zoom_xy: Optionally zoom to window location + * (coords compatible w/ #wmEvent.x, y). Use when not NULL. */ static void view_zoom_to_window_xy_camera( Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *ar, float dfac, const int zoom_xy[2]) @@ -1891,7 +1893,8 @@ static void view_zoom_to_window_xy_camera( } /** - * \param zoom_xy: Optionally zoom to window location (coords compatible w/ #wmEvent.x, y). Use when not NULL. + * \param zoom_xy: Optionally zoom to window location + * (coords compatible w/ #wmEvent.x, y). Use when not NULL. */ static void view_zoom_to_window_xy_3d(ARegion *ar, float dfac, const int zoom_xy[2]) { diff --git a/source/blender/editors/space_view3d/view3d_gizmo_armature.c b/source/blender/editors/space_view3d/view3d_gizmo_armature.c index ae186505456..3ea127b364f 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_armature.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_armature.c @@ -85,13 +85,13 @@ static void gizmo_bbone_offset_get(const wmGizmo *UNUSED(gz), if (bh->index == 0) { bh->co[1] = pchan->bone->ease1 / BBONE_SCALE_Y; - bh->co[0] = pchan->curveInX; - bh->co[2] = pchan->curveInY; + bh->co[0] = pchan->curve_in_x; + bh->co[2] = pchan->curve_in_y; } else { bh->co[1] = -pchan->bone->ease2 / BBONE_SCALE_Y; - bh->co[0] = pchan->curveOutX; - bh->co[2] = pchan->curveOutY; + bh->co[0] = pchan->curve_out_x; + bh->co[2] = pchan->curve_out_y; } copy_v3_v3(value, bh->co); } @@ -110,13 +110,13 @@ static void gizmo_bbone_offset_set(const wmGizmo *UNUSED(gz), if (bh->index == 0) { pchan->bone->ease1 = max_ff(0.0f, bh->co[1] * BBONE_SCALE_Y); - pchan->curveInX = bh->co[0]; - pchan->curveInY = bh->co[2]; + pchan->curve_in_x = bh->co[0]; + pchan->curve_in_y = bh->co[2]; } else { pchan->bone->ease2 = max_ff(0.0f, -bh->co[1] * BBONE_SCALE_Y); - pchan->curveOutX = bh->co[0]; - pchan->curveOutY = bh->co[2]; + pchan->curve_out_x = bh->co[0]; + pchan->curve_out_y = bh->co[2]; } } diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c index f98a87e84a8..5af6fd8b04b 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c @@ -259,8 +259,7 @@ static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *g navgroup->state.rv3d.is_camera = (rv3d->persp == RV3D_CAMOB); navgroup->state.rv3d.viewlock = rv3d->viewlock; - const bool show_rotate = (((rv3d->viewlock & RV3D_LOCKED) == 0) && - (navgroup->state.rv3d.is_camera == false)); + const bool show_rotate = (rv3d->viewlock & RV3D_LOCKED) == 0; const bool show_fixed_offset = navgroup->state.rv3d.is_camera; const float icon_size = GIZMO_SIZE; const float icon_offset = (icon_size * 0.52f) * GIZMO_OFFSET_FAC * UI_DPI_FAC; diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index fd306619577..9075909a6fe 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -134,8 +134,6 @@ void draw_object_select_id(struct Depsgraph *depsgraph, struct Object *ob, short select_mode); -void draw_object_depth(RegionView3D *rv3d, struct Object *ob); - int view3d_effective_drawtype(const struct View3D *v3d); /* view3d_draw.c */ @@ -234,7 +232,6 @@ void viewzoom_modal_keymap(struct wmKeyConfig *keyconf); void viewdolly_modal_keymap(struct wmKeyConfig *keyconf); /* view3d_buttons.c */ -void VIEW3D_OT_properties(struct wmOperatorType *ot); void VIEW3D_OT_object_mode_pie_or_toggle(struct wmOperatorType *ot); void view3d_buttons_register(struct ARegionType *art); @@ -267,9 +264,6 @@ void VIEW3D_OT_snap_cursor_to_selected(struct wmOperatorType *ot); void VIEW3D_OT_snap_cursor_to_active(struct wmOperatorType *ot); /* space_view3d.c */ -struct ARegion *view3d_has_buttons_region(struct ScrArea *sa); -struct ARegion *view3d_has_tools_region(struct ScrArea *sa); - extern const char *view3d_context_dir[]; /* doc access */ /* view3d_widgets.c */ diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index 4e33005ebc0..e5a145b0411 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -199,9 +199,7 @@ void view3d_operatortypes(void) WM_operatortype_append(VIEW3D_OT_copybuffer); WM_operatortype_append(VIEW3D_OT_pastebuffer); - WM_operatortype_append(VIEW3D_OT_properties); WM_operatortype_append(VIEW3D_OT_object_mode_pie_or_toggle); - WM_operatortype_append(VIEW3D_OT_toolshelf); WM_operatortype_append(VIEW3D_OT_snap_selected_to_grid); WM_operatortype_append(VIEW3D_OT_snap_selected_to_cursor); diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c index 6932e94e78d..b81b7e0109e 100644 --- a/source/blender/editors/space_view3d/view3d_project.c +++ b/source/blender/editors/space_view3d/view3d_project.c @@ -455,7 +455,8 @@ bool ED_view3d_win_to_ray_clipped(struct Depsgraph *depsgraph, * \param r_ray_start: The world-space point where the ray intersects the window plane. * \param r_ray_normal: The normalized world-space direction of towards mval. * - * \note Ignores view near/far clipping, to take this into account use #ED_view3d_win_to_ray_clipped. + * \note Ignores view near/far clipping, + * to take this into account use #ED_view3d_win_to_ray_clipped. */ void ED_view3d_win_to_ray(const ARegion *ar, const float mval[2], @@ -498,7 +499,10 @@ void ED_view3d_global_to_vector(const RegionView3D *rv3d, const float coord[3], /* very similar to ED_view3d_win_to_3d() but has no advantage, de-duplicating */ #if 0 -bool view3d_get_view_aligned_coordinate(ARegion *ar, float fp[3], const int mval[2], const bool do_fallback) +bool view3d_get_view_aligned_coordinate(ARegion *ar, + float fp[3], + const int mval[2], + const bool do_fallback) { RegionView3D *rv3d = ar->regiondata; float dvec[3]; @@ -508,8 +512,7 @@ bool view3d_get_view_aligned_coordinate(ARegion *ar, float fp[3], const int mval ret = ED_view3d_project_int_global(ar, fp, mval_cpy, V3D_PROJ_TEST_NOP); if (ret == V3D_PROJ_RET_OK) { - const float mval_f[2] = {(float)(mval_cpy[0] - mval[0]), - (float)(mval_cpy[1] - mval[1])}; + const float mval_f[2] = {(float)(mval_cpy[0] - mval[0]), (float)(mval_cpy[1] - mval[1])}; const float zfac = ED_view3d_calc_zfac(rv3d, fp, NULL); ED_view3d_win_to_delta(ar, mval_f, dvec, zfac); sub_v3_v3(fp, dvec); @@ -554,8 +557,9 @@ void ED_view3d_win_to_3d(const View3D *v3d, copy_v3_v3(ray_origin, rv3d->viewinv[3]); ED_view3d_win_to_vector(ar, mval, ray_direction); - /* note, we could use isect_line_plane_v3() however we want the intersection to be infront of the - * view no matter what, so apply the unsigned factor instead */ + /* note, we could use isect_line_plane_v3() + * however we want the intersection to be infront of the view no matter what, + * so apply the unsigned factor instead */ plane_from_point_normal_v3(plane, depth_pt, rv3d->viewinv[2]); isect_ray_plane_v3(ray_origin, ray_direction, plane, &lambda, false); diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index c0f2e563365..2ce23486476 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -1080,9 +1080,8 @@ static void do_lasso_select_node(int mcords[][2], short moves, const eSelectOp s ipoco_to_areaco_noclip(G.v2d, node_centf, node_cent); const bool is_select = node->flag & SELECT; - const bool is_inside = ( - BLI_rcti_isect_pt_v(&rect, node_cent) && - BLI_lasso_is_point_inside(mcords, moves, node_cent[0], node_cent[1])); + const bool is_inside = (BLI_rcti_isect_pt_v(&rect, node_cent) && + BLI_lasso_is_point_inside(mcords, moves, node_cent[0], node_cent[1])); const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside); if (sel_op_result != -1) { SET_FLAG_FROM_TEST(node->flag, sel_op_result, SELECT); @@ -1912,8 +1911,7 @@ static bool ed_object_select_pick(bContext *C, } } - basact->flag |= BASE_SELECTED; - BKE_scene_object_base_flag_sync_from_base(basact); + ED_object_base_select(basact, BA_SELECT); retval = true; @@ -1946,8 +1944,7 @@ static bool ed_object_select_pick(bContext *C, /* we make the armature selected: * not-selected active object in posemode won't work well for tools */ - basact->flag |= BASE_SELECTED; - BKE_scene_object_base_flag_sync_from_base(basact); + ED_object_base_select(basact, BA_SELECT); retval = true; WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, basact->object); @@ -2038,8 +2035,8 @@ static bool ed_object_select_pick(bContext *C, } /* Set special modes for grease pencil - The grease pencil modes are not real modes, but a hack to make the interface - consistent, so need some tricks to keep UI synchronized */ + * The grease pencil modes are not real modes, but a hack to make the interface + * consistent, so need some tricks to keep UI synchronized */ // XXX: This stuff needs reviewing (Aligorith) if (false && (((oldbasact) && oldbasact->object->type == OB_GPENCIL) || (basact->object->type == OB_GPENCIL))) { @@ -2214,7 +2211,7 @@ static int view3d_select_exec(bContext *C, wmOperator *op) } } - /* passthrough allows tweaks + /* Pass-through allows tweaks * FINISHED to signal one operator worked * */ if (retval) { @@ -2252,9 +2249,6 @@ void VIEW3D_OT_select(wmOperatorType *ot) /* properties */ WM_operator_properties_mouse_select(ot); - prop = RNA_def_boolean( - ot->srna, "deselect_all", 0, "Deselect", "Deselect all when nothing under the cursor"); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); prop = RNA_def_boolean( ot->srna, diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index 5aa19cc8a51..fb121aa716b 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -233,9 +233,11 @@ void VIEW3D_OT_snap_selected_to_grid(wmOperatorType *ot) /** Snaps the selection as a whole (use_offset=true) or each selected object to the given location. * - * \param snap_target_global: a location in global space to snap to (eg. 3D cursor or active object). - * \param use_offset: if the selected objects should maintain their relative offsets and be snapped by the selection - * pivot point (median, active), or if every object origin should be snapped to the given location. + * \param snap_target_global: a location in global space to snap to + * (eg. 3D cursor or active object). + * \param use_offset: if the selected objects should maintain their relative offsets + * and be snapped by the selection pivot point (median, active), + * or if every object origin should be snapped to the given location. */ static int snap_selected_to_location(bContext *C, const float snap_target_global[3], diff --git a/source/blender/editors/space_view3d/view3d_toolbar.c b/source/blender/editors/space_view3d/view3d_toolbar.c deleted file mode 100644 index 9357d3e05ee..00000000000 --- a/source/blender/editors/space_view3d/view3d_toolbar.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - * - * The Original Code is Copyright (C) 2009 Blender Foundation. - * All rights reserved. - */ - -/** \file - * \ingroup spview3d - */ - -#include <string.h> -#include <stdio.h> -#include <math.h> -#include <float.h> - -#include "DNA_scene_types.h" - -#include "BLI_utildefines.h" - -#include "BKE_context.h" - -#include "WM_api.h" -#include "WM_types.h" - -#include "ED_screen.h" - -#include "view3d_intern.h" /* own include */ - -/* ********** operator to open/close toolshelf region */ - -static int view3d_toolshelf_toggle_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = view3d_has_tools_region(sa); - - if (ar) { - ED_region_toggle_hidden(C, ar); - } - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_toolshelf(wmOperatorType *ot) -{ - ot->name = "Toggle Toolbar"; - ot->description = "Toggles tool shelf display"; - ot->idname = "VIEW3D_OT_toolshelf"; - - ot->exec = view3d_toolshelf_toggle_exec; - ot->poll = ED_operator_view3d_active; - - /* flags */ - ot->flag = 0; -} diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c index 3f078e35046..91313657f59 100644 --- a/source/blender/editors/space_view3d/view3d_utils.c +++ b/source/blender/editors/space_view3d/view3d_utils.c @@ -1143,7 +1143,8 @@ float ED_view3d_radius_to_dist_ortho(const float lens, const float radius) * \param ar: Can be NULL if \a use_aspect is false. * \param persp: Allow the caller to tell what kind of perspective to use (ortho/view/camera) * \param use_aspect: Increase the distance to account for non 1:1 view aspect. - * \param radius: The radius will be fitted exactly, typically pre-scaled by a margin (#VIEW3D_MARGIN). + * \param radius: The radius will be fitted exactly, + * typically pre-scaled by a margin (#VIEW3D_MARGIN). */ float ED_view3d_radius_to_dist(const View3D *v3d, const ARegion *ar, @@ -1435,7 +1436,8 @@ void ED_view3d_from_object(const Object *ob, float ofs[3], float quat[4], float /** * Set the object transformation from RegionView3D members. - * \param depsgraph: The depsgraph to get the evaluated object parent for the transformation calculation. + * \param depsgraph: The depsgraph to get the evaluated object parent + * for the transformation calculation. * \param ob: The object which has the transformation assigned. * \param ofs: The view offset, normally from RegionView3D.ofs. * \param quat: The view rotation, quaternion normally from RegionView3D.viewquat. diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index e313ed39c49..2454358b687 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -146,7 +146,7 @@ void ED_view3d_smooth_view_ex( } sms.org_view = rv3d->view; - /* sms.to_camera = false; */ /* initizlized to zero anyway */ + /* sms.to_camera = false; */ /* initialized to zero anyway */ /* note on camera locking, this is a little confusing but works ok. * we may be changing the view 'as if' there is no active camera, but in fact @@ -739,9 +739,16 @@ void view3d_winmatrix_set(Depsgraph *depsgraph, ARegion *ar, const View3D *v3d, rv3d->is_persp = !is_ortho; #if 0 - printf("%s: %d %d %f %f %f %f %f %f\n", __func__, winx, winy, - viewplane.xmin, viewplane.ymin, viewplane.xmax, viewplane.ymax, - clipsta, clipend); + printf("%s: %d %d %f %f %f %f %f %f\n", + __func__, + winx, + winy, + viewplane.xmin, + viewplane.ymin, + viewplane.xmax, + viewplane.ymax, + clipsta, + clipend); #endif if (rect) { /* picking */ @@ -858,8 +865,8 @@ void view3d_viewmatrix_set(Depsgraph *depsgraph, vec[2] = 0.0f; if (rect_scale) { - /* Since 'RegionView3D.winmat' has been calculated and this function doesn't take the 'ARegion' - * we don't know about the region size. + /* Since 'RegionView3D.winmat' has been calculated and this function doesn't take the + * 'ARegion' we don't know about the region size. * Use 'rect_scale' when drawing a sub-region to apply 2D offset, * scaled by the difference between the sub-region and the region size. */ @@ -1223,7 +1230,7 @@ static bool view3d_localview_init(const Depsgraph *depsgraph, if (local_view_bit == 0) { /* TODO(dfelinto): We can kick one of the other 3D views out of local view - specially if it is not being used. */ + * specially if it is not being used. */ BKE_report(reports, RPT_ERROR, "No more than 16 local views"); ok = false; } diff --git a/source/blender/editors/transform/CMakeLists.txt b/source/blender/editors/transform/CMakeLists.txt index 05e0659637b..9696f0fb315 100644 --- a/source/blender/editors/transform/CMakeLists.txt +++ b/source/blender/editors/transform/CMakeLists.txt @@ -27,10 +27,10 @@ set(INC ../../makesdna ../../makesrna ../../render/extern/include - ../../windowmanager ../../depsgraph - ../../../../intern/guardedalloc + ../../windowmanager ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 944c6436dfb..81405b55ac2 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -96,7 +96,8 @@ #include "transform.h" -/* Disabling, since when you type you know what you are doing, and being able to set it to zero is handy. */ +/* Disabling, since when you type you know what you are doing, + * and being able to set it to zero is handy. */ // #define USE_NUM_NO_ZERO static void drawTransformApply(const struct bContext *C, ARegion *ar, void *arg); @@ -585,30 +586,33 @@ static void viewRedrawForce(const bContext *C, TransInfo *t) } else { /* Do we need more refined tags? */ - if (t->flag & T_POSE) + if (t->flag & T_POSE) { WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL); - else + } + else { WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); + } /* For real-time animation record - send notifiers recognized by animation editors */ // XXX: is this notifier a lame duck? - if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) + if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) { WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, NULL); + } } } else if (t->spacetype == SPACE_ACTION) { - //SpaceAction *saction = (SpaceAction *)t->sa->spacedata.first; + // SpaceAction *saction = (SpaceAction *)t->sa->spacedata.first; WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); } else if (t->spacetype == SPACE_GRAPH) { - //SpaceGraph *sipo = (SpaceGraph *)t->sa->spacedata.first; + // SpaceGraph *sipo = (SpaceGraph *)t->sa->spacedata.first; WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); } else if (t->spacetype == SPACE_NLA) { WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL); } else if (t->spacetype == SPACE_NODE) { - //ED_area_tag_redraw(t->sa); + // ED_area_tag_redraw(t->sa); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_NODE_VIEW, NULL); } else if (t->spacetype == SPACE_SEQ) { @@ -663,8 +667,9 @@ static void viewRedrawPost(bContext *C, TransInfo *t) if (t->spacetype == SPACE_VIEW3D) { /* if autokeying is enabled, send notifiers that keyframes were added */ - if (IS_AUTOKEY_ON(t->scene)) + if (IS_AUTOKEY_ON(t->scene)) { WM_main_add_notifier(NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); + } /* redraw UV editor */ if (ELEM(t->mode, TFM_VERT_SLIDE, TFM_EDGE_SLIDE) && @@ -1045,8 +1050,9 @@ int transformEvent(TransInfo *t, const wmEvent *event) handled = true; } else if (event->type == MOUSEMOVE) { - if (t->modifiers & MOD_CONSTRAINT_SELECT) + if (t->modifiers & MOD_CONSTRAINT_SELECT) { t->con.mode |= CON_SELECT; + } copy_v2_v2_int(t->mval, event->mval); @@ -1380,8 +1386,9 @@ int transformEvent(TransInfo *t, const wmEvent *event) if ((t->flag & T_NO_CONSTRAINT) == 0) { /* exception for switching to dolly, or trackball, in camera view */ if (t->flag & T_CAMERA) { - if (t->mode == TFM_TRANSLATION) + if (t->mode == TFM_TRANSLATION) { setLocalConstraint(t, (CON_AXIS2), IFACE_("along local Z")); + } else if (t->mode == TFM_ROTATION) { restoreTransObjects(t); initTrackball(t); @@ -1486,8 +1493,9 @@ int transformEvent(TransInfo *t, const wmEvent *event) case PADPLUSKEY: if (event->alt && t->flag & T_PROP_EDIT) { t->prop_size *= (t->modifiers & MOD_PRECISION) ? 1.01f : 1.1f; - if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO) + if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO) { t->prop_size = min_ff(t->prop_size, ((View3D *)t->view)->clip_end); + } calculatePropRatio(t); t->redraw = TREDRAW_HARD; handled = true; @@ -1769,8 +1777,9 @@ static bool helpline_poll(bContext *C) { ARegion *ar = CTX_wm_region(C); - if (ar && ar->regiontype == RGN_TYPE_WINDOW) + if (ar && ar->regiontype == RGN_TYPE_WINDOW) { return 1; + } return 0; } @@ -2092,20 +2101,16 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op) } } - /* convert flag to enum */ - switch (t->flag & T_PROP_EDIT_ALL) { - case T_PROP_EDIT: - proportional = PROP_EDIT_ON; - break; - case (T_PROP_EDIT | T_PROP_CONNECTED): - proportional = PROP_EDIT_CONNECTED; - break; - case (T_PROP_EDIT | T_PROP_PROJECTED): - proportional = PROP_EDIT_PROJECTED; - break; - default: - proportional = PROP_EDIT_OFF; - break; + if (t->flag & T_PROP_EDIT_ALL) { + if (t->flag & T_PROP_EDIT) { + proportional |= PROP_EDIT_USE; + } + if (t->flag & T_PROP_CONNECTED) { + proportional |= PROP_EDIT_CONNECTED; + } + if (t->flag & T_PROP_PROJECTED) { + proportional |= PROP_EDIT_PROJECTED; + } } // If modal, save settings back in scene if not set as operator argument @@ -2114,18 +2119,23 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op) /* skip saving proportional edit if it was not actually used */ if (!(t->options & CTX_NO_PET)) { - if ((prop = RNA_struct_find_property(op->ptr, "proportional")) && + if ((prop = RNA_struct_find_property(op->ptr, "use_proportional_edit")) && !RNA_property_is_set(op->ptr, prop)) { - if (t->spacetype == SPACE_GRAPH) + if (t->spacetype == SPACE_GRAPH) { ts->proportional_fcurve = proportional; - else if (t->spacetype == SPACE_ACTION) + } + else if (t->spacetype == SPACE_ACTION) { ts->proportional_action = proportional; - else if (t->obedit_type != -1) - ts->proportional = proportional; - else if (t->options & CTX_MASK) - ts->proportional_mask = (proportional != PROP_EDIT_OFF); - else - ts->proportional_objects = (proportional != PROP_EDIT_OFF); + } + else if (t->obedit_type != -1) { + ts->proportional_edit = proportional; + } + else if (t->options & CTX_MASK) { + ts->proportional_mask = proportional != 0; + } + else { + ts->proportional_objects = proportional != 0; + } } if ((prop = RNA_struct_find_property(op->ptr, "proportional_size"))) { @@ -2163,8 +2173,10 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op) } } - if ((prop = RNA_struct_find_property(op->ptr, "proportional"))) { - RNA_property_enum_set(op->ptr, prop, proportional); + if ((prop = RNA_struct_find_property(op->ptr, "use_proportional_edit"))) { + RNA_property_boolean_set(op->ptr, prop, proportional & PROP_EDIT_USE); + RNA_boolean_set(op->ptr, "use_proportional_connected", proportional & PROP_EDIT_CONNECTED); + RNA_boolean_set(op->ptr, "use_proportional_projected", proportional & PROP_EDIT_PROJECTED); RNA_enum_set(op->ptr, "proportional_edit_falloff", t->prop_mode); RNA_float_set(op->ptr, "proportional_size", t->prop_size); } @@ -2341,8 +2353,9 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve /* Needed to translate tweak events to mouse buttons. */ t->launch_event = event ? WM_userdef_event_type_from_keymap_type(event->type) : -1; - // XXX Remove this when wm_operator_call_internal doesn't use window->eventstate (which can have type = 0) - // For gizmo only, so assume LEFTMOUSE + /* XXX Remove this when wm_operator_call_internal doesn't use window->eventstate + * (which can have type = 0) */ + /* For gizmo only, so assume LEFTMOUSE. */ if (t->launch_event == 0) { t->launch_event = LEFTMOUSE; } @@ -2365,7 +2378,6 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve else if (t->spacetype == SPACE_IMAGE) { t->draw_handle_view = ED_region_draw_cb_activate( t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW); - //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL); t->draw_handle_cursor = WM_paint_cursor_activate( CTX_wm_manager(C), SPACE_TYPE_ANY, RGN_TYPE_ANY, helpline_poll, drawHelpline, t); } @@ -2376,7 +2388,6 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve CTX_wm_manager(C), SPACE_TYPE_ANY, RGN_TYPE_ANY, helpline_poll, drawHelpline, t); } else if (t->spacetype == SPACE_NODE) { - /*t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);*/ t->draw_handle_view = ED_region_draw_cb_activate( t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW); t->draw_handle_cursor = WM_paint_cursor_activate( @@ -2385,14 +2396,12 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve else if (t->spacetype == SPACE_GRAPH) { t->draw_handle_view = ED_region_draw_cb_activate( t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW); - //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL); t->draw_handle_cursor = WM_paint_cursor_activate( CTX_wm_manager(C), SPACE_TYPE_ANY, RGN_TYPE_ANY, helpline_poll, drawHelpline, t); } else if (t->spacetype == SPACE_ACTION) { t->draw_handle_view = ED_region_draw_cb_activate( t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW); - //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL); t->draw_handle_cursor = WM_paint_cursor_activate( CTX_wm_manager(C), SPACE_TYPE_ANY, RGN_TYPE_ANY, helpline_poll, drawHelpline, t); } @@ -2588,10 +2597,12 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve /* same as TFM_TIME_EXTEND, but we need the mode info for later * so that duplicate-culling will work properly */ - if (ELEM(t->spacetype, SPACE_GRAPH, SPACE_NLA)) + if (ELEM(t->spacetype, SPACE_GRAPH, SPACE_NLA)) { initTranslation(t); - else + } + else { initTimeTranslate(t); + } t->mode = mode; break; case TFM_TIME_EXTEND: @@ -2600,10 +2611,12 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement) * depending on which editor this was called from */ - if (ELEM(t->spacetype, SPACE_GRAPH, SPACE_NLA)) + if (ELEM(t->spacetype, SPACE_GRAPH, SPACE_NLA)) { initTranslation(t); - else + } + else { initTimeTranslate(t); + } break; case TFM_BAKE_TIME: initBakeTime(t); @@ -2678,7 +2691,8 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve } } - /* Don't write into the values when non-modal because they are already set from operator redo values. */ + /* Don't write into the values when non-modal because they are already set from operator redo + * values. */ if (t->flag & T_MODAL) { /* Setup the mouse input with initial values. */ applyMouseInput(t, &t->mouse, t->mouse.imval, t->values); @@ -2687,8 +2701,7 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve if ((prop = RNA_struct_find_property(op->ptr, "preserve_clnor"))) { if ((t->flag & T_EDIT) && t->obedit_type == OB_MESH) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { if ((((Mesh *)(tc->obedit->data))->flag & ME_AUTOSMOOTH)) { BMEditMesh *em = NULL; // BKE_editmesh_from_object(t->obedit); bool do_skip = false; @@ -2781,8 +2794,7 @@ int transformEnd(bContext *C, TransInfo *t) } else { if (t->flag & T_CLNOR_REBUILD) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); BM_lnorspace_rebuild(em->bm, true); } @@ -2811,32 +2823,41 @@ int transformEnd(bContext *C, TransInfo *t) static void protectedTransBits(short protectflag, float vec[3]) { - if (protectflag & OB_LOCK_LOCX) + if (protectflag & OB_LOCK_LOCX) { vec[0] = 0.0f; - if (protectflag & OB_LOCK_LOCY) + } + if (protectflag & OB_LOCK_LOCY) { vec[1] = 0.0f; - if (protectflag & OB_LOCK_LOCZ) + } + if (protectflag & OB_LOCK_LOCZ) { vec[2] = 0.0f; + } } static void protectedSizeBits(short protectflag, float size[3]) { - if (protectflag & OB_LOCK_SCALEX) + if (protectflag & OB_LOCK_SCALEX) { size[0] = 1.0f; - if (protectflag & OB_LOCK_SCALEY) + } + if (protectflag & OB_LOCK_SCALEY) { size[1] = 1.0f; - if (protectflag & OB_LOCK_SCALEZ) + } + if (protectflag & OB_LOCK_SCALEZ) { size[2] = 1.0f; + } } static void protectedRotateBits(short protectflag, float eul[3], const float oldeul[3]) { - if (protectflag & OB_LOCK_ROTX) + if (protectflag & OB_LOCK_ROTX) { eul[0] = oldeul[0]; - if (protectflag & OB_LOCK_ROTY) + } + if (protectflag & OB_LOCK_ROTY) { eul[1] = oldeul[1]; - if (protectflag & OB_LOCK_ROTZ) + } + if (protectflag & OB_LOCK_ROTZ) { eul[2] = oldeul[2]; + } } /* this function only does the delta rotation */ @@ -2845,19 +2866,24 @@ static void protectedAxisAngleBits( short protectflag, float axis[3], float *angle, float oldAxis[3], float oldAngle) { /* check that protection flags are set */ - if ((protectflag & (OB_LOCK_ROTX | OB_LOCK_ROTY | OB_LOCK_ROTZ | OB_LOCK_ROTW)) == 0) + if ((protectflag & (OB_LOCK_ROTX | OB_LOCK_ROTY | OB_LOCK_ROTZ | OB_LOCK_ROTW)) == 0) { return; + } if (protectflag & OB_LOCK_ROT4D) { /* axis-angle getting limited as 4D entities that they are... */ - if (protectflag & OB_LOCK_ROTW) + if (protectflag & OB_LOCK_ROTW) { *angle = oldAngle; - if (protectflag & OB_LOCK_ROTX) + } + if (protectflag & OB_LOCK_ROTX) { axis[0] = oldAxis[0]; - if (protectflag & OB_LOCK_ROTY) + } + if (protectflag & OB_LOCK_ROTY) { axis[1] = oldAxis[1]; - if (protectflag & OB_LOCK_ROTZ) + } + if (protectflag & OB_LOCK_ROTZ) { axis[2] = oldAxis[2]; + } } else { /* axis-angle get limited with euler... */ @@ -2866,16 +2892,20 @@ static void protectedAxisAngleBits( axis_angle_to_eulO(eul, EULER_ORDER_DEFAULT, axis, *angle); axis_angle_to_eulO(oldeul, EULER_ORDER_DEFAULT, oldAxis, oldAngle); - if (protectflag & OB_LOCK_ROTX) + if (protectflag & OB_LOCK_ROTX) { eul[0] = oldeul[0]; - if (protectflag & OB_LOCK_ROTY) + } + if (protectflag & OB_LOCK_ROTY) { eul[1] = oldeul[1]; - if (protectflag & OB_LOCK_ROTZ) + } + if (protectflag & OB_LOCK_ROTZ) { eul[2] = oldeul[2]; + } eulO_to_axis_angle(axis, angle, eul, EULER_ORDER_DEFAULT); - /* when converting to axis-angle, we need a special exception for the case when there is no axis */ + /* When converting to axis-angle, + * we need a special exception for the case when there is no axis. */ if (IS_EQF(axis[0], axis[1]) && IS_EQF(axis[1], axis[2])) { /* for now, rotate around y-axis then (so that it simply becomes the roll) */ axis[1] = 1.0f; @@ -2887,19 +2917,24 @@ static void protectedAxisAngleBits( static void protectedQuaternionBits(short protectflag, float quat[4], const float oldquat[4]) { /* check that protection flags are set */ - if ((protectflag & (OB_LOCK_ROTX | OB_LOCK_ROTY | OB_LOCK_ROTZ | OB_LOCK_ROTW)) == 0) + if ((protectflag & (OB_LOCK_ROTX | OB_LOCK_ROTY | OB_LOCK_ROTZ | OB_LOCK_ROTW)) == 0) { return; + } if (protectflag & OB_LOCK_ROT4D) { /* quaternions getting limited as 4D entities that they are... */ - if (protectflag & OB_LOCK_ROTW) + if (protectflag & OB_LOCK_ROTW) { quat[0] = oldquat[0]; - if (protectflag & OB_LOCK_ROTX) + } + if (protectflag & OB_LOCK_ROTX) { quat[1] = oldquat[1]; - if (protectflag & OB_LOCK_ROTY) + } + if (protectflag & OB_LOCK_ROTY) { quat[2] = oldquat[2]; - if (protectflag & OB_LOCK_ROTZ) + } + if (protectflag & OB_LOCK_ROTZ) { quat[3] = oldquat[3]; + } } else { /* quaternions get limited with euler... (compatibility mode) */ @@ -2912,12 +2947,15 @@ static void protectedQuaternionBits(short protectflag, float quat[4], const floa quat_to_eul(eul, nquat); quat_to_eul(oldeul, noldquat); - if (protectflag & OB_LOCK_ROTX) + if (protectflag & OB_LOCK_ROTX) { eul[0] = oldeul[0]; - if (protectflag & OB_LOCK_ROTY) + } + if (protectflag & OB_LOCK_ROTY) { eul[1] = oldeul[1]; - if (protectflag & OB_LOCK_ROTZ) + } + if (protectflag & OB_LOCK_ROTZ) { eul[2] = oldeul[2]; + } eul_to_quat(quat, eul); @@ -2958,24 +2996,28 @@ static void constraintTransLim(TransInfo *t, TransData *td) ListBase targets = {NULL, NULL}; /* only consider constraint if enabled */ - if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) + if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) { continue; - if (con->enforce == 0.0f) + } + if (con->enforce == 0.0f) { continue; + } /* only use it if it's tagged for this purpose (and the right type) */ if (con->type == CONSTRAINT_TYPE_LOCLIMIT) { bLocLimitConstraint *data = con->data; - if ((data->flag2 & LIMIT_TRANSFORM) == 0) + if ((data->flag2 & LIMIT_TRANSFORM) == 0) { continue; + } cti = ctiLoc; } else if (con->type == CONSTRAINT_TYPE_DISTLIMIT) { bDistLimitConstraint *data = con->data; - if ((data->flag & LIMITDIST_TRANSFORM) == 0) + if ((data->flag & LIMITDIST_TRANSFORM) == 0) { continue; + } cti = ctiDist; } @@ -3051,22 +3093,26 @@ static void constraintRotLim(TransInfo *UNUSED(t), TransData *td) /* Evaluate valid constraints */ for (con = td->con; con; con = con->next) { /* only consider constraint if enabled */ - if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) + if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) { continue; - if (con->enforce == 0.0f) + } + if (con->enforce == 0.0f) { continue; + } /* we're only interested in Limit-Rotation constraints */ if (con->type == CONSTRAINT_TYPE_ROTLIMIT) { bRotLimitConstraint *data = con->data; /* only use it if it's tagged for this purpose */ - if ((data->flag2 & LIMIT_TRANSFORM) == 0) + if ((data->flag2 & LIMIT_TRANSFORM) == 0) { continue; + } /* skip incompatible spacetypes */ - if (!ELEM(con->ownspace, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL)) + if (!ELEM(con->ownspace, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL)) { continue; + } /* only do conversion if necessary, to preserve quats and eulers */ if (do_limit == false) { @@ -3128,8 +3174,9 @@ static void constraintSizeLim(TransInfo *t, TransData *td) } else { /* Reset val if SINGLESIZE but using a constraint */ - if (td->flag & TD_SINGLESIZE) + if (td->flag & TD_SINGLESIZE) { return; + } /* separate out sign to apply back later */ for (i = 0; i < 3; i++) { @@ -3143,18 +3190,21 @@ static void constraintSizeLim(TransInfo *t, TransData *td) /* Evaluate valid constraints */ for (con = td->con; con; con = con->next) { /* only consider constraint if enabled */ - if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) + if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) { continue; - if (con->enforce == 0.0f) + } + if (con->enforce == 0.0f) { continue; + } /* we're only interested in Limit-Scale constraints */ if (con->type == CONSTRAINT_TYPE_SIZELIMIT) { bSizeLimitConstraint *data = con->data; /* only use it if it's tagged for this purpose */ - if ((data->flag2 & LIMIT_TRANSFORM) == 0) + if ((data->flag2 & LIMIT_TRANSFORM) == 0) { continue; + } /* do space conversions */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { @@ -3184,8 +3234,9 @@ static void constraintSizeLim(TransInfo *t, TransData *td) } else { /* Reset val if SINGLESIZE but using a constraint */ - if (td->flag & TD_SINGLESIZE) + if (td->flag & TD_SINGLESIZE) { return; + } /* extrace scale from matrix and apply back sign */ mat4_to_size(td->ext->size, cob.matrix); @@ -3240,7 +3291,7 @@ static void initBend(TransInfo *t) t->flag |= T_NO_CONSTRAINT; - //copy_v3_v3(t->center, ED_view3d_cursor3d_get(t->scene, t->view)); + // copy_v3_v3(t->center, ED_view3d_cursor3d_get(t->scene, t->view)); if ((t->flag & T_OVERRIDE_CENTER) == 0) { calculateCenterCursor(t, t->center_global); } @@ -3364,8 +3415,7 @@ static void Bend(TransInfo *t, const int UNUSED(mval[2])) } /* TODO(campbell): xform, compensate object center. */ - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; float warp_sta_local[3]; @@ -3391,11 +3441,13 @@ static void Bend(TransInfo *t, const int UNUSED(mval[2])) float delta[3]; float fac, fac_scaled; - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } if (UNLIKELY(values.angle == 0.0f)) { copy_v3_v3(td->loc, td->iloc); @@ -3579,10 +3631,12 @@ static void applyShear(TransInfo *t, const int UNUSED(mval[2])) unit_m3(smat); // Custom data signals shear direction - if (t->custom.mode.data == NULL) + if (t->custom.mode.data == NULL) { smat[1][0] = value; - else + } + else { smat[0][1] = value; + } copy_v3_v3(axismat_inv[0], t->orient_matrix[t->orient_axis_ortho]); copy_v3_v3(axismat_inv[2], t->orient_matrix[t->orient_axis]); @@ -3591,17 +3645,18 @@ static void applyShear(TransInfo *t, const int UNUSED(mval[2])) mul_m3_series(totmat, axismat_inv, smat, axismat); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { const float *center, *co; - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } if (t->flag & T_EDIT) { mul_m3_series(tmat, td->smtx, totmat, td->mtx); @@ -3774,12 +3829,15 @@ static void TransMat3ToSize(float mat[3][3], float smat[3][3], float size[3]) mat3_to_rot_size(rmat, size, mat); /* first tried with dotproduct... but the sign flip is crucial */ - if (dot_v3v3(rmat[0], smat[0]) < 0.0f) + if (dot_v3v3(rmat[0], smat[0]) < 0.0f) { size[0] = -size[0]; - if (dot_v3v3(rmat[1], smat[1]) < 0.0f) + } + if (dot_v3v3(rmat[1], smat[1]) < 0.0f) { size[1] = -size[1]; - if (dot_v3v3(rmat[2], smat[2]) < 0.0f) + } + if (dot_v3v3(rmat[2], smat[2]) < 0.0f) { size[2] = -size[2]; + } } static void ElementResize(TransInfo *t, TransDataContainer *tc, TransData *td, float mat[3][3]) @@ -3844,8 +3902,9 @@ static void ElementResize(TransInfo *t, TransDataContainer *tc, TransData *td, f } else { /* Reset val if SINGLESIZE but using a constraint */ - if (td->flag & TD_SINGLESIZE) + if (td->flag & TD_SINGLESIZE) { *td->val = td->ival; + } td->ext->size[0] = td->ext->isize[0] * (1 + (fsize[0] - 1) * td->factor); td->ext->size[1] = td->ext->isize[1] * (1 + (fsize[1] - 1) * td->factor); @@ -3857,18 +3916,22 @@ static void ElementResize(TransInfo *t, TransDataContainer *tc, TransData *td, f } /* For individual element center, Editmode need to use iloc */ - if (t->flag & T_POINTS) + if (t->flag & T_POINTS) { sub_v3_v3v3(vec, td->iloc, center); - else + } + else { sub_v3_v3v3(vec, td->center, center); + } mul_m3_v3(tmat, vec); add_v3_v3(vec, center); - if (t->flag & T_POINTS) + if (t->flag & T_POINTS) { sub_v3_v3(vec, td->iloc); - else + } + else { sub_v3_v3(vec, td->center); + } /* grease pencil falloff */ if (t->options & CTX_GPENCIL_STROKES) { @@ -3947,15 +4010,16 @@ static void applyResize(TransInfo *t, const int UNUSED(mval[2])) copy_m3_m3(t->mat, mat); // used in gizmo - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } ElementResize(t, tc, td, mat); } @@ -3969,11 +4033,11 @@ static void applyResize(TransInfo *t, const int UNUSED(mval[2])) t->con.applySize(t, NULL, NULL, mat); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; - for (i = 0; i < tc->data_len; i++, td++) + for (i = 0; i < tc->data_len; i++, td++) { ElementResize(t, tc, td, mat); + } /* In proportional edit it can happen that */ /* vertices in the radius of the brush end */ @@ -4057,18 +4121,19 @@ static void applySkinResize(TransInfo *t, const int UNUSED(mval[2])) headerResize(t, size, str); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { float tmat[3][3], smat[3][3]; float fsize[3]; - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } if (t->flag & T_EDIT) { mul_m3_m3m3(smat, mat, td->mtx); @@ -4123,8 +4188,7 @@ static void initToSphere(TransInfo *t) t->flag |= T_NO_CONSTRAINT; // Calculate average radius - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { t->val += len_v3v3(tc->center_local, td->iloc); @@ -4164,16 +4228,17 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) BLI_snprintf(str, sizeof(str), IFACE_("To Sphere: %.4f %s"), ratio, t->proptext); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { float tratio; - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } sub_v3_v3v3(vec, td->iloc, tc->center_local); @@ -4227,8 +4292,9 @@ static void initRotation(TransInfo *t) t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS); t->num.unit_type[0] = B_UNIT_ROTATION; - if (t->flag & T_2D_EDIT) + if (t->flag & T_2D_EDIT) { t->flag |= T_NO_CONSTRAINT; + } } /* Used by Transform Rotation and Transform Normal Rotation */ @@ -4519,16 +4585,17 @@ static void applyRotationValue(TransInfo *t, float angle, float axis[3]) axis_angle_normalized_to_mat3(mat, axis, angle); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } if (t->con.applyRot) { t->con.applyRot(t, tc, td, axis, NULL); @@ -4562,7 +4629,8 @@ static void applyRotation(TransInfo *t, const int UNUSED(mval[2])) applySnapping(t, &final); - /* Used to clamp final result in [-PI, PI[ range, no idea why, inheritance from 2.4x area, see T48998. */ + /* Used to clamp final result in [-PI, PI[ range, no idea why, + * inheritance from 2.4x area, see T48998. */ applyNumInput(&t->num, &final); t->values[0] = final; @@ -4620,15 +4688,16 @@ static void applyTrackballValue(TransInfo *t, angle = normalize_v3(axis); axis_angle_normalized_to_mat3(mat, axis, angle); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } if (t->flag & T_PROP_EDIT) { axis_angle_normalized_to_mat3(mat, axis, td->factor * angle); @@ -4762,8 +4831,7 @@ static void initNormalRotation(TransInfo *t) t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS); t->num.unit_type[0] = B_UNIT_ROTATION; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); BMesh *bm = em->bm; @@ -4785,8 +4853,7 @@ static void applyNormalRotation(TransInfo *t, const int UNUSED(mval[2])) t->con.applyRot(t, NULL, NULL, axis_final, NULL); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); BMesh *bm = em->bm; @@ -4964,13 +5031,16 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_ if (t->flag & T_AUTOIK) { short chainlen = t->settings->autoik_chainlen; - if (chainlen) + if (chainlen) { BLI_snprintf(autoik, NUM_STR_REP_LEN, IFACE_("AutoIK-Len: %d"), chainlen); - else + } + else { autoik[0] = '\0'; + } } - else + else { autoik[0] = '\0'; + } if (t->con.mode & CON_APPLY) { switch (t->num.idx_max) { @@ -5073,8 +5143,7 @@ static void applyTranslationValue(TransInfo *t, const float vec[3]) /* The ideal would be "apply_snap_align_rotation" only when a snap point is found * so, maybe inside this function is not the best place to apply this rotation. * but you need "handle snapping rotation before doing the translation" (really?) */ - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { float pivot[3]; if (apply_snap_align_rotation) { @@ -5087,11 +5156,13 @@ static void applyTranslationValue(TransInfo *t, const float vec[3]) TransData *td = tc->data; for (int i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } float rotate_offset[3] = {0}; bool use_rotate_offset = false; @@ -5104,10 +5175,12 @@ static void applyTranslationValue(TransInfo *t, const float vec[3]) const float *original_normal; /* In pose mode, we want to align normals with Y axis of bones... */ - if (t->flag & T_POSE) + if (t->flag & T_POSE) { original_normal = td->axismtx[1]; - else + } + else { original_normal = td->axismtx[2]; + } rotation_between_vecs_to_mat3(mat, original_normal, t->tsnap.snapNormal); } @@ -5154,8 +5227,9 @@ static void applyTranslationValue(TransInfo *t, const float vec[3]) protectedTransBits(td->protectflag, tvec); - if (td->loc) + if (td->loc) { add_v3_v3v3(td->loc, td->iloc, tvec); + } constraintTransLim(t, td); } @@ -5294,16 +5368,17 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) WM_bool_as_string((t->flag & T_ALT_TRANSFORM) != 0)); /* done with header string */ - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { float tdistance; /* temp dist */ - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } /* get the final offset */ tdistance = distance * td->factor; @@ -5377,15 +5452,16 @@ static void applyTilt(TransInfo *t, const int UNUSED(mval[2])) BLI_snprintf(str, sizeof(str), IFACE_("Tilt: %.2f° %s"), RAD2DEGF(final), t->proptext); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } if (td->val) { *td->val = td->ival + final * td->factor; @@ -5455,22 +5531,24 @@ static void applyCurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) BLI_snprintf(str, sizeof(str), IFACE_("Shrink/Fatten: %3f"), ratio); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } if (td->val) { *td->val = td->ival * ratio; /* apply PET */ *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival); - if (*td->val <= 0.0f) + if (*td->val <= 0.0f) { *td->val = 0.001f; + } } } } @@ -5542,43 +5620,49 @@ static void applyMaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) if (ratio > 1.0f) { initial_feather = true; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } - if (td->ival >= 0.001f) + if (td->ival >= 0.001f) { initial_feather = false; + } } } } /* apply shrink/fatten */ - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (td = tc->data, i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } if (td->val) { - if (initial_feather) + if (initial_feather) { *td->val = td->ival + (ratio - 1.0f) * 0.01f; - else + } + else { *td->val = td->ival * ratio; + } /* apply PET */ *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival); - if (*td->val <= 0.0f) + if (*td->val <= 0.0f) { *td->val = 0.001f; + } } } } @@ -5645,22 +5729,24 @@ static void applyGPShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) BLI_snprintf(str, sizeof(str), IFACE_("Shrink/Fatten: %3f"), ratio); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } if (td->val) { *td->val = td->ival * ratio; /* apply PET */ *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival); - if (*td->val <= 0.0f) + if (*td->val <= 0.0f) { *td->val = 0.001f; + } } } } @@ -5725,15 +5811,16 @@ static void applyGPOpacity(TransInfo *t, const int UNUSED(mval[2])) BLI_snprintf(str, sizeof(str), IFACE_("Opacity: %3f"), ratio); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } if (td->val) { *td->val = td->ival * ratio; @@ -5805,15 +5892,16 @@ static void applyPushPull(TransInfo *t, const int UNUSED(mval[2])) t->con.applyRot(t, NULL, NULL, axis_global, NULL); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } sub_v3_v3v3(vec, tc->center_local, td->center); if (t->con.applyRot && t->con.mode & CON_APPLY) { @@ -5891,32 +5979,38 @@ static void applyBevelWeight(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c, &t->scene->unit); - if (weight >= 0.0f) + if (weight >= 0.0f) { BLI_snprintf(str, sizeof(str), IFACE_("Bevel Weight: +%s %s"), c, t->proptext); - else + } + else { BLI_snprintf(str, sizeof(str), IFACE_("Bevel Weight: %s %s"), c, t->proptext); + } } else { /* default header print */ - if (weight >= 0.0f) + if (weight >= 0.0f) { BLI_snprintf(str, sizeof(str), IFACE_("Bevel Weight: +%.3f %s"), weight, t->proptext); - else + } + else { BLI_snprintf(str, sizeof(str), IFACE_("Bevel Weight: %.3f %s"), weight, t->proptext); + } } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } if (td->val) { *td->val = td->ival + weight * td->factor; - if (*td->val < 0.0f) + if (*td->val < 0.0f) { *td->val = 0.0f; - if (*td->val > 1.0f) + } + if (*td->val > 1.0f) { *td->val = 1.0f; + } } } } @@ -5975,35 +6069,42 @@ static void applyCrease(TransInfo *t, const int UNUSED(mval[2])) outputNumInput(&(t->num), c, &t->scene->unit); - if (crease >= 0.0f) + if (crease >= 0.0f) { BLI_snprintf(str, sizeof(str), IFACE_("Crease: +%s %s"), c, t->proptext); - else + } + else { BLI_snprintf(str, sizeof(str), IFACE_("Crease: %s %s"), c, t->proptext); + } } else { /* default header print */ - if (crease >= 0.0f) + if (crease >= 0.0f) { BLI_snprintf(str, sizeof(str), IFACE_("Crease: +%.3f %s"), crease, t->proptext); - else + } + else { BLI_snprintf(str, sizeof(str), IFACE_("Crease: %.3f %s"), crease, t->proptext); + } } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } if (td->val) { *td->val = td->ival + crease * td->factor; - if (*td->val < 0.0f) + if (*td->val < 0.0f) { *td->val = 0.0f; - if (*td->val > 1.0f) + } + if (*td->val > 1.0f) { *td->val = 1.0f; + } } } } @@ -6058,10 +6159,11 @@ static void headerBoneSize(TransInfo *t, const float vec[3], char str[UI_MAX_DRA /* hmm... perhaps the y-axis values don't need to be shown? */ if (t->con.mode & CON_APPLY) { - if (t->num.idx_max == 0) + if (t->num.idx_max == 0) { BLI_snprintf( str, UI_MAX_DRAW_STR, IFACE_("ScaleB: %s%s %s"), &tvec[0], t->con.text, t->proptext); - else + } + else { BLI_snprintf(str, UI_MAX_DRAW_STR, IFACE_("ScaleB: %s : %s : %s%s %s"), @@ -6070,6 +6172,7 @@ static void headerBoneSize(TransInfo *t, const float vec[3], char str[UI_MAX_DRA &tvec[NUM_STR_REP_LEN * 2], t->con.text, t->proptext); + } } else { BLI_snprintf(str, @@ -6130,15 +6233,16 @@ static void applyBoneSize(TransInfo *t, const int UNUSED(mval[2])) headerBoneSize(t, size, str); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } ElementBoneSize(t, tc, td, mat); } @@ -6201,22 +6305,25 @@ static void applyBoneEnvelope(TransInfo *t, const int UNUSED(mval[2])) BLI_snprintf(str, sizeof(str), IFACE_("Envelope: %3f"), ratio); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } if (td->val) { /* if the old/original value was 0.0f, then just use ratio */ - if (td->ival) + if (td->ival) { *td->val = td->ival * ratio; - else + } + else { *td->val = ratio; + } } } } @@ -6365,7 +6472,8 @@ static void slide_origdata_create_data(TransDataContainer *tc, for (i = 0; i < tc->data_len; i++, td++) { BMVert *eve = td->extra; - /* Check the vertex has been used since both sides of the mirror may be selected & sliding. */ + /* Check the vertex has been used since both sides + * of the mirror may be selected & sliding. */ if (eve && !BLI_ghash_haskey(sod->origverts, eve)) { sv_mirror->v = eve; copy_v3_v3(sv_mirror->co_orig_3d, eve->co); @@ -6498,13 +6606,11 @@ static void slide_origdata_interp_data_vert(SlideOrigData *sod, float(*faces_center)[3] = BLI_array_alloca(faces_center, l_num); BMLoop *l; - BM_ITER_ELEM_INDEX(l, &liter, sv->v, BM_LOOPS_OF_VERT, j) - { + BM_ITER_ELEM_INDEX (l, &liter, sv->v, BM_LOOPS_OF_VERT, j) { BM_face_calc_center_median(l->f, faces_center[j]); } - BM_ITER_ELEM_INDEX(l, &liter, sv->v, BM_LOOPS_OF_VERT, j) - { + BM_ITER_ELEM_INDEX (l, &liter, sv->v, BM_LOOPS_OF_VERT, j) { BMFace *f_copy = BLI_ghash_lookup(sod->origfaces, l->f); float f_copy_center[3]; BMIter liter_other; @@ -6513,8 +6619,7 @@ static void slide_origdata_interp_data_vert(SlideOrigData *sod, BM_face_calc_center_median(f_copy, f_copy_center); - BM_ITER_ELEM_INDEX(l_other, &liter_other, sv->v, BM_LOOPS_OF_VERT, j_other) - { + BM_ITER_ELEM_INDEX (l_other, &liter_other, sv->v, BM_LOOPS_OF_VERT, j_other) { BM_face_interp_multires_ex(bm, l_other->f, f_copy, @@ -6731,7 +6836,8 @@ static BMLoop *get_next_loop( cross_v3_v3v3(vec_accum, l_tmp->f->no, tdir); #if 0 /* rough guess, we can do better! */ - normalize_v3_length(vec_accum, (BM_edge_calc_length(e_prev) + BM_edge_calc_length(e_next)) / 2.0f); + normalize_v3_length(vec_accum, + (BM_edge_calc_length(e_prev) + BM_edge_calc_length(e_next)) / 2.0f); #else /* be clever, check the opposite ngon edge to slide into. * this gives best results */ @@ -6863,8 +6969,9 @@ static void calcEdgeSlide_mval_range(TransInfo *t, float dist_sq; int j, l_nr; - if (BM_elem_flag_test(e_other, BM_ELEM_SELECT)) + if (BM_elem_flag_test(e_other, BM_ELEM_SELECT)) { continue; + } /* This test is only relevant if object is not wire-drawn! See [#32068]. */ if (use_occlude_geometry && @@ -7106,15 +7213,18 @@ static bool createEdgeSlideVerts_double_side(TransInfo *t, TransDataContainer *t v = NULL; BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { - if (BM_elem_flag_test(v, BM_ELEM_TAG)) + if (BM_elem_flag_test(v, BM_ELEM_TAG)) { break; + } } - if (!v) + if (!v) { break; + } - if (!v->e) + if (!v->e) { continue; + } v_first = v; @@ -7129,8 +7239,9 @@ static bool createEdgeSlideVerts_double_side(TransInfo *t, TransDataContainer *t break; } - if (!BM_elem_flag_test(BM_edge_other_vert(e, v), BM_ELEM_TAG)) + if (!BM_elem_flag_test(BM_edge_other_vert(e, v), BM_ELEM_TAG)) { break; + } v = BM_edge_other_vert(e, v); } while (e != v_first->e); @@ -7284,10 +7395,12 @@ static bool createEdgeSlideVerts_double_side(TransInfo *t, TransDataContainer *t else { if (l_a || l_b) { /* find the opposite loop if it was missing previously */ - if (l_a == NULL && l_b && (l_b->radial_next != l_b)) + if (l_a == NULL && l_b && (l_b->radial_next != l_b)) { l_a = l_b->radial_next; - else if (l_b == NULL && l_a && (l_a->radial_next != l_a)) + } + else if (l_b == NULL && l_a && (l_a->radial_next != l_a)) { l_b = l_a->radial_next; + } } else if (e->l != NULL) { /* if there are non-contiguous faces, we can still recover @@ -7560,8 +7673,7 @@ static bool createEdgeSlideVerts_single_side(TransInfo *t, TransDataContainer *t void projectEdgeSlideData(TransInfo *t, bool is_final) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { EdgeSlideData *sld = tc->custom.mode.data; SlideOrigData *sod = &sld->orig_data; @@ -7589,8 +7701,9 @@ void freeEdgeSlideVerts(TransInfo *UNUSED(t), { EdgeSlideData *sld = custom_data->data; - if (!sld) + if (!sld) { return; + } freeEdgeSlideTempFaces(sld); @@ -7631,14 +7744,12 @@ static void initEdgeSlide_ex( } if (use_double_side) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { ok |= createEdgeSlideVerts_double_side(t, tc); } } else { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { ok |= createEdgeSlideVerts_single_side(t, tc); } } @@ -7648,8 +7759,7 @@ static void initEdgeSlide_ex( return; } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { sld = tc->custom.mode.data; if (!sld) { continue; @@ -7784,12 +7894,14 @@ static void drawEdgeSlide(TransInfo *t) GPU_point_size(ctrl_size); immBegin(GPU_PRIM_POINTS, 1); if (slp->flipped) { - if (curr_sv->v_side[1]) + if (curr_sv->v_side[1]) { immVertex3fv(pos, curr_sv->v_side[1]->co); + } } else { - if (curr_sv->v_side[0]) + if (curr_sv->v_side[0]) { immVertex3fv(pos, curr_sv->v_side[0]->co); + } } immEnd(); @@ -7861,8 +7973,7 @@ static void doEdgeSlide(TransInfo *t, float perc) if (is_clamp) { const int side_index = (perc < 0.0f); const float perc_final = fabsf(perc); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { EdgeSlideData *sld = tc->custom.mode.data; TransDataEdgeSlideVert *sv = sld->sv; for (int i = 0; i < sld->totsv; i++, sv++) { @@ -7875,8 +7986,7 @@ static void doEdgeSlide(TransInfo *t, float perc) const float perc_init = fabsf(perc) * ((sld_active->curr_side_unclamp == (perc < 0.0f)) ? 1 : -1); const int side_index = sld_active->curr_side_unclamp; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { EdgeSlideData *sld = tc->custom.mode.data; TransDataEdgeSlideVert *sv = sld->sv; for (int i = 0; i < sld->totsv; i++, sv++) { @@ -7896,12 +8006,14 @@ static void doEdgeSlide(TransInfo *t, float perc) } else { /** - * Implementation note, even mode ignores the starting positions and uses only the - * a/b verts, this could be changed/improved so the distance is still met but the verts are moved along - * their original path (which may not be straight), however how it works now is OK and matches 2.4x - Campbell + * Implementation note, even mode ignores the starting positions and uses + * only the a/b verts, this could be changed/improved so the distance is + * still met but the verts are moved along their original path (which may not be straight), + * however how it works now is OK and matches 2.4x - Campbell * - * \note len_v3v3(curr_sv->dir_side[0], curr_sv->dir_side[1]) - * is the same as the distance between the original vert locations, same goes for the lines below. + * \note `len_v3v3(curr_sv->dir_side[0], curr_sv->dir_side[1])` + * is the same as the distance between the original vert locations, + * same goes for the lines below. */ TransDataEdgeSlideVert *curr_sv = &sld_active->sv[sld_active->curr_sv_index]; const float curr_length_perc = curr_sv->edge_len * @@ -7910,8 +8022,7 @@ static void doEdgeSlide(TransInfo *t, float perc) float co_a[3]; float co_b[3]; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { EdgeSlideData *sld = tc->custom.mode.data; TransDataEdgeSlideVert *sv = sld->sv; for (int i = 0; i < sld->totsv; i++, sv++) { @@ -8215,8 +8326,7 @@ static bool createVertSlideVerts(TransInfo *t, TransDataContainer *tc) void projectVertSlideData(TransInfo *t, bool is_final) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { VertSlideData *sld = tc->custom.mode.data; SlideOrigData *sod = &sld->orig_data; if (sod->use_origfaces == true) { @@ -8241,8 +8351,9 @@ void freeVertSlideVerts(TransInfo *UNUSED(t), { VertSlideData *sld = custom_data->data; - if (!sld) + if (!sld) { return; + } freeVertSlideTempFaces(sld); @@ -8284,8 +8395,7 @@ static void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use } bool ok = false; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { ok |= createVertSlideVerts(t, tc); VertSlideData *sld = tc->custom.mode.data; if (sld) { @@ -8504,8 +8614,7 @@ static void doVertSlide(TransInfo *t, float perc) slp->perc = perc; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { VertSlideData *sld = tc->custom.mode.data; TransDataVertSlideVert *svlist = sld->sv, *sv; int i; @@ -8653,15 +8762,16 @@ static void applyBoneRoll(TransInfo *t, const int UNUSED(mval[2])) } /* set roll values */ - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } *(td->val) = td->ival - final; } @@ -8727,35 +8837,42 @@ static void applyBakeTime(TransInfo *t, const int mval[2]) outputNumInput(&(t->num), c, &t->scene->unit); - if (time >= 0.0f) + if (time >= 0.0f) { BLI_snprintf(str, sizeof(str), IFACE_("Time: +%s %s"), c, t->proptext); - else + } + else { BLI_snprintf(str, sizeof(str), IFACE_("Time: %s %s"), c, t->proptext); + } } else { /* default header print */ - if (time >= 0.0f) + if (time >= 0.0f) { BLI_snprintf(str, sizeof(str), IFACE_("Time: +%.3f %s"), time, t->proptext); - else + } + else { BLI_snprintf(str, sizeof(str), IFACE_("Time: %.3f %s"), time, t->proptext); + } } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } if (td->val) { *td->val = td->ival + time * td->factor; - if (td->ext->size && *td->val < *td->ext->size) + if (td->ext->size && *td->val < *td->ext->size) { *td->val = *td->ext->size; - if (td->ext->quat && *td->val > *td->ext->quat) + } + if (td->ext->quat && *td->val > *td->ext->quat) { *td->val = *td->ext->quat; + } } } } @@ -8807,15 +8924,16 @@ static void applyMirror(TransInfo *t, const int UNUSED(mval[2])) BLI_snprintf(str, sizeof(str), IFACE_("Mirror%s"), t->con.text); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } ElementResize(t, tc, td, mat); } @@ -8830,15 +8948,16 @@ static void applyMirror(TransInfo *t, const int UNUSED(mval[2])) size_to_mat3(mat, size); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } ElementResize(t, tc, td, mat); } @@ -8846,10 +8965,12 @@ static void applyMirror(TransInfo *t, const int UNUSED(mval[2])) recalcData(t); - if (t->flag & T_2D_EDIT) + if (t->flag & T_2D_EDIT) { ED_area_status_text(t->sa, IFACE_("Select a mirror axis (X, Y)")); - else + } + else { ED_area_status_text(t->sa, IFACE_("Select a mirror axis (X, Y, Z)")); + } } } /** \} */ @@ -8874,19 +8995,20 @@ static void applyAlign(TransInfo *t, const int UNUSED(mval[2])) float center[3]; int i; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { /* saving original center */ copy_v3_v3(center, tc->center_local); TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { float mat[3][3], invmat[3][3]; - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } /* around local centers */ if (t->flag & (T_OBJECT | T_POSE)) { @@ -8973,15 +9095,16 @@ static void applySeqSlideValue(TransInfo *t, const float val[2]) { int i; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } madd_v2_v2v2fl(td->loc, td->iloc, val, td->factor); } @@ -9037,20 +9160,23 @@ static short getAnimEdit_SnapMode(TransInfo *t) if (t->spacetype == SPACE_ACTION) { SpaceAction *saction = (SpaceAction *)t->sa->spacedata.first; - if (saction) + if (saction) { autosnap = saction->autosnap; + } } else if (t->spacetype == SPACE_GRAPH) { SpaceGraph *sipo = (SpaceGraph *)t->sa->spacedata.first; - if (sipo) + if (sipo) { autosnap = sipo->autosnap; + } } else if (t->spacetype == SPACE_NLA) { SpaceNla *snla = (SpaceNla *)t->sa->spacedata.first; - if (snla) + if (snla) { autosnap = snla->autosnap; + } } else { autosnap = SACTSNAP_OFF; @@ -9060,10 +9186,12 @@ static short getAnimEdit_SnapMode(TransInfo *t) * - when toggling on, prefer nearest frame over 1.0 frame increments */ if (t->modifiers & MOD_SNAP_INVERT) { - if (autosnap) + if (autosnap) { autosnap = SACTSNAP_OFF; - else + } + else { autosnap = SACTSNAP_FRAME; + } } return autosnap; @@ -9082,10 +9210,12 @@ static void doAnimEdit_SnapFrame( double val; /* convert frame to nla-action time (if needed) */ - if (adt) + if (adt) { val = BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_MAP); - else + } + else { val = *(td->val); + } /* do the snapping to nearest frame/second */ if (autosnap == SACTSNAP_FRAME) { @@ -9096,35 +9226,42 @@ static void doAnimEdit_SnapFrame( } /* convert frame out of nla-action time */ - if (adt) + if (adt) { *(td->val) = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP); - else + } + else { *(td->val) = val; + } } /* snap key to nearest marker? */ else if (autosnap == SACTSNAP_MARKER) { float val; /* convert frame to nla-action time (if needed) */ - if (adt) + if (adt) { val = BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_MAP); - else + } + else { val = *(td->val); + } /* snap to nearest marker */ // TODO: need some more careful checks for where data comes from val = (float)ED_markers_find_nearest_marker_time(&t->scene->markers, val); /* convert frame out of nla-action time */ - if (adt) + if (adt) { *(td->val) = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP); - else + } + else { *(td->val) = val; + } } - /* if the handles are to be moved too (as side-effect of keyframes moving, to keep the general effect) - * offset them by the same amount so that the general angles are maintained (i.e. won't change while - * handles are free-to-roam and keyframes are snap-locked) + /* If the handles are to be moved too + * (as side-effect of keyframes moving, to keep the general effect) + * offset them by the same amount so that the general angles are maintained + * (i.e. won't change while handles are free-to-roam and keyframes are snap-locked). */ if ((td->flag & TD_MOVEHANDLE1) && td2d->h1) { td2d->h1[0] = td2d->ih1[0] + *td->val - td->ival; @@ -9197,14 +9334,18 @@ static void headerTimeTranslate(TransInfo *t, char str[UI_MAX_DRAW_STR]) val = (float)((double)val / secf); } - if (autosnap == SACTSNAP_FRAME) + if (autosnap == SACTSNAP_FRAME) { BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%d.00 (%.4f)", (int)val, val); - else if (autosnap == SACTSNAP_SECOND) + } + else if (autosnap == SACTSNAP_SECOND) { BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%d.00 sec (%.4f)", (int)val, val); - else if (autosnap == SACTSNAP_TSTEP) + } + else if (autosnap == SACTSNAP_TSTEP) { BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f sec", val); - else + } + else { BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", val); + } } ofs += BLI_snprintf(str, UI_MAX_DRAW_STR, IFACE_("DeltaX: %s"), &tvec[0]); @@ -9225,11 +9366,11 @@ static void applyTimeTranslateValue(TransInfo *t) float deltax, val /* , valprev */; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; TransData2D *td2d = tc->data_2d; - /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */ + /* It doesn't matter whether we apply to t->data or + * t->data2d, but t->data2d is more convenient. */ for (i = 0; i < tc->data_len; i++, td++, td2d++) { /* it is assumed that td->extra is a pointer to the AnimData, * whose active action is where this keyframe comes from @@ -9334,21 +9475,23 @@ static void initTimeSlide(TransInfo *t) float min = 999999999.0f, max = -999999999.0f; int i; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL; float val = *(td->val); /* strip/action time to global (mapped) time */ - if (adt) + if (adt) { val = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_MAP); + } - if (min > val) + if (min > val) { min = val; - if (max < val) + } + if (max < val) { max = val; + } } } @@ -9415,9 +9558,9 @@ static void applyTimeSlideValue(TransInfo *t, float sval) saction->timeslide = cvalf; } - /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */ - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + /* It doesn't matter whether we apply to t->data or + * t->data2d, but t->data2d is more convenient. */ + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { /* it is assumed that td->extra is a pointer to the AnimData, @@ -9548,10 +9691,12 @@ static void headerTimeScale(TransInfo *t, char str[UI_MAX_DRAW_STR]) { char tvec[NUM_STR_REP_LEN * 3]; - if (hasNumInput(&t->num)) + if (hasNumInput(&t->num)) { outputNumInput(&(t->num), tvec, &t->scene->unit); - else + } + else { BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", t->values[0]); + } BLI_snprintf(str, UI_MAX_DRAW_STR, IFACE_("ScaleX: %s"), &tvec[0]); } @@ -9564,8 +9709,7 @@ static void applyTimeScaleValue(TransInfo *t) const short autosnap = getAnimEdit_SnapMode(t); const double secf = FPS; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; TransData2D *td2d = tc->data_2d; for (i = 0; i < tc->data_len; i++, td++, td2d++) { @@ -9588,8 +9732,9 @@ static void applyTimeScaleValue(TransInfo *t) fac = ((fac - 1.0f) * td->factor) + 1; /* check if any need to apply nla-mapping */ - if (adt) + if (adt) { startx = BKE_nla_tweakedit_remap(adt, startx, NLATIME_CONVERT_UNMAP); + } /* now, calculate the new value */ *(td->val) = ((td->ival - startx) * fac) + startx; diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 6451d82e45c..50fc1a276b9 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -824,9 +824,10 @@ enum { TD_BEZTRIPLE = 1 << 12, /** when this is set, don't apply translation changes to this element */ TD_NO_LOC = 1 << 13, - /** for Graph Editor autosnap, indicates that point should not undergo autosnapping */ + /** For Graph Editor autosnap, indicates that point should not undergo autosnapping */ TD_NOTIMESNAP = 1 << 14, - /** for Graph Editor - curves that can only have int-values need their keyframes tagged with this */ + /** For Graph Editor - curves that can only have int-values + * need their keyframes tagged with this. */ TD_INTVALUES = 1 << 15, /** For editmode mirror, clamp to x = 0 */ TD_MIRROR_EDGE = 1 << 16, diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index 27d6e597931..ee08eb20ea3 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -129,14 +129,17 @@ static void postConstraintChecks(TransInfo *t, float vec[3], float pvec[3]) snapGridIncrement(t, vec); if (t->flag & T_NULL_ONE) { - if (!(t->con.mode & CON_AXIS0)) + if (!(t->con.mode & CON_AXIS0)) { vec[0] = 1.0f; + } - if (!(t->con.mode & CON_AXIS1)) + if (!(t->con.mode & CON_AXIS1)) { vec[1] = 1.0f; + } - if (!(t->con.mode & CON_AXIS2)) + if (!(t->con.mode & CON_AXIS2)) { vec[2] = 1.0f; + } } if (applyNumInput(&t->num, vec)) { @@ -219,11 +222,14 @@ static void axisProjection(const TransInfo *t, if (angle < DEG2RADF(5.0f)) { project_v3_v3v3(vec, in, t->viewinv[1]); factor = dot_v3v3(t->viewinv[1], vec) * 2.0f; - /* since camera distance is quite relative, use quadratic relationship. holding shift can compensate */ - if (factor < 0.0f) + /* Since camera distance is quite relative, use quadratic relationship. + * holding shift can compensate. */ + if (factor < 0.0f) { factor *= -factor; - else + } + else { factor *= factor; + } /* -factor makes move down going backwards */ normalize_v3_v3_length(out, axis, -factor); @@ -266,12 +272,15 @@ static void axisProjection(const TransInfo *t, /* possible some values become nan when * viewpoint and object are both zero */ - if (!isfinite(out[0])) + if (!isfinite(out[0])) { out[0] = 0.0f; - if (!isfinite(out[1])) + } + if (!isfinite(out[1])) { out[1] = 0.0f; - if (!isfinite(out[2])) + } + if (!isfinite(out[2])) { out[2] = 0.0f; + } } } } @@ -740,12 +749,15 @@ void drawConstraint(TransInfo *t) { TransCon *tc = &(t->con); - if (!ELEM(t->spacetype, SPACE_VIEW3D, SPACE_IMAGE, SPACE_NODE)) + if (!ELEM(t->spacetype, SPACE_VIEW3D, SPACE_IMAGE, SPACE_NODE)) { return; - if (!(tc->mode & CON_APPLY)) + } + if (!(tc->mode & CON_APPLY)) { return; - if (t->flag & T_NO_CONSTRAINT) + } + if (t->flag & T_NO_CONSTRAINT) { return; + } if (tc->drawExtra) { tc->drawExtra(t); @@ -763,8 +775,9 @@ void drawConstraint(TransInfo *t) drawLine(t, t->center_global, tc->mtx[2], 'Z', 0); depth_test_enabled = GPU_depth_test_enabled(); - if (depth_test_enabled) + if (depth_test_enabled) { GPU_depth_test(false); + } const uint shdr_pos = GPU_vertformat_attr_add( immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); @@ -787,8 +800,9 @@ void drawConstraint(TransInfo *t) immUnbindProgram(); - if (depth_test_enabled) + if (depth_test_enabled) { GPU_depth_test(true); + } } if (tc->mode & CON_AXIS0) { @@ -840,8 +854,9 @@ void drawPropCircle(const struct bContext *C, TransInfo *t) } depth_test_enabled = GPU_depth_test_enabled(); - if (depth_test_enabled) + if (depth_test_enabled) { GPU_depth_test(false); + } uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); @@ -854,8 +869,9 @@ void drawPropCircle(const struct bContext *C, TransInfo *t) immUnbindProgram(); - if (depth_test_enabled) + if (depth_test_enabled) { GPU_depth_test(true); + } GPU_matrix_pop(); } @@ -873,8 +889,7 @@ static void drawObjectConstraint(TransInfo *t) int i; float tmp_axismtx[3][3]; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { float co[3]; @@ -990,8 +1005,9 @@ void selectConstraint(TransInfo *t) void postSelectConstraint(TransInfo *t) { - if (!(t->con.mode & CON_SELECT)) + if (!(t->con.mode & CON_SELECT)) { return; + } t->con.mode &= ~CON_AXIS0; t->con.mode &= ~CON_AXIS1; @@ -1150,14 +1166,17 @@ bool isLockConstraint(TransInfo *t) { int mode = t->con.mode; - if ((mode & (CON_AXIS0 | CON_AXIS1)) == (CON_AXIS0 | CON_AXIS1)) + if ((mode & (CON_AXIS0 | CON_AXIS1)) == (CON_AXIS0 | CON_AXIS1)) { return true; + } - if ((mode & (CON_AXIS1 | CON_AXIS2)) == (CON_AXIS1 | CON_AXIS2)) + if ((mode & (CON_AXIS1 | CON_AXIS2)) == (CON_AXIS1 | CON_AXIS2)) { return true; + } - if ((mode & (CON_AXIS0 | CON_AXIS2)) == (CON_AXIS0 | CON_AXIS2)) + if ((mode & (CON_AXIS0 | CON_AXIS2)) == (CON_AXIS0 | CON_AXIS2)) { return true; + } return false; } @@ -1174,21 +1193,24 @@ int getConstraintSpaceDimension(TransInfo *t) { int n = 0; - if (t->con.mode & CON_AXIS0) + if (t->con.mode & CON_AXIS0) { n++; + } - if (t->con.mode & CON_AXIS1) + if (t->con.mode & CON_AXIS1) { n++; + } - if (t->con.mode & CON_AXIS2) + if (t->con.mode & CON_AXIS2) { n++; + } return n; /* - * Someone willing to do it cryptically could do the following instead: - * - * return t->con & (CON_AXIS0|CON_AXIS1|CON_AXIS2); - * - * Based on the assumptions that the axis flags are one after the other and start at 1 - */ + * Someone willing to do it cryptically could do the following instead: + * + * return t->con & (CON_AXIS0|CON_AXIS1|CON_AXIS2); + * + * Based on the assumptions that the axis flags are one after the other and start at 1 + */ } diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index b682617f348..6c1da5ae825 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -146,12 +146,15 @@ static int trans_data_compare_dist(const void *a, const void *b) const TransData *td_a = (const TransData *)a; const TransData *td_b = (const TransData *)b; - if (td_a->dist < td_b->dist) + if (td_a->dist < td_b->dist) { return -1; - else if (td_a->dist > td_b->dist) + } + else if (td_a->dist > td_b->dist) { return 1; - else + } + else { return 0; + } } static int trans_data_compare_rdist(const void *a, const void *b) @@ -159,12 +162,15 @@ static int trans_data_compare_rdist(const void *a, const void *b) const TransData *td_a = (const TransData *)a; const TransData *td_b = (const TransData *)b; - if (td_a->rdist < td_b->rdist) + if (td_a->rdist < td_b->rdist) { return -1; - else if (td_a->rdist > td_b->rdist) + } + else if (td_a->rdist > td_b->rdist) { return 1; - else + } + else { return 0; + } } static void sort_trans_data_dist_container(const TransInfo *t, TransDataContainer *tc) @@ -187,8 +193,7 @@ static void sort_trans_data_dist_container(const TransInfo *t, TransDataContaine } void sort_trans_data_dist(TransInfo *t) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { sort_trans_data_dist_container(t, tc); } } @@ -222,8 +227,7 @@ static void sort_trans_data_container(TransDataContainer *tc) } static void sort_trans_data(TransInfo *t) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { sort_trans_data_container(tc); } } @@ -248,8 +252,7 @@ static void set_prop_dist(TransInfo *t, const bool with_dist) } } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *tob = tc->data; for (a = 0; a < tc->data_len; a++, tob++) { @@ -453,8 +456,7 @@ static void createTransCursor_view3d(TransInfo *t) static void createTransEdge(TransInfo *t) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); TransData *td = NULL; @@ -467,10 +469,12 @@ static void createTransEdge(TransInfo *t) BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) { - if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) + if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { countsel++; - if (is_prop_edit) + } + if (is_prop_edit) { count++; + } } } @@ -496,7 +500,7 @@ static void createTransEdge(TransInfo *t) BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(tc->obedit), ME_CDFLAG_EDGE_BWEIGHT); cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_BWEIGHT); } - else { //if (t->mode == TFM_CREASE) { + else { // if (t->mode == TFM_CREASE) { BLI_assert(t->mode == TFM_CREASE); BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(tc->obedit), ME_CDFLAG_EDGE_CREASE); cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_CREASE); @@ -512,10 +516,12 @@ static void createTransEdge(TransInfo *t) mid_v3_v3v3(td->center, eed->v1->co, eed->v2->co); td->loc = NULL; - if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) + if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { td->flag = TD_SELECTED; - else + } + else { td->flag = 0; + } copy_m3_m3(td->smtx, smtx); copy_m3_m3(td->mtx, mtx); @@ -542,10 +548,12 @@ static bKinematicConstraint *has_targetless_ik(bPoseChannel *pchan) if (con->type == CONSTRAINT_TYPE_KINEMATIC && (con->enforce != 0.0f)) { bKinematicConstraint *data = con->data; - if (data->tar == NULL) + if (data->tar == NULL) { return data; - if (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0) + } + if (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0) { return data; + } } } return NULL; @@ -569,18 +577,21 @@ static short apply_targetless_ik(Object *ob) segcount = 0; /* exclude tip from chain? */ - if (!(data->flag & CONSTRAINT_IK_TIP)) + if (!(data->flag & CONSTRAINT_IK_TIP)) { parchan = pchan->parent; - else + } + else { parchan = pchan; + } /* Find the chain's root & count the segments needed */ for (; parchan; parchan = parchan->parent) { chanlist[segcount] = parchan; segcount++; - if (segcount == data->rootbone || segcount > 255) + if (segcount == data->rootbone || segcount > 255) { break; // 255 is weak + } } for (; segcount; segcount--) { Bone *bone; @@ -600,32 +611,19 @@ static short apply_targetless_ik(Object *ob) /* apply and decompose, doesn't work for constraints or non-uniform scale well */ { float rmat3[3][3], qrmat[3][3], imat3[3][3], smat[3][3]; - copy_m3_m4(rmat3, rmat); /* rotation */ /* [#22409] is partially caused by this, as slight numeric error introduced during * the solving process leads to locked-axis values changing. However, we cannot modify * the values here, or else there are huge discrepancies between IK-solver (interactive) - * and applied poses. - */ - if (parchan->rotmode > 0) - mat3_to_eulO(parchan->eul, parchan->rotmode, rmat3); - else if (parchan->rotmode == ROT_MODE_AXISANGLE) - mat3_to_axis_angle(parchan->rotAxis, &parchan->rotAngle, rmat3); - else - mat3_to_quat(parchan->quat, rmat3); + * and applied poses. */ + BKE_pchan_mat3_to_rot(parchan, rmat3, false); /* for size, remove rotation */ /* causes problems with some constraints (so apply only if needed) */ if (data->flag & CONSTRAINT_IK_STRETCH) { - if (parchan->rotmode > 0) - eulO_to_mat3(qrmat, parchan->eul, parchan->rotmode); - else if (parchan->rotmode == ROT_MODE_AXISANGLE) - axis_angle_to_mat3(qrmat, parchan->rotAxis, parchan->rotAngle); - else - quat_to_mat3(qrmat, parchan->quat); - + BKE_pchan_rot_to_mat3(parchan, qrmat); invert_m3_m3(imat3, qrmat); mul_m3_m3m3(smat, rmat3, imat3); mat3_to_size(parchan->size, smat); @@ -711,10 +709,12 @@ static void add_pose_transdata( float rpmat[3][3]; BKE_bone_parent_transform_calc_from_pchan(pchan, &bpt); - if (t->mode == TFM_TRANSLATION) + if (t->mode == TFM_TRANSLATION) { copy_m3_m4(pmat, bpt.loc_mat); - else + } + else { copy_m3_m4(pmat, bpt.rotscale_mat); + } /* Grrr! Exceptional case: When translating pose bones that are either Hinge or NoLocal, * and want align snapping, we just need both loc_mat and rotscale_mat. @@ -831,16 +831,19 @@ int count_set_pose_transflags(Object *ob, for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { bone = pchan->bone; if (PBONE_VISIBLE(arm, bone)) { - if ((bone->flag & BONE_SELECTED)) + if ((bone->flag & BONE_SELECTED)) { bone->flag |= BONE_TRANSFORM; - else + } + else { bone->flag &= ~BONE_TRANSFORM; + } bone->flag &= ~BONE_HINGE_CHILD_TRANSFORM; bone->flag &= ~BONE_TRANSFORM_CHILD; } - else + else { bone->flag &= ~BONE_TRANSFORM; + } } /* make sure no bone can be transformed when a parent is transformed */ @@ -848,8 +851,9 @@ int count_set_pose_transflags(Object *ob, if (!ELEM(mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) { for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { bone = pchan->bone; - if (bone->flag & BONE_TRANSFORM) + if (bone->flag & BONE_TRANSFORM) { bone_children_clear_transflag(mode, around, &bone->childbase); + } } } /* now count, and check if we have autoIK or have to switch from translate to rotate */ @@ -947,8 +951,7 @@ void transform_autoik_update(TransInfo *t, short mode) /* apply to all pose-channels */ bool changed = false; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { /* sanity checks (don't assume t->poseobj is set, or that it is an armature) */ if (ELEM(NULL, tc->poseobj, tc->poseobj->pose)) { @@ -997,8 +1000,9 @@ static void pose_grab_with_ik_clear(Main *bmain, Object *ob) continue; } pchan->constflag |= PCHAN_HAS_IK; - if (data->tar == NULL || (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0)) + if (data->tar == NULL || (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0)) { pchan->constflag |= PCHAN_HAS_TARGET; + } } } } @@ -1017,8 +1021,9 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) bConstraint *con; /* Sanity check */ - if (pchan == NULL) + if (pchan == NULL) { return 0; + } /* Rule: not if there's already an IK on this channel */ for (con = pchan->constraints.first; con; con = con->next) { @@ -1040,12 +1045,15 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) for (; pchan; pchan = pchan->parent) { /* here, we set ik-settings for bone from pchan->protectflag */ // XXX: careful with quats/axis-angle rotations where we're locking 4d components - if (pchan->protectflag & OB_LOCK_ROTX) + if (pchan->protectflag & OB_LOCK_ROTX) { pchan->ikflag |= BONE_IK_NO_XDOF_TEMP; - if (pchan->protectflag & OB_LOCK_ROTY) + } + if (pchan->protectflag & OB_LOCK_ROTY) { pchan->ikflag |= BONE_IK_NO_YDOF_TEMP; - if (pchan->protectflag & OB_LOCK_ROTZ) + } + if (pchan->protectflag & OB_LOCK_ROTZ) { pchan->ikflag |= BONE_IK_NO_ZDOF_TEMP; + } } } @@ -1053,8 +1061,9 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) } } - if ((con->flag & CONSTRAINT_DISABLE) == 0 && (con->enforce != 0.0f)) + if ((con->flag & CONSTRAINT_DISABLE) == 0 && (con->enforce != 0.0f)) { return 0; + } } } @@ -1068,8 +1077,9 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) /* if exists, use values from last targetless (but disabled) IK-constraint as base */ *data = *targetless; } - else + else { data->flag = CONSTRAINT_IK_TIP; + } data->flag |= CONSTRAINT_IK_TEMP | CONSTRAINT_IK_AUTO | CONSTRAINT_IK_POS; copy_v3_v3(data->grabtarget, pchan->pose_tail); @@ -1081,21 +1091,26 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) do { /* here, we set ik-settings for bone from pchan->protectflag */ // XXX: careful with quats/axis-angle rotations where we're locking 4d components - if (pchan->protectflag & OB_LOCK_ROTX) + if (pchan->protectflag & OB_LOCK_ROTX) { pchan->ikflag |= BONE_IK_NO_XDOF_TEMP; - if (pchan->protectflag & OB_LOCK_ROTY) + } + if (pchan->protectflag & OB_LOCK_ROTY) { pchan->ikflag |= BONE_IK_NO_YDOF_TEMP; - if (pchan->protectflag & OB_LOCK_ROTZ) + } + if (pchan->protectflag & OB_LOCK_ROTZ) { pchan->ikflag |= BONE_IK_NO_ZDOF_TEMP; + } /* now we count this pchan as being included */ data->rootbone++; /* continue to parent, but only if we're connected to it */ - if (pchan->bone->flag & BONE_CONNECTED) + if (pchan->bone->flag & BONE_CONNECTED) { pchan = pchan->parent; - else + } + else { pchan = NULL; + } } while (pchan); /* make a copy of maximum chain-length */ @@ -1119,8 +1134,9 @@ static short pose_grab_with_ik_children(bPose *pose, Bone *bone) } if (wentdeeper == 0) { bPoseChannel *pchan = BKE_pose_channel_find_name(pose, bone->name); - if (pchan) + if (pchan) { added += pose_grab_with_ik_add(pchan); + } } return added; @@ -1134,8 +1150,9 @@ static short pose_grab_with_ik(Main *bmain, Object *ob) Bone *bonec; short tot_ik = 0; - if ((ob == NULL) || (ob->pose == NULL) || (ob->mode & OB_MODE_POSE) == 0) + if ((ob == NULL) || (ob->pose == NULL) || (ob->mode & OB_MODE_POSE) == 0) { return 0; + } arm = ob->data; @@ -1150,18 +1167,21 @@ static short pose_grab_with_ik(Main *bmain, Object *ob) break; } } - if ((pchan->bone->flag & BONE_CONNECTED) == 0 && (bonec == NULL)) + if ((pchan->bone->flag & BONE_CONNECTED) == 0 && (bonec == NULL)) { continue; + } /* rule: if selected Bone is not a root bone, it gets a temporal IK */ if (pchan->parent) { /* only adds if there's no IK yet (and no parent bone was selected) */ for (parent = pchan->parent; parent; parent = parent->parent) { - if (parent->bone->flag & BONE_SELECTED) + if (parent->bone->flag & BONE_SELECTED) { break; + } } - if (parent == NULL) + if (parent == NULL) { tot_ik += pose_grab_with_ik_add(pchan); + } } else { /* rule: go over the children and add IK to the tips */ @@ -1193,8 +1213,7 @@ static void createTransPose(TransInfo *t) bool has_translate_rotate_buf[2] = {false, false}; bool *has_translate_rotate = (t->mode == TFM_TRANSLATION) ? has_translate_rotate_buf : NULL; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { Object *ob = tc->poseobj; bArmature *arm; @@ -1240,8 +1259,7 @@ static void createTransPose(TransInfo *t) } } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { if (tc->data_len == 0) { continue; } @@ -1288,10 +1306,18 @@ static void createTransPose(TransInfo *t) void restoreBones(TransDataContainer *tc) { - bArmature *arm = tc->obedit->data; + bArmature *arm; BoneInitData *bid = tc->custom.type.data; EditBone *ebo; + if (tc->obedit) { + arm = tc->obedit->data; + } + else { + BLI_assert(tc->poseobj != NULL); + arm = tc->poseobj->data; + } + while (bid->bone) { ebo = bid->bone; @@ -1331,8 +1357,7 @@ static void createTransArmatureVerts(TransInfo *t) { t->data_len_all = 0; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { EditBone *ebo, *eboflip; bArmature *arm = tc->obedit->data; ListBase *edbo = arm->edbo; @@ -1345,25 +1370,30 @@ static void createTransArmatureVerts(TransInfo *t) if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) { if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) { - if (ebo->flag & BONE_SELECTED) + if (ebo->flag & BONE_SELECTED) { tc->data_len++; + } } else if (t->mode == TFM_BONE_ROLL) { - if (ebo->flag & BONE_SELECTED) + if (ebo->flag & BONE_SELECTED) { tc->data_len++; + } } else { - if (ebo->flag & BONE_TIPSEL) + if (ebo->flag & BONE_TIPSEL) { tc->data_len++; - if (ebo->flag & BONE_ROOTSEL) + } + if (ebo->flag & BONE_ROOTSEL) { tc->data_len++; + } } } if (mirror && (data_len_prev < tc->data_len)) { eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo); - if (eboflip) + if (eboflip) { total_mirrored++; + } } } if (!tc->data_len) { @@ -1385,8 +1415,7 @@ static void createTransArmatureVerts(TransInfo *t) transform_around_single_fallback(t); t->data_len_all = -1; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { if (!tc->data_len) { continue; } @@ -1507,8 +1536,9 @@ static void createTransArmatureVerts(TransInfo *t) td->loc = ebo->tail; td->flag = TD_SELECTED; - if (ebo->flag & BONE_EDITMODE_LOCKED) + if (ebo->flag & BONE_EDITMODE_LOCKED) { td->protectflag = OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE; + } copy_m3_m3(td->smtx, smtx); copy_m3_m3(td->mtx, mtx); @@ -1531,8 +1561,9 @@ static void createTransArmatureVerts(TransInfo *t) copy_v3_v3(td->center, td->iloc); td->loc = ebo->head; td->flag = TD_SELECTED; - if (ebo->flag & BONE_EDITMODE_LOCKED) + if (ebo->flag & BONE_EDITMODE_LOCKED) { td->protectflag = OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE; + } copy_m3_m3(td->smtx, smtx); copy_m3_m3(td->mtx, mtx); @@ -1579,8 +1610,7 @@ static void createTransArmatureVerts(TransInfo *t) static void createTransMBallVerts(TransInfo *t) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { MetaBall *mb = (MetaBall *)tc->obedit->data; MetaElem *ml; TransData *td; @@ -1591,10 +1621,12 @@ static void createTransMBallVerts(TransInfo *t) /* count totals */ for (ml = mb->editelems->first; ml; ml = ml->next) { - if (ml->flag & SELECT) + if (ml->flag & SELECT) { countsel++; - if (is_prop_edit) + } + if (is_prop_edit) { count++; + } } /* note: in prop mode we need at least 1 selected */ @@ -1602,10 +1634,12 @@ static void createTransMBallVerts(TransInfo *t) continue; } - if (is_prop_edit) + if (is_prop_edit) { tc->data_len = count; - else + } + else { tc->data_len = countsel; + } td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(MBall EditMode)"); tx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension), @@ -1622,10 +1656,12 @@ static void createTransMBallVerts(TransInfo *t) quat_to_mat3(td->axismtx, ml->quat); - if (ml->flag & SELECT) + if (ml->flag & SELECT) { td->flag = TD_SELECTED | TD_USEQUAT | TD_SINGLESIZE; - else + } + else { td->flag = TD_USEQUAT; + } copy_m3_m3(td->smtx, smtx); copy_m3_m3(td->mtx, mtx); @@ -1766,8 +1802,7 @@ static void createTransCurveVerts(TransInfo *t) t->data_len_all = 0; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { Curve *cu = tc->obedit->data; BLI_assert(cu->editnurb != NULL); BezTriple *bezt; @@ -1796,18 +1831,21 @@ static void createTransCurveVerts(TransInfo *t) if (bezt_tx & SEL_F3) { countsel++; } - if (is_prop_edit) + if (is_prop_edit) { count += 3; + } } } } else { for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a > 0; a--, bp++) { if (bp->hide == 0) { - if (is_prop_edit) + if (is_prop_edit) { count++; - if (bp->f1 & SELECT) + } + if (bp->f1 & SELECT) { countsel++; + } } } } @@ -1818,10 +1856,12 @@ static void createTransCurveVerts(TransInfo *t) continue; } - if (is_prop_edit) + if (is_prop_edit) { tc->data_len = count; - else + } + else { tc->data_len = countsel; + } tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Curve EditMode)"); t->data_len_all += tc->data_len; @@ -1830,8 +1870,7 @@ static void createTransCurveVerts(TransInfo *t) transform_around_single_fallback(t); t->data_len_all = -1; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { if (tc->data_len == 0) { continue; } @@ -1890,16 +1929,20 @@ static void createTransCurveVerts(TransInfo *t) 1 : 0]); if (hide_handles) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { td->flag = TD_SELECTED; - else + } + else { td->flag = 0; + } } else { - if (bezt->f1 & SELECT) + if (bezt->f1 & SELECT) { td->flag = TD_SELECTED; - else + } + else { td->flag = 0; + } } td->ext = NULL; td->val = NULL; @@ -1921,10 +1964,12 @@ static void createTransCurveVerts(TransInfo *t) copy_v3_v3(td->iloc, bezt->vec[1]); td->loc = bezt->vec[1]; copy_v3_v3(td->center, td->loc); - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { td->flag = TD_SELECTED; - else + } + else { td->flag = 0; + } td->ext = NULL; /* TODO - make points scale */ @@ -1946,12 +1991,13 @@ static void createTransCurveVerts(TransInfo *t) copy_m3_m3(td->axismtx, axismtx); } - if ((bezt_tx & SEL_F1) == 0 && (bezt_tx & SEL_F3) == 0) + if ((bezt_tx & SEL_F1) == 0 && (bezt_tx & SEL_F3) == 0) { /* If the middle is selected but the sides arnt, this is needed */ if (hdata == NULL) { /* if the handle was not saved by the previous handle */ hdata = initTransDataCurveHandles(td, bezt); } + } td++; tail++; @@ -1965,16 +2011,20 @@ static void createTransCurveVerts(TransInfo *t) 1 : 2]); if (hide_handles) { - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { td->flag = TD_SELECTED; - else + } + else { td->flag = 0; + } } else { - if (bezt->f3 & SELECT) + if (bezt->f3 & SELECT) { td->flag = TD_SELECTED; - else + } + else { td->flag = 0; + } } td->ext = NULL; td->val = NULL; @@ -2001,11 +2051,12 @@ static void createTransCurveVerts(TransInfo *t) head = tail; } } - if (is_prop_edit && head != tail) + if (is_prop_edit && head != tail) { calc_distanceCurveVerts(head, tail - 1); + } - /* TODO - in the case of tilt and radius we can also avoid allocating the initTransDataCurveHandles - * but for now just don't change handle types */ + /* TODO - in the case of tilt and radius we can also avoid allocating the + * initTransDataCurveHandles but for now just don't change handle types */ if (ELEM(t->mode, TFM_CURVE_SHRINKFATTEN, TFM_TILT, TFM_DUMMY) == 0) { /* sets the handles based on their selection, * do this after the data is copied to the TransData */ @@ -2041,10 +2092,12 @@ static void createTransCurveVerts(TransInfo *t) copy_v3_v3(td->iloc, bp->vec); td->loc = bp->vec; copy_v3_v3(td->center, td->loc); - if (bp->f1 & SELECT) + if (bp->f1 & SELECT) { td->flag = TD_SELECTED; - else + } + else { td->flag = 0; + } td->ext = NULL; if (t->mode == TFM_CURVE_SHRINKFATTEN || t->mode == TFM_RESIZE) { @@ -2073,8 +2126,9 @@ static void createTransCurveVerts(TransInfo *t) head = tail; } } - if (is_prop_edit && head != tail) + if (is_prop_edit && head != tail) { calc_distanceCurveVerts(head, tail - 1); + } } } } @@ -2087,8 +2141,7 @@ static void createTransCurveVerts(TransInfo *t) static void createTransLatticeVerts(TransInfo *t) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { Lattice *latt = ((Lattice *)tc->obedit->data)->editlatt->latt; TransData *td = NULL; @@ -2102,22 +2155,27 @@ static void createTransLatticeVerts(TransInfo *t) a = latt->pntsu * latt->pntsv * latt->pntsw; while (a--) { if (bp->hide == 0) { - if (bp->f1 & SELECT) + if (bp->f1 & SELECT) { countsel++; - if (is_prop_edit) + } + if (is_prop_edit) { count++; + } } bp++; } /* note: in prop mode we need at least 1 selected */ - if (countsel == 0) + if (countsel == 0) { return; + } - if (is_prop_edit) + if (is_prop_edit) { tc->data_len = count; - else + } + else { tc->data_len = countsel; + } tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Lattice EditMode)"); copy_m3_m4(mtx, tc->obedit->obmat); @@ -2155,8 +2213,7 @@ static void createTransLatticeVerts(TransInfo *t) /* ******************* particle edit **************** */ static void createTransParticleVerts(bContext *C, TransInfo *t) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = NULL; TransDataExtension *tx; @@ -2171,8 +2228,9 @@ static void createTransParticleVerts(bContext *C, TransInfo *t) int count = 0, hasselected = 0; const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; - if (edit == NULL || t->settings->particle.selectmode == SCE_SELECT_PATH) + if (edit == NULL || t->settings->particle.selectmode == SCE_SELECT_PATH) { return; + } psys = edit->psys; @@ -2187,8 +2245,9 @@ static void createTransParticleVerts(bContext *C, TransInfo *t) hasselected = 1; transformparticle = 1; } - else if (is_prop_edit) + else if (is_prop_edit) { transformparticle = 1; + } } } } @@ -2200,17 +2259,20 @@ static void createTransParticleVerts(bContext *C, TransInfo *t) } /* note: in prop mode we need at least 1 selected */ - if (hasselected == 0) + if (hasselected == 0) { return; + } tc->data_len = count; td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Particle Mode)"); - if (t->mode == TFM_BAKE_TIME) + if (t->mode == TFM_BAKE_TIME) { tx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension), "Particle_TransExtension"); - else + } + else { tx = tc->data_ext = NULL; + } unit_m4(mat); @@ -2220,8 +2282,9 @@ static void createTransParticleVerts(bContext *C, TransInfo *t) TransData *head, *tail; head = tail = td; - if (!(point->flag & PEP_TRANSFORM)) + if (!(point->flag & PEP_TRANSFORM)) { continue; + } if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { ParticleSystemModifierData *psmd_eval = edit->psmd_eval; @@ -2235,23 +2298,27 @@ static void createTransParticleVerts(bContext *C, TransInfo *t) mul_m4_v3(mat, key->world_co); td->loc = key->world_co; } - else + else { td->loc = key->co; + } copy_v3_v3(td->iloc, td->loc); copy_v3_v3(td->center, td->loc); - if (key->flag & PEK_SELECT) + if (key->flag & PEK_SELECT) { td->flag |= TD_SELECTED; - else if (!is_prop_edit) + } + else if (!is_prop_edit) { td->flag |= TD_SKIP; + } unit_m3(td->mtx); unit_m3(td->smtx); /* don't allow moving roots */ - if (k == 0 && pset->flag & PE_LOCK_FIRST && (!psys || !(psys->flag & PSYS_GLOBAL_HAIR))) + if (k == 0 && pset->flag & PE_LOCK_FIRST && (!psys || !(psys->flag & PSYS_GLOBAL_HAIR))) { td->protectflag |= OB_LOCK_LOC; + } td->ob = ob; td->ext = tx; @@ -2260,32 +2327,37 @@ static void createTransParticleVerts(bContext *C, TransInfo *t) td->ival = *(key->time); /* abuse size and quat for min/max values */ td->flag |= TD_NO_EXT; - if (k == 0) + if (k == 0) { tx->size = NULL; - else + } + else { tx->size = (key - 1)->time; + } - if (k == point->totkey - 1) + if (k == point->totkey - 1) { tx->quat = NULL; - else + } + else { tx->quat = (key + 1)->time; + } } td++; - if (tx) + if (tx) { tx++; + } tail++; } - if (is_prop_edit && head != tail) + if (is_prop_edit && head != tail) { calc_distanceCurveVerts(head, tail - 1); + } } } } void flushTransParticles(TransInfo *t) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { Scene *scene = t->scene; ViewLayer *view_layer = t->view_layer; Object *ob = OBACT(view_layer); @@ -2302,8 +2374,9 @@ void flushTransParticles(TransInfo *t) * back to particle local space (only for hair particles) */ td = tc->data; for (i = 0, point = edit->points; i < edit->totpoint; i++, point++, td++) { - if (!(point->flag & PEP_TRANSFORM)) + if (!(point->flag & PEP_TRANSFORM)) { continue; + } if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { ParticleSystemModifierData *psmd_eval = edit->psmd_eval; @@ -2322,8 +2395,9 @@ void flushTransParticles(TransInfo *t) } } } - else + else { point->flag |= PEP_EDIT_RECALC; + } } PE_update_object(t->depsgraph, scene, OBACT(view_layer), 1); @@ -2679,9 +2753,9 @@ static void VertsToTransData(TransInfo *t, BLI_assert(BM_elem_flag_test(eve, BM_ELEM_HIDDEN) == 0); td->flag = 0; - //if (key) + // if (key) // td->loc = key->co; - //else + // else td->loc = eve->co; copy_v3_v3(td->iloc, td->loc); @@ -2739,8 +2813,7 @@ static void VertsToTransData(TransInfo *t, static void createTransEditVerts(TransInfo *t) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *tob = NULL; TransDataExtension *tx = NULL; BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); @@ -2784,7 +2857,8 @@ static void createTransEditVerts(TransInfo *t) /** * Quick check if we can transform. * - * \note ignore modes here, even in edge/face modes, transform data is created by selected vertices. + * \note ignore modes here, even in edge/face modes, + * transform data is created by selected vertices. * \note in prop mode we need at least 1 selected. */ if (bm->totvertsel == 0) { @@ -2838,7 +2912,8 @@ static void createTransEditVerts(TransInfo *t) } if (is_island_center) { - /* In this specific case, near-by vertices will need to know the island of the nearest connected vertex. */ + /* In this specific case, near-by vertices will need to know + * the island of the nearest connected vertex. */ const bool calc_single_islands = ((prop_mode & T_PROP_CONNECTED) && (t->around == V3D_AROUND_LOCAL_ORIGINS) && (em->selectmode & SCE_SELECT_VERTEX)); @@ -2874,8 +2949,9 @@ static void createTransEditVerts(TransInfo *t) mappedcos = BKE_crazyspace_get_mapped_editverts(t->depsgraph, t->scene, tc->obedit); quats = MEM_mallocN(em->bm->totvert * sizeof(*quats), "crazy quats"); BKE_crazyspace_set_quats_editmesh(em, defcos, mappedcos, quats, !prop_mode); - if (mappedcos) + if (mappedcos) { MEM_freeN(mappedcos); + } } if (defcos) { @@ -2914,12 +2990,14 @@ static void createTransEditVerts(TransInfo *t) /* Do not use the island center in case we are using islands * only to get axis for snap/rotate to normal... */ VertsToTransData(t, tob, tx, em, eve, bweight, v_island, is_snap_rotate); - if (tx) + if (tx) { tx++; + } /* selected */ - if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) + if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { tob->flag |= TD_SELECTED; + } if (prop_mode) { if (prop_mode & T_PROP_CONNECTED) { @@ -2932,20 +3010,24 @@ static void createTransEditVerts(TransInfo *t) } /* CrazySpace */ - if (defmats || (quats && BM_elem_flag_test(eve, BM_ELEM_TAG))) { + const bool use_quats = quats && BM_elem_flag_test(eve, BM_ELEM_TAG); + if (use_quats || defmats) { float mat[3][3], qmat[3][3], imat[3][3]; - /* use both or either quat and defmat correction */ - if (quats && BM_elem_flag_test(eve, BM_ELEM_TAG)) { + /* Use both or either quat and defmat correction. */ + if (use_quats) { quat_to_mat3(qmat, quats[BM_elem_index_get(eve)]); - if (defmats) + if (defmats) { mul_m3_series(mat, defmats[a], qmat, mtx); - else + } + else { mul_m3_m3m3(mat, mtx, qmat); + } } - else + else { mul_m3_m3m3(mat, mtx, defmats[a]); + } invert_m3_m3(imat, mat); @@ -2959,7 +3041,7 @@ static void createTransEditVerts(TransInfo *t) /* Mirror? */ if ((mirror > 0 && tob->iloc[0] > 0.0f) || (mirror < 0 && tob->iloc[0] < 0.0f)) { - BMVert *vmir = EDBM_verts_mirror_get(em, eve); //t->obedit, em, eve, tob->iloc, a); + BMVert *vmir = EDBM_verts_mirror_get(em, eve); // t->obedit, em, eve, tob->iloc, a); if (vmir && vmir != eve) { tob->extra = vmir; } @@ -2985,14 +3067,18 @@ static void createTransEditVerts(TransInfo *t) cleanup: /* crazy space free */ - if (quats) + if (quats) { MEM_freeN(quats); - if (defmats) + } + if (defmats) { MEM_freeN(defmats); - if (dists) + } + if (dists) { MEM_freeN(dists); - if (dists_index) + } + if (dists_index) { MEM_freeN(dists_index); + } if (tc->mirror.axis_flag) { EDBM_verts_mirror_cache_end(em); @@ -3005,8 +3091,7 @@ void flushTransNodes(TransInfo *t) { const float dpi_fac = UI_DPI_FAC; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { int a; TransData *td; TransData2D *td2d; @@ -3063,8 +3148,9 @@ BLI_INLINE void trans_update_seq(Scene *sce, Sequence *seq, int old_start, int s BKE_sequence_calc_disp(sce, seq); } - if (sel_flag == SELECT) + if (sel_flag == SELECT) { BKE_sequencer_offset_animdata(sce, seq, seq->start - old_start); + } } void flushTransSeq(TransInfo *t) @@ -3128,8 +3214,9 @@ void flushTransSeq(TransInfo *t) break; } - /* Update *previous* seq! Else, we would update a seq after its first transform, and if it has more than one - * (like e.g. SEQ_LEFTSEL and SEQ_RIGHTSEL), the others are not updated! See T38469. + /* Update *previous* seq! Else, we would update a seq after its first transform, + * and if it has more than one (like e.g. SEQ_LEFTSEL and SEQ_RIGHTSEL), + * the others are not updated! See T38469. */ if (seq != seq_prev) { if (seq_prev) { @@ -3253,8 +3340,7 @@ static void createTransUVs(bContext *C, TransInfo *t) const bool is_prop_connected = (t->flag & T_PROP_CONNECTED) != 0; const bool is_island_center = (t->around == V3D_AROUND_LOCAL_ORIGINS); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = NULL; TransData2D *td2d = NULL; @@ -3349,8 +3435,9 @@ static void createTransUVs(bContext *C, TransInfo *t) * treated just as if they were 3d verts */ tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransObData2D(UV Editing)"); - if (sima->flag & SI_CLIP_UV) + if (sima->flag & SI_CLIP_UV) { t->flag |= T_CLIP_UV; + } td = tc->data; td2d = tc->data_2d; @@ -3358,16 +3445,18 @@ static void createTransUVs(bContext *C, TransInfo *t) BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { BMLoop *l; - if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) + if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { const bool selected = uvedit_uv_select_test(scene, l, cd_loop_uv_offset); MLoopUV *luv; const float *center = NULL; - if (!is_prop_edit && !selected) + if (!is_prop_edit && !selected) { continue; + } if (is_prop_connected || is_island_center) { UvElement *element = BM_uv_element_get(elementmap, efa, l); @@ -3419,8 +3508,7 @@ void flushTransUVs(TransInfo *t) const bool use_pixel_snap = ((sima->pixel_snap_mode != SI_PIXEL_SNAP_DISABLED) && (t->state != TRANS_CANCEL)); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData2D *td; int a; float aspect_inv[2], size[2]; @@ -3471,8 +3559,7 @@ bool clipUVTransform(TransInfo *t, float vec[2], const bool resize) max[0] = t->aspect[0]; max[1] = t->aspect[1]; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td; int a; @@ -3482,34 +3569,48 @@ bool clipUVTransform(TransInfo *t, float vec[2], const bool resize) } if (resize) { - if (min[0] < 0.0f && t->center_global[0] > 0.0f && t->center_global[0] < t->aspect[0] * 0.5f) + if (min[0] < 0.0f && t->center_global[0] > 0.0f && + t->center_global[0] < t->aspect[0] * 0.5f) { vec[0] *= t->center_global[0] / (t->center_global[0] - min[0]); - else if (max[0] > t->aspect[0] && t->center_global[0] < t->aspect[0]) + } + else if (max[0] > t->aspect[0] && t->center_global[0] < t->aspect[0]) { vec[0] *= (t->center_global[0] - t->aspect[0]) / (t->center_global[0] - max[0]); - else + } + else { clipx = 0; + } - if (min[1] < 0.0f && t->center_global[1] > 0.0f && t->center_global[1] < t->aspect[1] * 0.5f) + if (min[1] < 0.0f && t->center_global[1] > 0.0f && + t->center_global[1] < t->aspect[1] * 0.5f) { vec[1] *= t->center_global[1] / (t->center_global[1] - min[1]); - else if (max[1] > t->aspect[1] && t->center_global[1] < t->aspect[1]) + } + else if (max[1] > t->aspect[1] && t->center_global[1] < t->aspect[1]) { vec[1] *= (t->center_global[1] - t->aspect[1]) / (t->center_global[1] - max[1]); - else + } + else { clipy = 0; + } } else { - if (min[0] < 0.0f) + if (min[0] < 0.0f) { vec[0] -= min[0]; - else if (max[0] > t->aspect[0]) + } + else if (max[0] > t->aspect[0]) { vec[0] -= max[0] - t->aspect[0]; - else + } + else { clipx = 0; + } - if (min[1] < 0.0f) + if (min[1] < 0.0f) { vec[1] -= min[1]; - else if (max[1] > t->aspect[1]) + } + else if (max[1] > t->aspect[1]) { vec[1] -= max[1] - t->aspect[1]; - else + } + else { clipy = 0; + } } } @@ -3518,15 +3619,16 @@ bool clipUVTransform(TransInfo *t, float vec[2], const bool resize) void clipUVData(TransInfo *t) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (int a = 0; a < tc->data_len; a++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if ((td->flag & TD_SKIP) || (!td->loc)) + if ((td->flag & TD_SKIP) || (!td->loc)) { continue; + } td->loc[0] = min_ff(max_ff(0.0f, td->loc[0]), t->aspect[0]); td->loc[1] = min_ff(max_ff(0.0f, td->loc[1]), t->aspect[1]); @@ -3540,14 +3642,17 @@ void clipUVData(TransInfo *t) static bool FrameOnMouseSide(char side, float frame, float cframe) { /* both sides, so it doesn't matter */ - if (side == 'B') + if (side == 'B') { return true; + } /* only on the named side */ - if (side == 'R') + if (side == 'R') { return (frame >= cframe); - else + } + else { return (frame <= cframe); + } } /* ********************* NLA EDITOR ************************* */ @@ -3569,8 +3674,9 @@ static void createTransNlaData(bContext *C, TransInfo *t) TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); /* determine what type of data we are operating on */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return; + } snla = (SpaceNla *)ac.sl; /* filter data */ @@ -3604,10 +3710,12 @@ static void createTransNlaData(bContext *C, TransInfo *t) /* transition strips can't get directly transformed */ if (strip->type != NLASTRIP_TYPE_TRANSITION) { if (strip->flag & NLASTRIP_FLAG_SELECT) { - if (FrameOnMouseSide(t->frame_side, strip->start, (float)CFRA)) + if (FrameOnMouseSide(t->frame_side, strip->start, (float)CFRA)) { count++; - if (FrameOnMouseSide(t->frame_side, strip->end, (float)CFRA)) + } + if (FrameOnMouseSide(t->frame_side, strip->end, (float)CFRA)) { count++; + } } } } @@ -3746,13 +3854,16 @@ static void createTransNlaData(bContext *C, TransInfo *t) td++; } - /* if both handles were used, skip the next tdn (i.e. leave it blank) since the counting code is dumb... - * otherwise, just advance to the next one... + /* If both handles were used, skip the next tdn (i.e. leave it blank) + * since the counting code is dumb. + * Otherwise, just advance to the next one. */ - if (tdn->handle == 2) + if (tdn->handle == 2) { tdn += 2; - else + } + else { tdn++; + } } } } @@ -3770,10 +3881,12 @@ static int gpf_cmp_frame(void *thunk, const void *a, const void *b) const bGPDframe *frame_a = a; const bGPDframe *frame_b = b; - if (frame_a->framenum < frame_b->framenum) + if (frame_a->framenum < frame_b->framenum) { return -1; - if (frame_a->framenum > frame_b->framenum) + } + if (frame_a->framenum > frame_b->framenum) { return 1; + } *((bool *)thunk) = true; /* selected last */ if ((frame_a->flag & GP_FRAME_SELECT) && ((frame_b->flag & GP_FRAME_SELECT) == 0)) { @@ -3787,10 +3900,12 @@ static int masklay_shape_cmp_frame(void *thunk, const void *a, const void *b) const MaskLayerShape *frame_a = a; const MaskLayerShape *frame_b = b; - if (frame_a->frame < frame_b->frame) + if (frame_a->frame < frame_b->frame) { return -1; - if (frame_a->frame > frame_b->frame) + } + if (frame_a->frame > frame_b->frame) { return 1; + } *((bool *)thunk) = true; /* selected last */ if ((frame_a->flag & MASK_SHAPE_SELECT) && ((frame_b->flag & MASK_SHAPE_SELECT) == 0)) { @@ -3883,8 +3998,9 @@ static void posttrans_fcurve_clean(FCurve *fcu, const bool use_handle) 0); /* sanity checks */ - if ((fcu->totvert == 0) || (fcu->bezt == NULL)) + if ((fcu->totvert == 0) || (fcu->bezt == NULL)) { return; + } /* 1) Identify selected keyframes, and average the values on those * in case there are collisions due to multiple keys getting scaled @@ -4017,8 +4133,9 @@ static void posttrans_action_clean(bAnimContext *ac, bAction *act) posttrans_fcurve_clean(ale->key_data, false); /* only use handles in graph editor */ ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0); } - else + else { posttrans_fcurve_clean(ale->key_data, false); /* only use handles in graph editor */ + } } /* free temp data */ @@ -4033,25 +4150,29 @@ static int count_fcurve_keys(FCurve *fcu, char side, float cfra, bool is_prop_ed BezTriple *bezt; int i, count = 0, count_all = 0; - if (ELEM(NULL, fcu, fcu->bezt)) + if (ELEM(NULL, fcu, fcu->bezt)) { return count; + } /* only include points that occur on the right side of cfra */ for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) { if (FrameOnMouseSide(side, bezt->vec[1][0], cfra)) { /* no need to adjust the handle selection since they are assumed * selected (like graph editor with SIPO_NOHANDLES) */ - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { count++; + } count_all++; } } - if (is_prop_edit && count > 0) + if (is_prop_edit && count > 0) { return count_all; - else + } + else { return count; + } } /* fully select selected beztriples, but only include if it's on the right side of cfra */ @@ -4060,22 +4181,26 @@ static int count_gplayer_frames(bGPDlayer *gpl, char side, float cfra, bool is_p bGPDframe *gpf; int count = 0, count_all = 0; - if (gpl == NULL) + if (gpl == NULL) { return count; + } /* only include points that occur on the right side of cfra */ for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { if (FrameOnMouseSide(side, (float)gpf->framenum, cfra)) { - if (gpf->flag & GP_FRAME_SELECT) + if (gpf->flag & GP_FRAME_SELECT) { count++; + } count_all++; } } - if (is_prop_edit && count > 0) + if (is_prop_edit && count > 0) { return count_all; - else + } + else { return count; + } } /* fully select selected beztriples, but only include if it's on the right side of cfra */ @@ -4084,23 +4209,27 @@ static int count_masklayer_frames(MaskLayer *masklay, char side, float cfra, boo MaskLayerShape *masklayer_shape; int count = 0, count_all = 0; - if (masklay == NULL) + if (masklay == NULL) { return count; + } /* only include points that occur on the right side of cfra */ for (masklayer_shape = masklay->splines_shapes.first; masklayer_shape; masklayer_shape = masklayer_shape->next) { if (FrameOnMouseSide(side, (float)masklayer_shape->frame, cfra)) { - if (masklayer_shape->flag & MASK_SHAPE_SELECT) + if (masklayer_shape->flag & MASK_SHAPE_SELECT) { count++; + } count_all++; } } - if (is_prop_edit && count > 0) + if (is_prop_edit && count > 0) { return count_all; - else + } + else { return count; + } } /* This function assigns the information to transdata */ @@ -4139,8 +4268,9 @@ static TransData *ActionFCurveToTransData(TransData *td, TransData2D *td2d = *td2dv; int i; - if (ELEM(NULL, fcu, fcu->bezt)) + if (ELEM(NULL, fcu, fcu->bezt)) { return td; + } for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) { /* only add selected keyframes (for now, proportional edit is not enabled) */ @@ -4150,8 +4280,9 @@ static TransData *ActionFCurveToTransData(TransData *td, if (FrameOnMouseSide(side, bezt->vec[1][0], cfra)) { TimeToTransData(td, bezt->vec[1], adt, ypos); - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { td->flag |= TD_SELECTED; + } /*set flags to move handles as necessary*/ td->flag |= TD_MOVEHANDLE1 | TD_MOVEHANDLE2; @@ -4297,14 +4428,17 @@ static void createTransActionData(bContext *C, TransInfo *t) float ypos = 1.0f / ((ysize / xsize) * (xmask / ymask)) * BLI_rctf_cent_y(&t->ar->v2d.cur); /* determine what type of data we are operating on */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return; + } /* filter data */ - if (ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) + if (ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) { filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT); - else + } + else { filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/); + } ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); /* which side of the current frame should be allowed */ @@ -4327,19 +4461,25 @@ static void createTransActionData(bContext *C, TransInfo *t) /* convert current-frame to action-time (slightly less accurate, especially under * higher scaling ratios, but is faster than converting all points) */ - if (adt) + if (adt) { cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP); - else + } + else { cfra = (float)CFRA; + } - if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) + if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) { adt_count = count_fcurve_keys(ale->key_data, t->frame_side, cfra, is_prop_edit); - else if (ale->type == ANIMTYPE_GPLAYER) + } + else if (ale->type == ANIMTYPE_GPLAYER) { adt_count = count_gplayer_frames(ale->data, t->frame_side, cfra, is_prop_edit); - else if (ale->type == ANIMTYPE_MASKLAYER) + } + else if (ale->type == ANIMTYPE_MASKLAYER) { adt_count = count_masklayer_frames(ale->data, t->frame_side, cfra, is_prop_edit); - else + } + else { BLI_assert(0); + } if (adt_count > 0) { count += adt_count; @@ -4372,8 +4512,9 @@ static void createTransActionData(bContext *C, TransInfo *t) /* loop 2: build transdata array */ for (ale = anim_data.first; ale; ale = ale->next) { - if (is_prop_edit && !ale->tag) + if (is_prop_edit && !ale->tag) { continue; + } cfra = (float)CFRA; @@ -4417,14 +4558,17 @@ static void createTransActionData(bContext *C, TransInfo *t) AnimData *adt; /* F-Curve may not have any keyframes */ - if (!ale->tag) + if (!ale->tag) { continue; + } adt = ANIM_nla_mapping_get(&ac, ale); - if (adt) + if (adt) { cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP); - else + } + else { cfra = (float)CFRA; + } if (ale->type == ANIMTYPE_GPLAYER) { bGPDlayer *gpl = (bGPDlayer *)ale->data; @@ -4500,8 +4644,9 @@ static void createTransActionData(bContext *C, TransInfo *t) if (bezt_iter->f2 & SELECT) { if (FrameOnMouseSide(t->frame_side, (float)bezt_iter->vec[1][0], cfra)) { float val = fabs(bezt->vec[1][0] - bezt_iter->vec[1][0]); - if (val < min) + if (val < min) { min = val; + } } } } @@ -4601,13 +4746,16 @@ static void bezt_to_transdata(TransData *td, td->flag |= TD_SELECTED; td->dist = 0.0f; } - else + else { td->dist = FLT_MAX; + } - if (ishandle) + if (ishandle) { td->flag |= TD_NOTIMESNAP; - if (intvals) + } + if (intvals) { td->flag |= TD_INTVALUES; + } /* copy space-conversion matrices for dealing with non-uniform scales */ copy_m3_m3(td->mtx, mtx); @@ -4676,8 +4824,9 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) short anim_map_flag = ANIM_UNITCONV_ONLYSEL | ANIM_UNITCONV_SELVERTS; /* determine what type of data we are operating on */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return; + } anim_map_flag |= ANIM_get_normalization_flags(&ac); @@ -4699,7 +4848,8 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) t->frame_side = 'B'; } - /* loop 1: count how many BezTriples (specifically their verts) are selected (or should be edited) */ + /* Loop 1: count how many BezTriples (specifically their verts) + * are selected (or should be edited). */ for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(&ac, ale); FCurve *fcu = (FCurve *)ale->key_data; @@ -4708,18 +4858,22 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) bool selected = false; /* F-Curve may not have any keyframes */ - if (fcu->bezt == NULL) + if (fcu->bezt == NULL) { continue; + } /* convert current-frame to action-time (slightly less accurate, especially under * higher scaling ratios, but is faster than converting all points) */ - if (adt) + if (adt) { cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP); - else + } + else { cfra = (float)CFRA; + } - /* only include BezTriples whose 'keyframe' occurs on the same side of the current frame as mouse */ + /* Only include BezTriples whose 'keyframe' + * occurs on the same side of the current frame as mouse. */ for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) { if (FrameOnMouseSide(t->frame_side, bezt->vec[1][0], cfra)) { const bool sel2 = (bezt->f2 & SELECT) != 0; @@ -4728,8 +4882,9 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) if (is_prop_edit) { curvecount += 3; - if (sel2 || sel1 || sel3) + if (sel2 || sel1 || sel3) { selected = true; + } } else { if (!is_translation_mode || !(sel2)) { @@ -4771,7 +4926,8 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) tc->data_len = count; tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData (Graph Editor)"); - /* for each 2d vert a 3d vector is allocated, so that they can be treated just as if they were 3d verts */ + /* For each 2d vert a 3d vector is allocated, + * so that they can be treated just as if they were 3d verts. */ tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransData2D (Graph Editor)"); tc->custom.type.data = MEM_callocN(tc->data_len * sizeof(TransDataGraph), "TransDataGraph"); tc->custom.type.use_free = true; @@ -4795,10 +4951,12 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) mul_v3_fl(mtx[1], yscale); /* smtx is global (i.e. view) to data conversion */ - if (IS_EQF(xscale, 0.0f) == 0) + if (IS_EQF(xscale, 0.0f) == 0) { mul_v3_fl(smtx[0], 1.0f / xscale); - if (IS_EQF(yscale, 0.0f) == 0) + } + if (IS_EQF(yscale, 0.0f) == 0) { mul_v3_fl(smtx[1], 1.0f / yscale); + } } /* loop 2: build transdata arrays */ @@ -4810,16 +4968,19 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) float cfra; /* F-Curve may not have any keyframes */ - if (fcu->bezt == NULL || (is_prop_edit && ale->tag == 0)) + if (fcu->bezt == NULL || (is_prop_edit && ale->tag == 0)) { continue; + } /* convert current-frame to action-time (slightly less accurate, especially under * higher scaling ratios, but is faster than converting all points) */ - if (adt) + if (adt) { cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP); - else + } + else { cfra = (float)CFRA; + } unit_scale = ANIM_unit_mapping_get_factor( ac.scene, ale->id, ale->key_data, anim_map_flag, &offset); @@ -4907,8 +5068,9 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) } if (sel3) { - if (hdata == NULL) + if (hdata == NULL) { hdata = initTransDataCurveHandles(td, bezt); + } bezt_to_transdata(td++, td2d++, tdg++, @@ -4932,16 +5094,19 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) if (sel2 && !use_local_center) { /* move handles relative to center */ if (is_translation_mode) { - if (sel1) + if (sel1) { td->flag |= TD_MOVEHANDLE1; - if (sel3) + } + if (sel3) { td->flag |= TD_MOVEHANDLE2; + } } /* if handles were not selected, store their selection status */ if (!(sel1) || !(sel3)) { - if (hdata == NULL) + if (hdata == NULL) { hdata = initTransDataCurveHandles(td, bezt); + } } bezt_to_transdata(td++, @@ -4958,7 +5123,9 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) unit_scale, offset); } - /* special hack (must be done after initTransDataCurveHandles(), as that stores handle settings to restore...): + /* Special hack (must be done after #initTransDataCurveHandles(), + * as that stores handle settings to restore...): + * * - Check if we've got entire BezTriple selected and we're scaling/rotating that point, * then check if we're using auto-handles. * - If so, change them auto-handles to aligned handles so that handles get affected too @@ -4989,16 +5156,19 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) float cfra; /* F-Curve may not have any keyframes */ - if (fcu->bezt == NULL || (ale->tag == 0)) + if (fcu->bezt == NULL || (ale->tag == 0)) { continue; + } /* convert current-frame to action-time (slightly less accurate, especially under * higher scaling ratios, but is faster than converting all points) */ - if (adt) + if (adt) { cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP); - else + } + else { cfra = (float)CFRA; + } /* only include BezTriples whose 'keyframe' occurs on the * same side of the current frame as mouse (if applicable) */ @@ -5062,8 +5232,9 @@ static BeztMap *bezt_to_beztmaps(BezTriple *bezts, int totvert, const short UNUS int i; /* allocate memory for this array */ - if (totvert == 0 || bezts == NULL) + if (totvert == 0 || bezts == NULL) { return NULL; + } bezm = bezms = MEM_callocN(sizeof(BeztMap) * totvert, "BeztMaps"); /* assign beztriples to beztmaps */ @@ -5154,34 +5325,41 @@ static void beztmap_to_data( td = tc->data; for (j = 0; j < tc->data_len; j++, td2d++, td++) { /* skip item if already marked */ - if (adjusted[j] != 0) + if (adjusted[j] != 0) { continue; + } /* update all transdata pointers, no need to check for selections etc, * since only points that are really needed were created as transdata */ if (td2d->loc2d == bezm->bezt->vec[0]) { - if (bezm->swapHs == 1) + if (bezm->swapHs == 1) { td2d->loc2d = (bezts + bezm->newIndex)->vec[2]; - else + } + else { td2d->loc2d = (bezts + bezm->newIndex)->vec[0]; + } adjusted[j] = 1; } else if (td2d->loc2d == bezm->bezt->vec[2]) { - if (bezm->swapHs == 1) + if (bezm->swapHs == 1) { td2d->loc2d = (bezts + bezm->newIndex)->vec[0]; - else + } + else { td2d->loc2d = (bezts + bezm->newIndex)->vec[2]; + } adjusted[j] = 1; } else if (td2d->loc2d == bezm->bezt->vec[1]) { td2d->loc2d = (bezts + bezm->newIndex)->vec[1]; /* if only control point is selected, the handle pointers need to be updated as well */ - if (td2d->h1) + if (td2d->h1) { td2d->h1 = (bezts + bezm->newIndex)->vec[0]; - if (td2d->h2) + } + if (td2d->h2) { td2d->h2 = (bezts + bezm->newIndex)->vec[2]; + } adjusted[j] = 1; } @@ -5288,18 +5466,22 @@ void flushTransGraphData(TransInfo *t) } /* we need to unapply the nla-mapping from the time in some situations */ - if (adt) + if (adt) { td2d->loc2d[0] = BKE_nla_tweakedit_remap(adt, td2d->loc[0], NLATIME_CONVERT_UNMAP); - else + } + else { td2d->loc2d[0] = td2d->loc[0]; + } - /* Time-stepping auto-snapping modes don't get applied for Graph Editor transforms, + /** Time-stepping auto-snapping modes don't get applied for Graph Editor transforms, * as these use the generic transform modes which don't account for this sort of thing. * These ones aren't affected by NLA mapping, so we do this after the conversion... * - * NOTE: We also have to apply to td->loc, as that's what the handle-adjustment step below looks - * to, otherwise we get "swimming handles" - * NOTE: We don't do this when canceling transforms, or else these changes don't go away + * \note We also have to apply to td->loc, + * as that's what the handle-adjustment step below looks to, + * otherwise we get "swimming handles". + * + * \note We don't do this when canceling transforms, or else these changes don't go away. */ if ((t->state != TRANS_CANCEL) && (td->flag & TD_NOTIMESNAP) == 0 && ELEM(sipo->autosnap, SACTSNAP_STEP, SACTSNAP_TSTEP)) { @@ -5318,10 +5500,12 @@ void flushTransGraphData(TransInfo *t) } /* if int-values only, truncate to integers */ - if (td->flag & TD_INTVALUES) + if (td->flag & TD_INTVALUES) { td2d->loc2d[1] = floorf(td2d->loc[1] * inv_unit_scale - tdg->offset + 0.5f); - else + } + else { td2d->loc2d[1] = td2d->loc[1] * inv_unit_scale - tdg->offset; + } if ((td->flag & TD_MOVEHANDLE1) && td2d->h1) { td2d->h1[0] = td2d->ih1[0] + td->loc[0] - td->iloc[0]; @@ -5366,12 +5550,15 @@ static void SeqTransInfo(TransInfo *t, Sequence *seq, int *recursive, int *count /* for meta's we only ever need to extend their children, no matter what depth * just check the meta's are in the bounds */ - if (t->frame_side == 'R' && right <= cfra) + if (t->frame_side == 'R' && right <= cfra) { *recursive = false; - else if (t->frame_side == 'L' && left >= cfra) + } + else if (t->frame_side == 'L' && left >= cfra) { *recursive = false; - else + } + else { *recursive = true; + } *count = 1; *flag = (seq->flag | SELECT) & ~(SEQ_LEFTSEL | SEQ_RIGHTSEL); @@ -5388,8 +5575,9 @@ static void SeqTransInfo(TransInfo *t, Sequence *seq, int *recursive, int *count } /* ignore */ else if (left > cfra) { } /* keep the selection */ - else + else { *flag |= SEQ_RIGHTSEL; + } } else { if (left >= cfra) { @@ -5397,8 +5585,9 @@ static void SeqTransInfo(TransInfo *t, Sequence *seq, int *recursive, int *count } /* ignore */ else if (right < cfra) { } /* keep the selection */ - else + else { *flag |= SEQ_LEFTSEL; + } } } } @@ -5474,8 +5663,9 @@ static int SeqTransCount(TransInfo *t, Sequence *parent, ListBase *seqbase, int for (seq = seqbase->first; seq; seq = seq->next) { seq->depth = depth; - /* seq->tmp is used by seq_tx_get_final_{left, right} to check sequence's range and clamp to it if needed. - * it's first place where digging into sequences tree, so store link to parent here */ + /* 'seq->tmp' is used by seq_tx_get_final_{left, right} + * to check sequence's range and clamp to it if needed. + * It's first place where digging into sequences tree, so store link to parent here. */ seq->tmp = parent; SeqTransInfo(t, seq, &recursive, &count, &flag); /* ignore the flag */ @@ -5672,8 +5862,9 @@ static void freeSeqData(TransInfo *t, TransDataContainer *tc, TransCustomData *c if (overlap) { bool has_effect_root = false, has_effect_any = false; - for (seq = seqbasep->first; seq; seq = seq->next) + for (seq = seqbasep->first; seq; seq = seq->next) { seq->tmp = NULL; + } td = tc->data; for (a = 0, seq_prev = NULL; a < tc->data_len; a++, td++, seq_prev = seq) { @@ -5767,12 +5958,15 @@ static void freeSeqData(TransInfo *t, TransDataContainer *tc, TransCustomData *c for (seq = seqbasep->first; seq; seq = seq->next) { /* We might want to build a list of effects that need to be updated during transform */ if (seq->type & SEQ_TYPE_EFFECT) { - if (seq->seq1 && seq->seq1->flag & SELECT) + if (seq->seq1 && seq->seq1->flag & SELECT) { BKE_sequence_calc(t->scene, seq); - else if (seq->seq2 && seq->seq2->flag & SELECT) + } + else if (seq->seq2 && seq->seq2->flag & SELECT) { BKE_sequence_calc(t->scene, seq); - else if (seq->seq3 && seq->seq3->flag & SELECT) + } + else if (seq->seq3 && seq->seq3->flag & SELECT) { BKE_sequence_calc(t->scene, seq); + } } } @@ -5783,8 +5977,9 @@ static void freeSeqData(TransInfo *t, TransDataContainer *tc, TransCustomData *c for (a = 0; a < tc->data_len; a++, td++) { seq = ((TransDataSeq *)td->extra)->seq; if ((seq != seq_prev) && (seq->depth == 0)) { - if (seq->flag & SEQ_OVERLAP) + if (seq->flag & SEQ_OVERLAP) { BKE_sequence_base_shuffle(seqbasep, seq, t->scene); + } BKE_sequence_calc_disp(t->scene, seq); } @@ -5878,8 +6073,9 @@ static void createTransSeqData(bContext *C, TransInfo *t) SeqTransDataBounds(t, ed->seqbasep, ts); /* set the snap mode based on how close the mouse is at the end/start points */ - if (abs(xmouse - ts->max) > abs(xmouse - ts->min)) + if (abs(xmouse - ts->max) > abs(xmouse - ts->min)) { ts->snap_left = true; + } #undef XXX_DURIAN_ANIM_TX_HACK } @@ -5920,23 +6116,26 @@ static bool constraints_list_needinv(TransInfo *t, ListBase *list) bChildOfConstraint *data = (bChildOfConstraint *)con->data; if ((data->flag & CHILDOF_LOCX) && (data->flag & CHILDOF_LOCY) && - (data->flag & CHILDOF_LOCZ)) + (data->flag & CHILDOF_LOCZ)) { return true; + } } else if (con->type == CONSTRAINT_TYPE_ROTLIKE) { /* CopyRot constraint only does this when rotating, and offset is on */ bRotateLikeConstraint *data = (bRotateLikeConstraint *)con->data; - if ((data->flag & ROTLIKE_OFFSET) && (t->mode == TFM_ROTATION)) + if ((data->flag & ROTLIKE_OFFSET) && (t->mode == TFM_ROTATION)) { return true; + } } else if (con->type == CONSTRAINT_TYPE_TRANSFORM) { /* Transform constraint needs it for rotation at least (r.57309), * but doing so when translating may also mess things up [#36203] */ - if (t->mode == TFM_ROTATION) + if (t->mode == TFM_ROTATION) { return true; + } /* ??? (t->mode == TFM_SCALE) ? */ } } @@ -5996,8 +6195,9 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob) constinv = constraints_list_needinv(t, &ob->constraints); /* disable constraints inversion for dummy pass */ - if (t->mode == TFM_DUMMY) + if (t->mode == TFM_DUMMY) { skip_invert = true; + } /* NOTE: This is not really following copy-on-write design and we should not * be re-evaluating the evaluated object. But as the comment above mentioned @@ -6186,8 +6386,9 @@ static void set_trans_object_base_flags(TransInfo *t) static bool mark_children(Object *ob) { - if (ob->flag & (SELECT | BA_TRANSFORM_CHILD)) + if (ob->flag & (SELECT | BA_TRANSFORM_CHILD)) { return true; + } if (ob->parent) { if (mark_children(ob->parent)) { @@ -6213,7 +6414,7 @@ static int count_proportional_objects(TransInfo *t) (t->mode == TFM_ROTATION || t->mode == TFM_TRACKBALL))) { /* Mark all parents. */ for (Base *base = view_layer->object_bases.first; base; base = base->next) { - if (BASE_SELECTED_EDITABLE(v3d, base)) { + if (BASE_SELECTED_EDITABLE(v3d, base) && BASE_SELECTABLE(v3d, base)) { Object *parent = base->object->parent; /* flag all parents */ while (parent != NULL) { @@ -6226,7 +6427,8 @@ static int count_proportional_objects(TransInfo *t) for (Base *base = view_layer->object_bases.first; base; base = base->next) { /* all base not already selected or marked that is editable */ if ((base->object->flag & (BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT)) == 0 && - (base->flag & BASE_SELECTED) == 0 && (BASE_EDITABLE(v3d, base))) { + (base->flag & BASE_SELECTED) == 0 && + (BASE_EDITABLE(v3d, base) && BASE_SELECTABLE(v3d, base))) { mark_children(base->object); } } @@ -6235,10 +6437,11 @@ static int count_proportional_objects(TransInfo *t) for (Base *base = view_layer->object_bases.first; base; base = base->next) { Object *ob = base->object; /* If base is not selected, not a parent of selection or not a child of - * selection and it is editable. + * selection and it is editable and selectable. */ if ((ob->flag & (BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT)) == 0 && - (base->flag & BASE_SELECTED) == 0 && (BASE_EDITABLE(v3d, base))) { + (base->flag & BASE_SELECTED) == 0 && + (BASE_EDITABLE(v3d, base) && BASE_SELECTABLE(v3d, base))) { flush_trans_object_base_deps_flag(depsgraph, ob); total += 1; } @@ -6257,7 +6460,7 @@ static void clear_trans_object_base_flags(TransInfo *t) for (base = view_layer->object_bases.first; base; base = base->next) { if (base->flag_legacy & BA_WAS_SEL) { - base->flag |= BASE_SELECTED; + ED_object_base_select(base, BA_SELECT); } base->flag_legacy &= ~(BA_WAS_SEL | BA_SNAP_FIX_DEPS_FIASCO | BA_TEMP_TAG | @@ -6265,10 +6468,14 @@ static void clear_trans_object_base_flags(TransInfo *t) } } -/* auto-keyframing feature - for objects - * tmode: should be a transform mode +/** + * Auto-keyframing feature - for objects + * + * \param tmode: A transform mode. + * + * \note Context may not always be available, + * so must check before using it as it's a luxury for a few cases. */ -// NOTE: context may not always be available, so must check before using it as it's a luxury for a few cases void autokeyframe_object(bContext *C, Scene *scene, ViewLayer *view_layer, Object *ob, int tmode) { Main *bmain = CTX_data_main(C); @@ -6292,8 +6499,9 @@ void autokeyframe_object(bContext *C, Scene *scene, ViewLayer *view_layer, Objec ANIM_relative_keyingset_add_source(&dsources, id, NULL, NULL); if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (active_ks)) { - /* only insert into active keyingset - * NOTE: we assume here that the active Keying Set does not need to have its iterator overridden + /* Only insert into active keyingset + * NOTE: we assume here that the active Keying Set + * does not need to have its iterator overridden. */ ANIM_apply_keyingset(C, &dsources, NULL, active_ks, MODIFYKEY_MODE_INSERT, cfra); } @@ -6332,8 +6540,9 @@ void autokeyframe_object(bContext *C, Scene *scene, ViewLayer *view_layer, Objec } else if (ELEM(tmode, TFM_ROTATION, TFM_TRACKBALL)) { if (scene->toolsettings->transform_pivot_point == V3D_AROUND_ACTIVE) { - if (ob != OBACT(view_layer)) + if (ob != OBACT(view_layer)) { do_loc = true; + } } else if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CURSOR) { do_loc = true; @@ -6345,8 +6554,9 @@ void autokeyframe_object(bContext *C, Scene *scene, ViewLayer *view_layer, Objec } else if (tmode == TFM_RESIZE) { if (scene->toolsettings->transform_pivot_point == V3D_AROUND_ACTIVE) { - if (ob != OBACT(view_layer)) + if (ob != OBACT(view_layer)) { do_loc = true; + } } else if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CURSOR) { do_loc = true; @@ -6398,11 +6608,16 @@ bool motionpath_need_update_object(Scene *scene, Object *ob) return false; } -/* auto-keyframing feature - for poses/pose-channels - * tmode: should be a transform mode +/** + * Auto-keyframing feature - for poses/pose-channels + * + * \param tmode: A transform mode. + * * targetless_ik: has targetless ik been done on any channels? + * + * \note Context may not always be available, + * so must check before using it as it's a luxury for a few cases. */ -// NOTE: context may not always be available, so must check before using it as it's a luxury for a few cases void autokeyframe_pose(bContext *C, Scene *scene, Object *ob, int tmode, short targetless_ik) { Main *bmain = CTX_data_main(C); @@ -6430,8 +6645,9 @@ void autokeyframe_pose(bContext *C, Scene *scene, Object *ob, int tmode, short t */ flag = ANIM_get_keyframing_flags(scene, 1); - if (targetless_ik) + if (targetless_ik) { flag |= INSERTKEY_MATRIX; + } for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { if (pchan->bone->flag & BONE_TRANSFORM) { @@ -6474,8 +6690,9 @@ void autokeyframe_pose(bContext *C, Scene *scene, Object *ob, int tmode, short t flag); } - if (pchanName) + if (pchanName) { MEM_freeN(pchanName); + } } } } @@ -6484,12 +6701,15 @@ void autokeyframe_pose(bContext *C, Scene *scene, Object *ob, int tmode, short t else if (IS_AUTOKEY_FLAG(scene, INSERTNEEDED)) { bool do_loc = false, do_rot = false, do_scale = false; - /* filter the conditions when this happens (assume that curarea->spacetype==SPACE_VIE3D) */ + /* Filter the conditions when this happens + * (assume that 'curarea->spacetype == SPACE_VIEW3D'). */ if (tmode == TFM_TRANSLATION) { - if (targetless_ik) + if (targetless_ik) { do_rot = true; - else + } + else { do_loc = true; + } } else if (ELEM(tmode, TFM_ROTATION, TFM_TRACKBALL)) { if (ELEM(scene->toolsettings->transform_pivot_point, @@ -6620,7 +6840,7 @@ static void special_aftertrans_update__mask(bContext *C, TransInfo *t) if (t->scene->nodetree) { /* tracks can be used for stabilization nodes, * flush update for such nodes */ - //if (nodeUpdateID(t->scene->nodetree, &mask->id)) + // if (nodeUpdateID(t->scene->nodetree, &mask->id)) { WM_event_add_notifier(C, NC_MASK | ND_DATA, &mask->id); } @@ -6647,8 +6867,9 @@ static void special_aftertrans_update__node(bContext *C, TransInfo *t) bNode *node, *node_next; for (node = ntree->nodes.first; node; node = node_next) { node_next = node->next; - if (node->flag & NODE_SELECT) + if (node->flag & NODE_SELECT) { nodeRemoveNode(bmain, ntree, node, true); + } } } } @@ -6658,8 +6879,7 @@ static void special_aftertrans_update__mesh(bContext *UNUSED(C), TransInfo *t) { /* so automerge supports mirror */ if ((t->scene->toolsettings->automerge) && ((t->flag & T_EDIT) && t->obedit_type == OB_MESH)) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); BMesh *bm = em->bm; @@ -6698,10 +6918,11 @@ static void special_aftertrans_update__mesh(bContext *UNUSED(C), TransInfo *t) } /* inserting keys, pointcache, redraw events... */ -/* - * note: sequencer freeing has its own function now because of a conflict with transform's order of freeing (campbell) - * Order changed, the sequencer stuff should go back in here - * */ +/** + * \note Sequencer freeing has its own function now because of a conflict + * with transform's order of freeing (campbell). + * Order changed, the sequencer stuff should go back in here + */ void special_aftertrans_update(bContext *C, TransInfo *t) { Main *bmain = CTX_data_main(t->context); @@ -6730,8 +6951,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t) * really slow -joeedh */ projectEdgeSlideData(t, true); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { EdgeSlideData *sld = tc->custom.mode.data; /* Free temporary faces to avoid auto-merging and deleting @@ -6742,8 +6962,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t) else if (t->mode == TFM_VERT_SLIDE) { /* as above */ projectVertSlideData(t, true); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { VertSlideData *sld = tc->custom.mode.data; freeVertSlideTempFaces(sld); } @@ -6784,9 +7003,10 @@ void special_aftertrans_update(bContext *C, TransInfo *t) * for some reason EXTEND is changed into TRANSLATE, so use frame_side instead */ if (t->mode == TFM_SEQ_SLIDE) { - if (t->frame_side == 'B') + if (t->frame_side == 'B') { ED_markers_post_apply_transform( &t->scene->markers, t->scene, TFM_TIME_TRANSLATE, t->values[0], t->frame_side); + } } else if (ELEM(t->frame_side, 'L', 'R')) { ED_markers_post_apply_transform( @@ -6824,8 +7044,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t) bAnimContext ac; /* initialize relevant anim-context 'context' data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return; + } ob = ac.obact; @@ -6855,8 +7076,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t) posttrans_fcurve_clean(fcu, false); /* only use handles in graph editor */ ANIM_nla_mapping_apply_fcurve(adt, fcu, 1, 0); } - else + else { posttrans_fcurve_clean(fcu, false); /* only use handles in graph editor */ + } } } @@ -6867,11 +7089,13 @@ void special_aftertrans_update(bContext *C, TransInfo *t) /* Depending on the lock status, draw necessary views */ // fixme... some of this stuff is not good if (ob) { - if (ob->pose || BKE_key_from_object(ob)) + if (ob->pose || BKE_key_from_object(ob)) { DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION); - else + } + else { DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM); + } } /* 3 cases here for curve cleanups: @@ -6900,17 +7124,21 @@ void special_aftertrans_update(bContext *C, TransInfo *t) // XXX: BAD! this get gpencil datablocks directly from main db... // but that's how this currently works :/ for (gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) { - if (ID_REAL_USERS(gpd)) + if (ID_REAL_USERS(gpd)) { posttrans_gpd_clean(gpd); + } } } } else if (ac.datatype == ANIMCONT_MASK) { /* remove duplicate frames and also make sure points are in order! */ /* 3 cases here for curve cleanups: - * 1) NOTRANSKEYCULL on -> cleanup of duplicates shouldn't be done - * 2) canceled == 0 -> user confirmed the transform, so duplicates should be removed - * 3) canceled + duplicate -> user canceled the transform, but we made duplicates, so get rid of these + * 1) NOTRANSKEYCULL on: + * Cleanup of duplicates shouldn't be done. + * 2) canceled == 0: + * User confirmed the transform, so duplicates should be removed. + * 3) Canceled + duplicate: + * User canceled the transform, but we made duplicates, so get rid of these. */ if ((saction->flag & SACTION_NOTRANSKEYCULL) == 0 && ((canceled == 0) || (duplicate))) { Mask *mask; @@ -6918,8 +7146,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t) // XXX: BAD! this get gpencil datablocks directly from main db... // but that's how this currently works :/ for (mask = bmain->masks.first; mask; mask = mask->id.next) { - if (ID_REAL_USERS(mask)) + if (ID_REAL_USERS(mask)) { posttrans_mask_clean(mask); + } } } } @@ -6932,7 +7161,8 @@ void special_aftertrans_update(bContext *C, TransInfo *t) #if 0 if (ELEM(t->frame_side, 'L', 'R')) { /* TFM_TIME_EXTEND */ /* same as below */ - ED_markers_post_apply_transform(ED_context_get_markers(C), t->scene, t->mode, t->values[0], t->frame_side); + ED_markers_post_apply_transform( + ED_context_get_markers(C), t->scene, t->mode, t->values[0], t->frame_side); } else /* TFM_TIME_TRANSLATE */ #endif @@ -6948,8 +7178,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t) } /* make sure all F-Curves are set correctly */ - if (!ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) + if (!ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) { ANIM_editkeyframes_refresh(&ac); + } /* clear flag that was set for time-slide drawing */ saction->flag &= ~SACTION_MOVING; @@ -6960,8 +7191,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t) const bool use_handle = (sipo->flag & SIPO_NOHANDLES) == 0; /* initialize relevant anim-context 'context' data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return; + } if (ac.datatype) { ListBase anim_data = {NULL, NULL}; @@ -6988,8 +7220,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t) posttrans_fcurve_clean(fcu, use_handle); ANIM_nla_mapping_apply_fcurve(adt, fcu, 1, 0); } - else + else { posttrans_fcurve_clean(fcu, use_handle); + } } } @@ -7002,15 +7235,17 @@ void special_aftertrans_update(bContext *C, TransInfo *t) * Note: if the refresh is really needed after cancel then some way * has to be added to not update handle types (see bug 22289). */ - if (!canceled) + if (!canceled) { ANIM_editkeyframes_refresh(&ac); + } } else if (t->spacetype == SPACE_NLA) { bAnimContext ac; /* initialize relevant anim-context 'context' data */ - if (ANIM_animdata_get_context(C, &ac) == 0) + if (ANIM_animdata_get_context(C, &ac) == 0) { return; + } if (ac.datatype) { ListBase anim_data = {NULL, NULL}; @@ -7039,8 +7274,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t) } else if (t->flag & T_EDIT) { if (t->obedit_type == OB_MESH) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); /* table needs to be created for each edit command, since vertices can move etc */ ED_mesh_mirror_spatial_table(tc->obedit, em, NULL, NULL, 'e'); @@ -7053,8 +7287,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t) /* Handle the exception where for TFM_BONESIZE in edit mode we pretend to be * in pose mode (to use bone orientation matrix), * in that case we don't do operations like autokeyframing. */ - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { ob = tc->poseobj; DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); } @@ -7062,8 +7295,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t) else if (t->flag & T_POSE) { GSet *motionpath_updates = BLI_gset_ptr_new("motionpath updates"); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { bArmature *arm; bPoseChannel *pchan; @@ -7086,19 +7318,22 @@ void special_aftertrans_update(bContext *C, TransInfo *t) } /* if target-less IK grabbing, we calculate the pchan transforms and clear flag */ - if (!canceled && t->mode == TFM_TRANSLATION) + if (!canceled && t->mode == TFM_TRANSLATION) { targetless_ik = apply_targetless_ik(ob); + } else { /* not forget to clear the auto flag */ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { bKinematicConstraint *data = has_targetless_ik(pchan); - if (data) + if (data) { data->flag &= ~CONSTRAINT_IK_AUTO; + } } } - if (t->mode == TFM_TRANSLATION) + if (t->mode == TFM_TRANSLATION) { pose_grab_with_ik_clear(bmain, ob); + } /* automatic inserting of keys and unkeyed tagging - * only if transform wasn't canceled (or TFM_DUMMY) */ @@ -7154,11 +7389,13 @@ void special_aftertrans_update(bContext *C, TransInfo *t) PTCacheID *pid; ob = td->ob; - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } /* flag object caches as outdated */ BKE_ptcache_ids_from_object(&pidlist, ob, t->scene, MAX_DUPLI_RECUR); @@ -7171,8 +7408,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t) BLI_freelistN(&pidlist); /* pointcache refresh */ - if (BKE_ptcache_object_reset(t->scene, ob, PTCACHE_RESET_OUTDATED)) + if (BKE_ptcache_object_reset(t->scene, ob, PTCACHE_RESET_OUTDATED)) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + } /* Needed for proper updating of "quick cached" dynamics. */ /* Creates troubles for moving animated objects without */ @@ -7190,13 +7428,14 @@ void special_aftertrans_update(bContext *C, TransInfo *t) /* restore rigid body transform */ if (ob->rigidbody_object && canceled) { float ctime = BKE_scene_frame_get(t->scene); - if (BKE_rigidbody_check_sim_running(t->scene->rigidbody_world, ctime)) + if (BKE_rigidbody_check_sim_running(t->scene->rigidbody_world, ctime)) { BKE_rigidbody_aftertrans_update(ob, td->ext->oloc, td->ext->orot, td->ext->oquat, td->ext->orotAxis, td->ext->orotAngle); + } } } @@ -7288,9 +7527,10 @@ static void createTransObject(bContext *C, TransInfo *t) Object *ob = base->object; /* if base is not selected, not a parent of selection - * or not a child of selection and it is editable */ + * or not a child of selection and it is editable and selectable */ if ((ob->flag & (BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT)) == 0 && - (base->flag & BASE_SELECTED) == 0 && BASE_EDITABLE(v3d, base)) { + (base->flag & BASE_SELECTED) == 0 && BASE_EDITABLE(v3d, base) && + BASE_SELECTABLE(v3d, base)) { td->protectflag = ob->protectflag; td->ext = tx; td->ext->rotOrder = ob->rotmode; @@ -7481,14 +7721,15 @@ static void markerToTransDataInit(TransData *td, copy_v2_v2(tdt->srelative, rel); } - if (off) + if (off) { copy_v2_v2(tdt->soffset, off); + } td->flag = 0; td->loc = td2d->loc; copy_v3_v3(td->iloc, td->loc); - //copy_v3_v3(td->center, td->loc); + // copy_v3_v3(td->center, td->loc); td->flag |= TD_INDIVIDUAL_SCALE; td->center[0] = marker->pos[0] * aspect[0]; td->center[1] = marker->pos[1] * aspect[1]; @@ -7634,8 +7875,9 @@ static void transDataTrackingFree(TransInfo *UNUSED(t), { if (custom_data->data) { TransDataTracking *tdt = custom_data->data; - if (tdt->smarkers) + if (tdt->smarkers) { MEM_freeN(tdt->smarkers); + } MEM_freeN(tdt); custom_data->data = NULL; @@ -7665,14 +7907,17 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t) if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED) == 0) { tc->data_len++; /* offset */ - if (track->flag & SELECT) + if (track->flag & SELECT) { tc->data_len++; + } - if (track->pat_flag & SELECT) + if (track->pat_flag & SELECT) { tc->data_len += 4; + } - if (track->search_flag & SELECT) + if (track->search_flag & SELECT) { tc->data_len += 2; + } } track = track->next; @@ -7684,8 +7929,9 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t) } } - if (tc->data_len == 0) + if (tc->data_len == 0) { return; + } td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransTracking TransData"); td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), @@ -7813,22 +8059,26 @@ static void createTransTrackingCurvesData(bContext *C, TransInfo *t) marker = &track->markers[i]; prev_marker = &track->markers[i - 1]; - if ((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED)) + if ((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED)) { continue; + } - if (marker->flag & MARKER_GRAPH_SEL_X) + if (marker->flag & MARKER_GRAPH_SEL_X) { tc->data_len += 1; + } - if (marker->flag & MARKER_GRAPH_SEL_Y) + if (marker->flag & MARKER_GRAPH_SEL_Y) { tc->data_len += 1; + } } } track = track->next; } - if (tc->data_len == 0) + if (tc->data_len == 0) { return; + } td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransTracking TransData"); td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), @@ -7845,8 +8095,9 @@ static void createTransTrackingCurvesData(bContext *C, TransInfo *t) marker = &track->markers[i]; prev_marker = &track->markers[i - 1]; - if ((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED)) + if ((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED)) { continue; + } if (marker->flag & MARKER_GRAPH_SEL_X) { markerToTransCurveDataInit( @@ -7882,13 +8133,15 @@ static void createTransTrackingData(bContext *C, TransInfo *t) tc->data_len = 0; - if (!clip) + if (!clip) { return; + } BKE_movieclip_get_size(clip, &sc->user, &width, &height); - if (width == 0 || height == 0) + if (width == 0 || height == 0) { return; + } if (ar->regiontype == RGN_TYPE_PREVIEW) { /* transformation was called from graph editor */ @@ -7916,14 +8169,17 @@ static void cancelTransTracking(TransInfo *t) marker->flag = tdt->flag; - if (track->flag & SELECT) + if (track->flag & SELECT) { i++; + } - if (track->pat_flag & SELECT) + if (track->pat_flag & SELECT) { i += 4; + } - if (track->search_flag & SELECT) + if (track->search_flag & SELECT) { i += 2; + } } else if (tdt->mode == transDataTracking_ModeCurves) { MovieTrackingTrack *track = tdt->track; @@ -7934,8 +8190,9 @@ static void cancelTransTracking(TransInfo *t) marker = &track->markers[a]; prev_marker = &track->markers[a - 1]; - if ((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED)) + if ((marker->flag & MARKER_DISABLED) || (prev_marker->flag & MARKER_DISABLED)) { continue; + } if (marker->flag & (MARKER_GRAPH_SEL_X | MARKER_GRAPH_SEL_Y)) { marker->flag = tdt->flag; @@ -7961,8 +8218,9 @@ void flushTransTracking(TransInfo *t) TransDataTracking *tdt; int a; - if (t->state == TRANS_CANCEL) + if (t->state == TRANS_CANCEL) { cancelTransTracking(t); + } TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); @@ -7981,8 +8239,9 @@ void flushTransTracking(TransInfo *t) if (t->flag & T_ALT_TRANSFORM) { if (t->mode == TFM_RESIZE) { - if (tdt->area != TRACK_AREA_PAT) + if (tdt->area != TRACK_AREA_PAT) { continue; + } } else if (t->mode == TFM_TRANSLATION) { if (tdt->area == TRACK_AREA_POINT && tdt->relative) { @@ -7991,8 +8250,9 @@ void flushTransTracking(TransInfo *t) if (!tdt->smarkers) { tdt->smarkers = MEM_callocN(sizeof(*tdt->smarkers) * tdt->markersnr, "flushTransTracking markers"); - for (a = 0; a < tdt->markersnr; a++) + for (a = 0; a < tdt->markersnr; a++) { copy_v2_v2(tdt->smarkers[a], tdt->markers[a].pos); + } } sub_v2_v2v2(d, loc2d, tdt->soffset); @@ -8000,8 +8260,9 @@ void flushTransTracking(TransInfo *t) sub_v2_v2v2(d2, loc2d, tdt->srelative); - for (a = 0; a < tdt->markersnr; a++) + for (a = 0; a < tdt->markersnr; a++) { add_v2_v2v2(tdt->markers[a].pos, tdt->smarkers[a], d2); + } negate_v2_v2(td2d->loc2d, d); } @@ -8012,8 +8273,9 @@ void flushTransTracking(TransInfo *t) td2d->loc2d[0] = loc2d[0]; td2d->loc2d[1] = loc2d[1]; - if (tdt->relative) + if (tdt->relative) { sub_v2_v2(td2d->loc2d, tdt->relative); + } } } else if (tdt->mode == transDataTracking_ModeCurves) { @@ -8260,8 +8522,9 @@ static void createTransMaskingData(bContext *C, TransInfo *t) tc->data_len = 0; - if (!mask) + if (!mask) { return; + } if (t->spacetype == SPACE_CLIP) { SpaceClip *sc = t->sa->spacedata.first; @@ -8305,8 +8568,9 @@ static void createTransMaskingData(bContext *C, TransInfo *t) } } - if (is_prop_edit) + if (is_prop_edit) { count += 3; + } } } } @@ -8518,8 +8782,9 @@ static void createTransPaintCurveVerts(bContext *C, TransInfo *t) tc->data_len = 0; - if (!paint || !paint->brush || !paint->brush->paint_curve) + if (!paint || !paint->brush || !paint->brush->paint_curve) { return; + } br = paint->brush; pc = br->paint_curve; @@ -8531,16 +8796,19 @@ static void createTransPaintCurveVerts(bContext *C, TransInfo *t) continue; } else { - if (pcp->bez.f1 & SELECT) + if (pcp->bez.f1 & SELECT) { total++; - if (pcp->bez.f3 & SELECT) + } + if (pcp->bez.f3 & SELECT) { total++; + } } } } - if (!total) + if (!total) { return; + } tc->data_len = total; td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransData2D"); @@ -8638,8 +8906,9 @@ static void createTransGPencil(bContext *C, TransInfo *t) */ tc->data_len = 0; - if (gpd == NULL) + if (gpd == NULL) { return; + } /* initialize falloff curve */ if (is_multiedit) { @@ -8675,8 +8944,9 @@ static void createTransGPencil(bContext *C, TransInfo *t) /* Proportional Editing... */ if (is_prop_edit_connected) { /* connected only - so only if selected */ - if (gps->flag & GP_STROKE_SELECT) + if (gps->flag & GP_STROKE_SELECT) { tc->data_len += gps->totpoints; + } } else { /* everything goes - connection status doesn't matter */ @@ -8691,8 +8961,9 @@ static void createTransGPencil(bContext *C, TransInfo *t) // TODO: 2D vs 3D? for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { - if (pt->flag & GP_SPOINT_SELECT) + if (pt->flag & GP_SPOINT_SELECT) { tc->data_len++; + } } } } @@ -8745,7 +9016,9 @@ static void createTransGPencil(bContext *C, TransInfo *t) /* undo matrix */ invert_m4_m4(inverse_diff_mat, diff_mat); - /* Make a new frame to work on if the layer's frame and the current scene frame don't match up + /* Make a new frame to work on if the layer's frame + * and the current scene frame don't match up. + * * - This is useful when animating as it saves that "uh-oh" moment when you realize you've * spent too much time editing the wrong frame... */ @@ -8971,8 +9244,7 @@ void createTransData(bContext *C, TransInfo *t) else if (t->options & CTX_EDGE) { /* Multi object editing. */ initTransDataContainers_FromObjectData(t, ob, NULL, 0); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { tc->data_ext = NULL; } t->flag |= T_EDIT; @@ -9051,7 +9323,7 @@ void createTransData(bContext *C, TransInfo *t) if (t->data_len_all && (t->flag & T_PROP_EDIT)) { sort_trans_data(t); // makes selected become first in array /* don't do that, distance has been set in createTransActionData already */ - //set_prop_dist(t, false); + // set_prop_dist(t, false); sort_trans_data_dist(t); } } @@ -9127,8 +9399,7 @@ void createTransData(bContext *C, TransInfo *t) /* Multi object editing. */ initTransDataContainers_FromObjectData(t, ob, NULL, 0); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { tc->data_ext = NULL; } if (t->obedit_type == OB_MESH) { @@ -9179,16 +9450,17 @@ void createTransData(bContext *C, TransInfo *t) t->flag |= T_POSE; t->obedit_type = -1; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { tc->poseobj = tc->obedit; tc->obedit = NULL; } } } else if (ob && (ob->mode & OB_MODE_POSE)) { - // XXX this is currently limited to active armature only... - // XXX active-layer checking isn't done as that should probably be checked through context instead + /* XXX this is currently limited to active armature only... */ + + /* XXX active-layer checking isn't done + * as that should probably be checked through context instead. */ /* Multi object editing. */ initTransDataContainers_FromObjectData(t, ob, NULL, 0); diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 46e8447efc6..8ddc5461e9a 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -126,8 +126,7 @@ void getViewVector(const TransInfo *t, const float coord[3], float vec[3]) static void clipMirrorModifier(TransInfo *t) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { Object *ob = tc->obedit; ModifierData *md = ob->modifiers.first; float tolerance[3] = {0.0f, 0.0f, 0.0f}; @@ -168,13 +167,16 @@ static void clipMirrorModifier(TransInfo *t) int clip; float loc[3], iloc[3]; - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; - if (td->loc == NULL) + } + if (td->loc == NULL) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } copy_v3_v3(loc, td->loc); copy_v3_v3(iloc, td->iloc); @@ -221,20 +223,22 @@ static void clipMirrorModifier(TransInfo *t) /* assumes obedit set to mesh object */ static void editbmesh_apply_to_mirror(TransInfo *t) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { if (tc->mirror.axis_flag) { TransData *td = tc->data; BMVert *eve; int i; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; - if (td->loc == NULL) + } + if (td->loc == NULL) { break; - if (td->flag & TD_SKIP) + } + if (td->flag & TD_SKIP) { continue; + } eve = td->extra; if (eve) { @@ -257,8 +261,9 @@ static void animrecord_check_state(Scene *scene, ID *id, wmTimer *animtimer) ScreenAnimData *sad = (animtimer) ? animtimer->customdata : NULL; /* sanity checks */ - if (ELEM(NULL, scene, id, sad)) + if (ELEM(NULL, scene, id, sad)) { return; + } /* check if we need a new strip if: * - if animtimer is running @@ -331,12 +336,14 @@ static bool fcu_test_selected(FCurve *fcu) BezTriple *bezt = fcu->bezt; unsigned int i; - if (bezt == NULL) /* ignore baked */ + if (bezt == NULL) { /* ignore baked */ return 0; + } for (i = 0; i < fcu->totvert; i++, bezt++) { - if (BEZT_ISSEL_ANY(bezt)) + if (BEZT_ISSEL_ANY(bezt)) { return 1; + } } return 0; @@ -374,7 +381,8 @@ static void recalcData_actedit(TransInfo *t) } if (ac.datatype != ANIMCONT_MASK) { - /* get animdata blocks visible in editor, assuming that these will be the ones where things changed */ + /* Get animdata blocks visible in editor, + * assuming that these will be the ones where things changed. */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ANIMDATA); ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype); @@ -431,25 +439,30 @@ static void recalcData_graphedit(TransInfo *t) FCurve *fcu = (FCurve *)ale->key_data; /* ignore FC-Curves without any selected verts */ - if (!fcu_test_selected(fcu)) + if (!fcu_test_selected(fcu)) { continue; + } /* watch it: if the time is wrong: do not correct handles yet */ - if (test_time_fcurve(fcu)) + if (test_time_fcurve(fcu)) { dosort++; - else + } + else { calchandles_fcurve(fcu); + } /* set refresh tags for objects using this animation, * BUT only if realtime updates are enabled */ - if ((sipo->flag & SIPO_NOREALTIMEUPDATES) == 0) + if ((sipo->flag & SIPO_NOREALTIMEUPDATES) == 0) { ANIM_list_elem_update(CTX_data_main(t->context), t->scene, ale); + } } /* do resort and other updates? */ - if (dosort) + if (dosort) { remake_graph_transdata(t, &anim_data); + } /* now free temp channels */ ANIM_animdata_freelist(&anim_data); @@ -466,9 +479,9 @@ static void recalcData_nla(TransInfo *t) TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); TransDataNla *tdn = tc->custom.type.data; - /* for each strip we've got, perform some additional validation of the values that got set before - * using RNA to set the value (which does some special operations when setting these values to make - * sure that everything works ok) + /* For each strip we've got, perform some additional validation of the values + * that got set before using RNA to set the value (which does some special + * operations when setting these values to make sure that everything works ok). */ for (i = 0; i < tc->data_len; i++, tdn++) { NlaStrip *strip = tdn->strip; @@ -477,14 +490,16 @@ static void recalcData_nla(TransInfo *t) int delta_y1, delta_y2; /* if this tdn has no handles, that means it is just a dummy that should be skipped */ - if (tdn->handle == 0) + if (tdn->handle == 0) { continue; + } /* set refresh tags for objects using this animation, * BUT only if realtime updates are enabled */ - if ((snla->flag & SNLA_NOREALTIMEUPDATES) == 0) + if ((snla->flag & SNLA_NOREALTIMEUPDATES) == 0) { ANIM_id_update(CTX_data_main(t->context), tdn->id); + } /* if canceling transform, just write the values without validating, then move on */ if (t->state == TRANS_CANCEL) { @@ -495,21 +510,24 @@ static void recalcData_nla(TransInfo *t) /* start */ strip->start = tdn->h1[0]; - if ((strip->prev) && (strip->prev->type == NLASTRIP_TYPE_TRANSITION)) + if ((strip->prev) && (strip->prev->type == NLASTRIP_TYPE_TRANSITION)) { strip->prev->end = tdn->h1[0]; + } /* end */ strip->end = tdn->h2[0]; - if ((strip->next) && (strip->next->type == NLASTRIP_TYPE_TRANSITION)) + if ((strip->next) && (strip->next->type == NLASTRIP_TYPE_TRANSITION)) { strip->next->start = tdn->h2[0]; + } /* flush transforms to child strips (since this should be a meta) */ BKE_nlameta_flush_transforms(strip); /* restore to original track (if needed) */ if (tdn->oldTrack != tdn->nlt) { - /* just append to end of list for now, since strips get sorted in special_aftertrans_update() */ + /* Just append to end of list for now, + * since strips get sorted in special_aftertrans_update(). */ BLI_remlink(&tdn->nlt->strips, strip); BLI_addtail(&tdn->oldTrack->strips, strip); } @@ -530,8 +548,9 @@ static void recalcData_nla(TransInfo *t) if ((pExceeded && nExceeded) || (iter == 4)) { /* both endpoints exceeded (or iteration ping-pong'd meaning that we need a compromise) - * - simply crop strip to fit within the bounds of the strips bounding it - * - if there were no neighbors, clear the transforms (make it default to the strip's current values) + * - Simply crop strip to fit within the bounds of the strips bounding it + * - If there were no neighbors, clear the transforms + * (make it default to the strip's current values). */ if (strip->prev && strip->next) { tdn->h1[0] = strip->prev->end; @@ -556,8 +575,9 @@ static void recalcData_nla(TransInfo *t) tdn->h1[0] += offset; tdn->h2[0] += offset; } - else /* all is fine and well */ + else { /* all is fine and well */ break; + } } /* handle auto-snapping @@ -567,7 +587,7 @@ static void recalcData_nla(TransInfo *t) switch (snla->autosnap) { case SACTSNAP_FRAME: /* snap to nearest frame */ case SACTSNAP_STEP: /* frame step - this is basically the same, - * since we don't have any remapping going on */ + * since we don't have any remapping going on */ { tdn->h1[0] = floorf(tdn->h1[0] + 0.5f); tdn->h2[0] = floorf(tdn->h2[0] + 0.5f); @@ -576,7 +596,7 @@ static void recalcData_nla(TransInfo *t) case SACTSNAP_SECOND: /* snap to nearest second */ case SACTSNAP_TSTEP: /* second step - this is basically the same, - * since we don't have any remapping going on */ + * since we don't have any remapping going on */ { /* This case behaves differently from the rest, since lengths of strips * may not be multiples of a second. If we just naively resize adjust @@ -621,8 +641,9 @@ static void recalcData_nla(TransInfo *t) /* flush transforms to child strips (since this should be a meta) */ BKE_nlameta_flush_transforms(strip); - /* now, check if we need to try and move track - * - we need to calculate both, as only one may have been altered by transform if only 1 handle moved + /* Now, check if we need to try and move track: + * - we need to calculate both, + * as only one may have been altered by transform if only 1 handle moved. */ delta_y1 = ((int)tdn->h1[1] / NLACHANNEL_STEP(snla) - tdn->trackIndex); delta_y2 = ((int)tdn->h2[1] / NLACHANNEL_STEP(snla) - tdn->trackIndex); @@ -632,8 +653,9 @@ static void recalcData_nla(TransInfo *t) int delta = (delta_y2) ? delta_y2 : delta_y1; int n; - /* move in the requested direction, checking at each layer if there's space for strip to pass through, - * stopping on the last track available or that we're able to fit in + /* Move in the requested direction, + * checking at each layer if there's space for strip to pass through, + * stopping on the last track available or that we're able to fit in. */ if (delta > 0) { for (track = tdn->nlt->next, n = 0; (track) && (n < delta); track = track->next, n++) { @@ -646,8 +668,9 @@ static void recalcData_nla(TransInfo *t) tdn->nlt = track; tdn->trackIndex++; } - else /* can't move any further */ + else { /* can't move any further */ break; + } } } else { @@ -664,8 +687,9 @@ static void recalcData_nla(TransInfo *t) tdn->nlt = track; tdn->trackIndex--; } - else /* can't move any further */ + else { /* can't move any further */ break; + } } } } @@ -694,11 +718,11 @@ static void recalcData_image(TransInfo *t) SpaceImage *sima = t->sa->spacedata.first; flushTransUVs(t); - if (sima->flag & SI_LIVE_UNWRAP) + if (sima->flag & SI_LIVE_UNWRAP) { ED_uvedit_live_unwrap_re_solve(); + } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { if (tc->data_len) { DEG_id_tag_update(tc->obedit->data, 0); } @@ -725,20 +749,25 @@ static void recalcData_spaceclip(TransInfo *t) MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr); if (t->mode == TFM_TRANSLATION) { - if (TRACK_AREA_SELECTED(track, TRACK_AREA_PAT)) + if (TRACK_AREA_SELECTED(track, TRACK_AREA_PAT)) { BKE_tracking_marker_clamp(marker, CLAMP_PAT_POS); - if (TRACK_AREA_SELECTED(track, TRACK_AREA_SEARCH)) + } + if (TRACK_AREA_SELECTED(track, TRACK_AREA_SEARCH)) { BKE_tracking_marker_clamp(marker, CLAMP_SEARCH_POS); + } } else if (t->mode == TFM_RESIZE) { - if (TRACK_AREA_SELECTED(track, TRACK_AREA_PAT)) + if (TRACK_AREA_SELECTED(track, TRACK_AREA_PAT)) { BKE_tracking_marker_clamp(marker, CLAMP_PAT_DIM); - if (TRACK_AREA_SELECTED(track, TRACK_AREA_SEARCH)) + } + if (TRACK_AREA_SELECTED(track, TRACK_AREA_SEARCH)) { BKE_tracking_marker_clamp(marker, CLAMP_SEARCH_DIM); + } } else if (t->mode == TFM_ROTATION) { - if (TRACK_AREA_SELECTED(track, TRACK_AREA_PAT)) + if (TRACK_AREA_SELECTED(track, TRACK_AREA_PAT)) { BKE_tracking_marker_clamp(marker, CLAMP_PAT_POS); + } } } @@ -765,8 +794,7 @@ static void recalcData_objects(TransInfo *t) applyProject(t); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { Curve *cu = tc->obedit->data; ListBase *nurbs = BKE_curve_editNurbs_get(cu); Nurb *nu = nurbs->first; @@ -796,8 +824,7 @@ static void recalcData_objects(TransInfo *t) applyProject(t); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { Lattice *la = tc->obedit->data; DEG_id_tag_update(tc->obedit->data, 0); /* sets recalc flags */ if (la->editlatt->latt->flag & LT_OUTSIDE) { @@ -823,8 +850,7 @@ static void recalcData_objects(TransInfo *t) projectVertSlideData(t, false); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { DEG_id_tag_update(tc->obedit->data, 0); /* sets recalc flags */ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); EDBM_mesh_normals_update(em); @@ -837,8 +863,7 @@ static void recalcData_objects(TransInfo *t) applyProject(t); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { bArmature *arm = tc->obedit->data; ListBase *edbo = arm->edbo; EditBone *ebo, *ebo_parent; @@ -853,14 +878,16 @@ static void recalcData_objects(TransInfo *t) /* If this bone has a parent tip that has been moved */ if (ebo_parent->flag & BONE_TIPSEL) { copy_v3_v3(ebo->head, ebo_parent->tail); - if (t->mode == TFM_BONE_ENVELOPE) + if (t->mode == TFM_BONE_ENVELOPE) { ebo->rad_head = ebo_parent->rad_tail; + } } /* If this bone has a parent tip that has NOT been moved */ else { copy_v3_v3(ebo_parent->tail, ebo->head); - if (t->mode == TFM_BONE_ENVELOPE) + if (t->mode == TFM_BONE_ENVELOPE) { ebo_parent->rad_tail = ebo->rad_head; + } } } @@ -871,8 +898,9 @@ static void recalcData_objects(TransInfo *t) ebo->rad_tail = 0.10f * ebo->length; ebo->dist = 0.25f * ebo->length; if (ebo->parent) { - if (ebo->rad_head > ebo->parent->rad_tail) + if (ebo->rad_head > ebo->parent->rad_tail) { ebo->rad_head = ebo->parent->rad_tail; + } } } else if (t->mode != TFM_BONE_ENVELOPE) { @@ -933,19 +961,34 @@ static void recalcData_objects(TransInfo *t) if (t->state != TRANS_CANCEL) { applyProject(t); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { if (tc->data_len) { DEG_id_tag_update(tc->obedit->data, 0); /* sets recalc flags */ } } } } + else if (t->flag & T_POSE && (t->mode == TFM_BONESIZE)) { + /* Handle the exception where for TFM_BONESIZE in edit mode we pretend to be + * in pose mode (to use bone orientation matrix), + * in that case we have to do mirroring as well. */ + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + Object *ob = tc->poseobj; + bArmature *arm = ob->data; + if (arm->flag & ARM_MIRROR_EDIT) { + if (t->state != TRANS_CANCEL) { + ED_armature_edit_transform_mirror_update(ob); + } + else { + restoreBones(tc); + } + } + } + } else if (t->flag & T_POSE) { GSet *motionpath_updates = BLI_gset_ptr_new("motionpath updates"); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { Object *ob = tc->poseobj; bArmature *arm = ob->data; @@ -955,7 +998,9 @@ static void recalcData_objects(TransInfo *t) * * context is needed for keying set poll() functions. */ - // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes? + + /* TODO: autokeyframe calls need some setting to specify to add samples + * (FPoints) instead of keyframes? */ if ((t->animtimer) && (t->context) && IS_AUTOKEY_ON(t->scene)) { int targetless_ik = (t->flag & T_AUTOIK); // XXX this currently doesn't work, since flags aren't set yet! @@ -1001,24 +1046,26 @@ static void recalcData_objects(TransInfo *t) applyProject(t); } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (int i = 0; i < tc->data_len; i++, td++) { Object *ob = td->ob; - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } /* if animtimer is running, and the object already has animation data, * check if the auto-record feature means that we should record 'samples' * (i.e. uneditable animation values) */ - // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes? + /* TODO: autokeyframe calls need some setting to specify to add samples + * (FPoints) instead of keyframes? */ if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) { animrecord_check_state(t->scene, &ob->id, t->animtimer); autokeyframe_object(t->context, t->scene, t->view_layer, ob, t->mode); @@ -1031,8 +1078,9 @@ static void recalcData_objects(TransInfo *t) */ DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM); - if (t->flag & T_TEXTURE) + if (t->flag & T_TEXTURE) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + } } } @@ -1063,19 +1111,16 @@ static void recalcData_sequencer(TransInfo *t) if (seq != seq_prev) { if (BKE_sequence_tx_fullupdate_test(seq)) { - /* A few effect strip types need a complete recache on transform. */ BKE_sequence_invalidate_cache(t->scene, seq); } else { - BKE_sequence_invalidate_dependent(t->scene, seq); + BKE_sequence_invalidate_cache(t->scene, seq); } } seq_prev = seq; } - BKE_sequencer_preprocessed_cache_cleanup(); - flushTransSeq(t); } @@ -1194,16 +1239,17 @@ void resetTransRestrictions(TransInfo *t) static int initTransInfo_edit_pet_to_flag(const int proportional) { - switch (proportional) { - case PROP_EDIT_ON: - return T_PROP_EDIT; - case PROP_EDIT_CONNECTED: - return T_PROP_EDIT | T_PROP_CONNECTED; - case PROP_EDIT_PROJECTED: - return T_PROP_EDIT | T_PROP_PROJECTED; - default: - return 0; + int flag = 0; + if (proportional & PROP_EDIT_USE) { + flag |= T_PROP_EDIT; + } + if (proportional & PROP_EDIT_CONNECTED) { + flag |= T_PROP_CONNECTED; + } + if (proportional & PROP_EDIT_PROJECTED) { + flag |= T_PROP_PROJECTED; } + return flag; } void initTransDataContainers_FromObjectData(TransInfo *t, @@ -1515,10 +1561,12 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve t->view = &ar->v2d; t->around = sclip->around; - if (ED_space_clip_check_show_trackedit(sclip)) + if (ED_space_clip_check_show_trackedit(sclip)) { t->options |= CTX_MOVIECLIP; - else if (ED_space_clip_check_show_maskedit(sclip)) + } + else if (ED_space_clip_check_show_maskedit(sclip)) { t->options |= CTX_MASK; + } } else { if (ar) { @@ -1604,9 +1652,19 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve } /* setting PET flag only if property exist in operator. Otherwise, assume it's not supported */ - if (op && (prop = RNA_struct_find_property(op->ptr, "proportional"))) { + if (op && (prop = RNA_struct_find_property(op->ptr, "use_proportional_edit"))) { if (RNA_property_is_set(op->ptr, prop)) { - t->flag |= initTransInfo_edit_pet_to_flag(RNA_property_enum_get(op->ptr, prop)); + int proportional = 0; + if (RNA_property_boolean_get(op->ptr, prop)) { + proportional |= PROP_EDIT_USE; + if (RNA_boolean_get(op->ptr, "use_proportional_connected")) { + proportional |= PROP_EDIT_CONNECTED; + } + if (RNA_boolean_get(op->ptr, "use_proportional_projected")) { + proportional |= PROP_EDIT_PROJECTED; + } + } + t->flag |= initTransInfo_edit_pet_to_flag(proportional); } else { /* use settings from scene only if modal */ @@ -1619,16 +1677,16 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve t->flag |= initTransInfo_edit_pet_to_flag(ts->proportional_action); } else if (t->obedit_type != -1) { - t->flag |= initTransInfo_edit_pet_to_flag(ts->proportional); + t->flag |= initTransInfo_edit_pet_to_flag(ts->proportional_edit); } else if (t->options & CTX_GPENCIL_STROKES) { - t->flag |= initTransInfo_edit_pet_to_flag(ts->proportional); + t->flag |= initTransInfo_edit_pet_to_flag(ts->proportional_edit); } else if (t->options & CTX_MASK) { if (ts->proportional_mask) { t->flag |= T_PROP_EDIT; - if (ts->proportional == PROP_EDIT_CONNECTED) { + if (ts->proportional_edit & PROP_EDIT_CONNECTED) { t->flag |= T_PROP_CONNECTED; } } @@ -1718,8 +1776,7 @@ static void freeTransCustomDataContainer(TransInfo *t, void freeTransCustomDataForMode(TransInfo *t) { freeTransCustomData(t, NULL, &t->custom.mode); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { freeTransCustomData(t, tc, &tc->custom.mode); } } @@ -1727,14 +1784,18 @@ void freeTransCustomDataForMode(TransInfo *t) /* Here I would suggest only TransInfo related issues, like free data & reset vars. Not redraws */ void postTrans(bContext *C, TransInfo *t) { - if (t->draw_handle_view) + if (t->draw_handle_view) { ED_region_draw_cb_exit(t->ar->type, t->draw_handle_view); - if (t->draw_handle_apply) + } + if (t->draw_handle_apply) { ED_region_draw_cb_exit(t->ar->type, t->draw_handle_apply); - if (t->draw_handle_pixel) + } + if (t->draw_handle_pixel) { ED_region_draw_cb_exit(t->ar->type, t->draw_handle_pixel); - if (t->draw_handle_cursor) + } + if (t->draw_handle_cursor) { WM_paint_cursor_end(CTX_wm_manager(C), t->draw_handle_cursor); + } if (t->flag & T_MODAL_CURSOR_SET) { WM_cursor_modal_restore(CTX_wm_window(C)); @@ -1742,15 +1803,13 @@ void postTrans(bContext *C, TransInfo *t) /* Free all custom-data */ freeTransCustomDataContainer(t, NULL, &t->custom); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { freeTransCustomDataContainer(t, tc, &tc->custom); } /* postTrans can be called when nothing is selected, so data is NULL already */ if (t->data_len_all != 0) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { /* free data malloced per trans-data */ if (ELEM(t->obedit_type, OB_CURVE, OB_SURF) || (t->spacetype == SPACE_GRAPH)) { TransData *td = tc->data; @@ -1778,8 +1837,9 @@ void postTrans(bContext *C, TransInfo *t) } else { SpaceImage *sima = t->sa->spacedata.first; - if (sima->flag & SI_LIVE_UNWRAP) + if (sima->flag & SI_LIVE_UNWRAP) { ED_uvedit_live_unwrap_end(t->state == TRANS_CANCEL); + } } } else if (t->spacetype == SPACE_VIEW3D) { @@ -1856,8 +1916,7 @@ static void restoreElement(TransData *td) void restoreTransObjects(TransInfo *t) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td; TransData2D *td2d; @@ -1893,8 +1952,7 @@ void calculateCenterLocal(TransInfo *t, const float center_global[3]) { /* setting constraint center */ /* note, init functions may over-ride t->center */ - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { if (tc->use_local_mat) { mul_v3_m4v3(tc->center_local, tc->imat, center_global); } @@ -1986,8 +2044,7 @@ void calculateCenterMedian(TransInfo *t, float r_center[3]) float partial[3] = {0.0f, 0.0f, 0.0f}; int total = 0; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { for (int i = 0; i < tc->data_len; i++) { if (tc->data[i].flag & TD_SELECTED) { if (!(tc->data[i].flag & TD_NOCENTER)) { @@ -2015,8 +2072,7 @@ void calculateCenterBound(TransInfo *t, float r_center[3]) float max[3], min[3]; bool changed = false; INIT_MINMAX(min, max); - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { for (int i = 0; i < tc->data_len; i++) { if (tc->data[i].flag & TD_SELECTED) { if (!(tc->data[i].flag & TD_NOCENTER)) { @@ -2094,12 +2150,15 @@ static void calculateCenter_FromAround(TransInfo *t, int around, float r_center[ calculateCenterMedian(t, r_center); break; case V3D_AROUND_CURSOR: - if (ELEM(t->spacetype, SPACE_IMAGE, SPACE_CLIP)) + if (ELEM(t->spacetype, SPACE_IMAGE, SPACE_CLIP)) { calculateCenterCursor2D(t, r_center); - else if (t->spacetype == SPACE_GRAPH) + } + else if (t->spacetype == SPACE_GRAPH) { calculateCenterCursorGraph2D(t, r_center); - else + } + else { calculateCenterCursor(t, r_center); + } break; case V3D_AROUND_LOCAL_ORIGINS: /* Individual element center uses median center for helpline and such */ @@ -2160,7 +2219,8 @@ void calculateCenter(TransInfo *t) } if (t->spacetype == SPACE_VIEW3D) { - /* ED_view3d_calc_zfac() defines a factor for perspective depth correction, used in ED_view3d_win_to_delta() */ + /* ED_view3d_calc_zfac() defines a factor for perspective depth correction, + * used in ED_view3d_win_to_delta() */ /* zfac is only used convertViewVec only in cases operator was invoked in RGN_TYPE_WINDOW * and never used in other cases. @@ -2204,8 +2264,7 @@ void calculatePropRatio(TransInfo *t) if (t->flag & T_PROP_EDIT) { const char *pet_id = NULL; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { if (td->flag & TD_SELECTED) { @@ -2231,18 +2290,21 @@ void calculatePropRatio(TransInfo *t) /* Use rdist for falloff calculations, it is the real distance */ td->flag &= ~TD_NOACTION; - if (connected) + if (connected) { dist = (t->prop_size - td->dist) / t->prop_size; - else + } + else { dist = (t->prop_size - td->rdist) / t->prop_size; + } /* * Clamp to positive numbers. * Certain corner cases with connectivity and individual centers * can give values of rdist larger than propsize. */ - if (dist < 0.0f) + if (dist < 0.0f) { dist = 0.0f; + } switch (t->prop_mode) { case PROP_SHARP: @@ -2316,8 +2378,7 @@ void calculatePropRatio(TransInfo *t) } } else { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { td->factor = 1.0; diff --git a/source/blender/editors/transform/transform_gizmo_2d.c b/source/blender/editors/transform/transform_gizmo_2d.c index f5b8f19ed02..1015b47c304 100644 --- a/source/blender/editors/transform/transform_gizmo_2d.c +++ b/source/blender/editors/transform/transform_gizmo_2d.c @@ -231,8 +231,9 @@ void ED_widgetgroup_gizmo2d_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgro PointerRNA *ptr = WM_gizmo_operator_set(axis, 0, ot_translate, NULL); bool constraint[3] = {0}; constraint[(axis_idx + 1) % 2] = 1; - if (RNA_struct_find_property(ptr, "constraint_axis")) + if (RNA_struct_find_property(ptr, "constraint_axis")) { RNA_boolean_set_array(ptr, "constraint_axis", constraint); + } RNA_boolean_set(ptr, "release_confirm", 1); } MAN2D_ITER_AXES_END; @@ -385,8 +386,9 @@ bool ED_widgetgroup_gizmo2d_poll(const bContext *C, wmGizmoGroupType *UNUSED(gzg /* check if there's a selected poly */ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c index 1fde0006c2b..50610f1b3da 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.c @@ -116,7 +116,7 @@ static struct { /* Regular range */ {0.02f, 0.1f}, /* Use a different range because we flip the dot product, - * also the view aligned planes are harder to see so hiding early is preferred. */ + * also the view aligned planes are harder to see so hiding early is preferred. */ {0.175f, 0.25f}, }; @@ -352,7 +352,8 @@ static void gizmo_get_axis_color(const int axis_idx, else { bool is_plane = false; const int axis_idx_norm = gizmo_orientation_axis(axis_idx, &is_plane); - /* get alpha fac based on axis angle, to fade axis out when hiding it because it points towards view */ + /* Get alpha fac based on axis angle, + * to fade axis out when hiding it because it points towards view. */ if (axis_idx_norm < 3) { const float idot_min = g_tw_axis_range[is_plane].min; const float idot_max = g_tw_axis_range[is_plane].max; @@ -484,26 +485,35 @@ static void calc_tw_center_with_matrix(struct TransformBounds *tbounds, static void protectflag_to_drawflags(short protectflag, short *drawflags) { - if (protectflag & OB_LOCK_LOCX) + if (protectflag & OB_LOCK_LOCX) { *drawflags &= ~MAN_TRANS_X; - if (protectflag & OB_LOCK_LOCY) + } + if (protectflag & OB_LOCK_LOCY) { *drawflags &= ~MAN_TRANS_Y; - if (protectflag & OB_LOCK_LOCZ) + } + if (protectflag & OB_LOCK_LOCZ) { *drawflags &= ~MAN_TRANS_Z; + } - if (protectflag & OB_LOCK_ROTX) + if (protectflag & OB_LOCK_ROTX) { *drawflags &= ~MAN_ROT_X; - if (protectflag & OB_LOCK_ROTY) + } + if (protectflag & OB_LOCK_ROTY) { *drawflags &= ~MAN_ROT_Y; - if (protectflag & OB_LOCK_ROTZ) + } + if (protectflag & OB_LOCK_ROTZ) { *drawflags &= ~MAN_ROT_Z; + } - if (protectflag & OB_LOCK_SCALEX) + if (protectflag & OB_LOCK_SCALEX) { *drawflags &= ~MAN_SCALE_X; - if (protectflag & OB_LOCK_SCALEY) + } + if (protectflag & OB_LOCK_SCALEY) { *drawflags &= ~MAN_SCALE_Y; - if (protectflag & OB_LOCK_SCALEZ) + } + if (protectflag & OB_LOCK_SCALEZ) { *drawflags &= ~MAN_SCALE_Z; + } } /* for pose mode */ @@ -1054,8 +1064,9 @@ int ED_transform_calc_gizmo_stats(const bContext *C, if (edit) { point = edit->points; for (a = 0; a < edit->totpoint; a++, point++) { - if (point->flag & PEP_HIDE) + if (point->flag & PEP_HIDE) { continue; + } for (k = 0, ek = point->keys; k < point->totkey; k++, ek++) { if (ek->flag & PEK_SELECT) { @@ -1066,8 +1077,9 @@ int ED_transform_calc_gizmo_stats(const bContext *C, } /* selection center */ - if (totsel) + if (totsel) { mul_v3_fl(tbounds->center, 1.0f / (float)totsel); // centroid! + } } } else { @@ -1075,8 +1087,9 @@ int ED_transform_calc_gizmo_stats(const bContext *C, /* we need the one selected object, if its not active */ base = BASACT(view_layer); ob = OBACT(view_layer); - if (base && ((base->flag & BASE_SELECTED) == 0)) + if (base && ((base->flag & BASE_SELECTED) == 0)) { ob = NULL; + } for (base = view_layer->object_bases.first; base; base = base->next) { if (!BASE_SELECTED_EDITABLE(v3d, base)) { diff --git a/source/blender/editors/transform/transform_input.c b/source/blender/editors/transform/transform_input.c index 46f6e576cf4..6ebed88878f 100644 --- a/source/blender/editors/transform/transform_input.c +++ b/source/blender/editors/transform/transform_input.c @@ -223,8 +223,9 @@ static void InputAngle(TransInfo *UNUSED(t), MouseInput *mi, const double mval[2 float dphi; dphi = saacos((float)deler); - if ((dx1 * dy2 - dx2 * dy1) > 0.0) + if ((dx1 * dy2 - dx2 * dy1) > 0.0) { dphi = -dphi; + } /* If the angle is zero, because of lack of precision close to the 1.0 value in acos * approximate the angle with the opposite side of the normalized triangle @@ -244,8 +245,9 @@ static void InputAngle(TransInfo *UNUSED(t), MouseInput *mi, const double mval[2 dy = dy1 - dy2; dphi = sqrt(dx * dx + dy * dy); - if ((dx1 * dy2 - dx2 * dy1) > 0.0) + if ((dx1 * dy2 - dx2 * dy1) > 0.0) { dphi = -dphi; + } } data->angle += ((double)dphi) * (mi->precision ? (double)mi->precision_factor : 1.0); diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 14d904fdc6d..8606cd19c96 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -230,8 +230,9 @@ static bool delete_orientation_poll(bContext *C) { Scene *scene = CTX_data_scene(C); - if (ED_operator_areaactive(C) == 0) + if (ED_operator_areaactive(C) == 0) { return 0; + } return ((scene->orientation_slots[SCE_ORIENT_DEFAULT].type >= V3D_ORIENT_CUSTOM) && (scene->orientation_slots[SCE_ORIENT_DEFAULT].index_custom != -1)); @@ -403,8 +404,9 @@ static int transform_modal(bContext *C, wmOperator *op, const wmEvent *event) // in other words, 2D deltas are no longer good enough! // disable until individual 'transformers' behave better - if (event->type == NDOF_MOTION) + if (event->type == NDOF_MOTION) { return OPERATOR_PASS_THROUGH; + } #endif /* XXX insert keys are called here, and require context */ @@ -545,10 +547,9 @@ static bool transform_poll_property(const bContext *UNUSED(C), /* Proportional Editing. */ { - PropertyRNA *prop_pet = RNA_struct_find_property(op->ptr, "proportional"); - if (prop_pet && (prop_pet != prop) && - (RNA_property_enum_get(op->ptr, prop_pet) == PROP_EDIT_OFF)) { - if (STRPREFIX(prop_id, "proportional")) { + PropertyRNA *prop_pet = RNA_struct_find_property(op->ptr, "use_proportional_edit"); + if (prop_pet && (prop_pet != prop) && (RNA_property_boolean_get(op->ptr, prop_pet) == false)) { + if (STRPREFIX(prop_id, "proportional") || STRPREFIX(prop_id, "use_proportional")) { return false; } } @@ -608,12 +609,7 @@ void Transform_Properties(struct wmOperatorType *ot, int flags) } if (flags & P_PROPORTIONAL) { - RNA_def_enum(ot->srna, - "proportional", - rna_enum_proportional_editing_items, - 0, - "Proportional Editing", - ""); + RNA_def_boolean(ot->srna, "use_proportional_edit", 0, "Proportional Editing", ""); prop = RNA_def_enum(ot->srna, "proportional_edit_falloff", rna_enum_proportional_falloff_items, @@ -631,6 +627,9 @@ void Transform_Properties(struct wmOperatorType *ot, int flags) "", 0.001f, 100.0f); + + RNA_def_boolean(ot->srna, "use_proportional_connected", 0, "Connected", ""); + RNA_def_boolean(ot->srna, "use_proportional_projected", 0, "Projected (2D)", ""); } if (flags & P_SNAP) { @@ -975,7 +974,7 @@ static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot) { /* identifiers */ ot->name = "To Sphere"; - //added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()" + // added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()" ot->description = "Move selected vertices outward in a spherical shape around mesh center"; ot->idname = OP_TOSPHERE; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; @@ -1161,7 +1160,7 @@ static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot) static void TRANSFORM_OT_rotate_normal(struct wmOperatorType *ot) { /* identifiers */ - ot->name = "Normal Rotate"; + ot->name = "Rotate Normals"; ot->description = "Rotate split normal of selected items"; ot->idname = OP_NORMAL_ROTATION; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 18b19d903c4..e16579aba64 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -100,8 +100,9 @@ static TransformOrientation *createViewSpace(bContext *C, RegionView3D *rv3d = CTX_wm_region_view3d(C); float mat[3][3]; - if (!rv3d) + if (!rv3d) { return NULL; + } copy_m3_m4(mat, rv3d->viewinv); normalize_m3(mat); @@ -129,8 +130,9 @@ static TransformOrientation *createObjectSpace(bContext *C, Object *ob; float mat[3][3]; - if (base == NULL) + if (base == NULL) { return NULL; + } ob = base->object; @@ -309,12 +311,15 @@ void BIF_createTransformOrientation(bContext *C, Object *obedit = CTX_data_edit_object(C); Object *ob = CTX_data_active_object(C); if (obedit) { - if (obedit->type == OB_MESH) + if (obedit->type == OB_MESH) { ts = createMeshSpace(C, reports, name, overwrite); - else if (obedit->type == OB_ARMATURE) + } + else if (obedit->type == OB_ARMATURE) { ts = createBoneSpace(C, reports, name, overwrite); - else if (obedit->type == OB_CURVE) + } + else if (obedit->type == OB_CURVE) { ts = createCurveSpace(C, reports, name, overwrite); + } } else if (ob && (ob->mode & OB_MODE_POSE)) { ts = createBoneSpace(C, reports, name, overwrite); @@ -587,8 +592,7 @@ static unsigned int bm_mesh_edges_select_get_n(BMesh *bm, BMEdge **elems, const static unsigned int bm_mesh_faces_select_get_n(BMesh *bm, BMVert **elems, const unsigned int n) { return bm_mesh_elems_select_get_n__internal( - bm, (BMElem **)elems, min_ii(n, bm->totfacesel), - BM_FACES_OF_MESH, BM_FACE); + bm, (BMElem **)elems, min_ii(n, bm->totfacesel), BM_FACES_OF_MESH, BM_FACE); } #endif @@ -781,8 +785,10 @@ int getTransformOrientation_ex(const bContext *C, if (BM_vert_edge_pair(v, &e_pair[0], &e_pair[1])) { bool v_pair_swap = false; - BMVert *v_pair[2] = {BM_edge_other_vert(e_pair[0], v), - BM_edge_other_vert(e_pair[1], v)}; + BMVert *v_pair[2] = { + BM_edge_other_vert(e_pair[0], v), + BM_edge_other_vert(e_pair[1], v), + }; float dir_pair[2][3]; if (BM_edge_is_boundary(e_pair[0])) { @@ -867,12 +873,15 @@ int getTransformOrientation_ex(const bContext *C, #define SEL_F3 (1 << 2) if (use_handle) { - if (bezt->f1 & SELECT) + if (bezt->f1 & SELECT) { flag |= SEL_F1; - if (bezt->f2 & SELECT) + } + if (bezt->f2 & SELECT) { flag |= SEL_F2; - if (bezt->f3 & SELECT) + } + if (bezt->f3 & SELECT) { flag |= SEL_F3; + } } else { flag = (bezt->f2 & SELECT) ? (SEL_F1 | SEL_F2 | SEL_F3) : 0; diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index d9cc9e3fcee..58a50da9846 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -152,8 +152,9 @@ void drawSnapping(const struct bContext *C, TransInfo *t) { unsigned char col[4], selectedCol[4], activeCol[4]; - if (!activeSnap(t)) + if (!activeSnap(t)) { return; + } UI_GetThemeColor3ubv(TH_TRANSFORM, col); col[3] = 128; @@ -289,21 +290,23 @@ void applyProject(TransInfo *t) float tvec[3]; int i; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { float iloc[3], loc[3], no[3]; float mval_fl[2]; - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } - if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) + if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) { continue; + } copy_v3_v3(iloc, td->loc); if (tc->use_local_mat) { @@ -357,7 +360,7 @@ void applyProject(TransInfo *t) } } - //XXX constraintTransLim(t, td); + // XXX constraintTransLim(t, td); } } } @@ -369,12 +372,14 @@ void applyGridAbsolute(TransInfo *t) GearsType grid_action; int i; - if (!(activeSnap(t) && (t->tsnap.mode & (SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)))) + if (!(activeSnap(t) && (t->tsnap.mode & (SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)))) { return; + } grid_action = BIG_GEARS; - if (t->modifiers & MOD_PRECISION) + if (t->modifiers & MOD_PRECISION) { grid_action = SMALL_GEARS; + } switch (grid_action) { case NO_GEARS: @@ -388,24 +393,27 @@ void applyGridAbsolute(TransInfo *t) break; } /* early exit on unusable grid size */ - if (grid_size == 0.0f) + if (grid_size == 0.0f) { return; + } - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td; for (i = 0, td = tc->data; i < tc->data_len; i++, td++) { float iloc[3], loc[3], tvec[3]; - if (td->flag & TD_NOACTION) + if (td->flag & TD_NOACTION) { break; + } - if (td->flag & TD_SKIP) + if (td->flag & TD_SKIP) { continue; + } - if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) + if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) { continue; + } copy_v3_v3(iloc, td->loc); if (tc->use_local_mat) { @@ -543,8 +551,9 @@ static void initSnappingMode(TransInfo *t) } else { /* force project off when not supported */ - if ((ts->snap_mode & SCE_SNAP_MODE_FACE) == 0) + if ((ts->snap_mode & SCE_SNAP_MODE_FACE) == 0) { t->tsnap.project = 0; + } t->tsnap.mode = ts->snap_mode; } @@ -582,7 +591,8 @@ static void initSnappingMode(TransInfo *t) else if (t->tsnap.applySnap != NULL && // A snapping function actually exist (obedit_type == -1)) // Object Mode { - /* In "Edit Strokes" mode, Snap tool can perform snap to selected or active objects (see T49632) + /* In "Edit Strokes" mode, + * snap tool can perform snap to selected or active objects (see T49632) * TODO: perform self snap in gpencil_strokes */ t->tsnap.modeSelect = (((t->options & (CTX_GPENCIL_STROKES | CTX_CURSOR)) != 0) ? SNAP_ALL : @@ -852,10 +862,12 @@ static void ApplySnapTranslation(TransInfo *t, float vec[3]) if (t->spacetype == SPACE_NODE) { char border = t->tsnap.snapNodeBorder; - if (border & (NODE_LEFT | NODE_RIGHT)) + if (border & (NODE_LEFT | NODE_RIGHT)) { vec[0] = point[0] - t->tsnap.snapTarget[0]; - if (border & (NODE_BOTTOM | NODE_TOP)) + } + if (border & (NODE_BOTTOM | NODE_TOP)) { vec[1] = point[1] - t->tsnap.snapTarget[1]; + } } else { if (t->spacetype == SPACE_VIEW3D) { @@ -922,10 +934,12 @@ static float RotationBetween(TransInfo *t, const float p1[3], const float p2[3]) cross_v3_v3v3(tmp, start, end); - if (dot_v3v3(tmp, axis) < 0.0f) + if (dot_v3v3(tmp, axis) < 0.0f) { angle = -acosf(dot_v3v3(start, end)); - else + } + else { angle = acosf(dot_v3v3(start, end)); + } } else { float mtx[3][3]; @@ -1063,23 +1077,31 @@ static void TargetSnapOffset(TransInfo *t, TransData *td) float height = BLI_rctf_size_y(&node->totr); #ifdef USE_NODE_CENTER - if (border & NODE_LEFT) + if (border & NODE_LEFT) { t->tsnap.snapTarget[0] -= 0.5f * width; - if (border & NODE_RIGHT) + } + if (border & NODE_RIGHT) { t->tsnap.snapTarget[0] += 0.5f * width; - if (border & NODE_BOTTOM) + } + if (border & NODE_BOTTOM) { t->tsnap.snapTarget[1] -= 0.5f * height; - if (border & NODE_TOP) + } + if (border & NODE_TOP) { t->tsnap.snapTarget[1] += 0.5f * height; + } #else - if (border & NODE_LEFT) + if (border & NODE_LEFT) { t->tsnap.snapTarget[0] -= 0.0f; - if (border & NODE_RIGHT) + } + if (border & NODE_RIGHT) { t->tsnap.snapTarget[0] += width; - if (border & NODE_BOTTOM) + } + if (border & NODE_BOTTOM) { t->tsnap.snapTarget[1] -= height; - if (border & NODE_TOP) + } + if (border & NODE_TOP) { t->tsnap.snapTarget[1] += 0.0f; + } #endif } } @@ -1123,8 +1145,7 @@ static void TargetSnapMedian(TransInfo *t) t->tsnap.snapTarget[1] = 0; t->tsnap.snapTarget[2] = 0; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; int i; float v[3]; @@ -1160,8 +1181,7 @@ static void TargetSnapClosest(TransInfo *t) /* Object mode */ if (t->flag & T_OBJECT) { int i; - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (td = tc->data, i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) { struct BoundBox *bb = BKE_object_boundbox_get(td->ob); @@ -1206,8 +1226,7 @@ static void TargetSnapClosest(TransInfo *t) } } else { - FOREACH_TRANS_DATA_CONTAINER(t, tc) - { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; int i; for (i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) { @@ -1506,8 +1525,9 @@ void snapSequenceBounds(TransInfo *t, const int mval[2]) int mframe; TransSeq *ts = TRANS_DATA_CONTAINER_FIRST_SINGLE(t)->custom.type.data; /* reuse increment, strictly speaking could be another snap mode, but leave as is */ - if (!(t->modifiers & MOD_SNAP_INVERT)) + if (!(t->modifiers & MOD_SNAP_INVERT)) { return; + } /* convert to frame range */ UI_view2d_region_to_view(&t->ar->v2d, mval[0], mval[1], &xmouse, &ymouse); @@ -1515,8 +1535,9 @@ void snapSequenceBounds(TransInfo *t, const int mval[2]) /* now find the closest sequence */ frame = BKE_sequencer_find_next_prev_edit(t->scene, mframe, SEQ_SIDE_BOTH, true, false, true); - if (!ts->snap_left) + if (!ts->snap_left) { frame = frame - (ts->max - ts->min); + } t->values[0] = frame - ts->min; } @@ -1542,24 +1563,11 @@ static void applyGridIncrement( /* custom aspect for fcurve */ if (t->spacetype == SPACE_GRAPH) { View2D *v2d = &t->ar->v2d; - View2DGrid *grid; + Scene *scene = t->scene; SpaceGraph *sipo = t->sa->spacedata.first; - int unity = V2D_UNIT_VALUES; - int unitx = (sipo->flag & SIPO_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMESCALE; - - /* grid */ - grid = UI_view2d_grid_calc(t->scene, - v2d, - unitx, - V2D_GRID_NOCLAMP, - unity, - V2D_GRID_NOCLAMP, - t->ar->winx, - t->ar->winy); - - UI_view2d_grid_size(grid, &asp_local[0], &asp_local[1]); - UI_view2d_grid_free(grid); - + asp_local[0] = UI_view2d_grid_resolution_x__frames_or_seconds( + v2d, scene, sipo->flag & SIPO_DRAWTIME); + asp_local[1] = UI_view2d_grid_resolution_y__values(v2d); asp = asp_local; } } diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index 93f89c1919e..829365367ee 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -826,7 +826,8 @@ static void raycast_obj_cb( * Read/Write Args * --------------- * - * \param ray_depth: maximum depth allowed for r_co, elements deeper than this value will be ignored. + * \param ray_depth: maximum depth allowed for r_co, + * elements deeper than this value will be ignored. * * Output Args * ----------- @@ -887,7 +888,8 @@ static bool snap_bound_box_check_dist(float min[3], float mval[2], float dist_px_sq) { - /* In vertex and edges you need to get the pixel distance from ray to BoundBox, see: T46099, T46816 */ + /* In vertex and edges you need to get the pixel distance from ray to BoundBox, + * see: T46099, T46816 */ struct DistProjectedAABBPrecalc data_precalc; dist_squared_to_projected_aabb_precalc(&data_precalc, lpmat, win_size, mval); @@ -951,11 +953,12 @@ static void cb_mlooptri_edges_get(const int index, int v_index[3], const BVHTree const MEdge *ed = &medge[mloop[lt->tri[j]].e]; unsigned int tri_edge[2] = {mloop[lt->tri[j]].v, mloop[lt->tri[j_next]].v}; if (ELEM(ed->v1, tri_edge[0], tri_edge[1]) && ELEM(ed->v2, tri_edge[0], tri_edge[1])) { - //printf("real edge found\n"); + // printf("real edge found\n"); v_index[j] = mloop[lt->tri[j]].e; } - else + else { v_index[j] = -1; + } } } @@ -1626,7 +1629,8 @@ static short snapCurve(SnapData *snapdata, nu->bezt[u].vec[1], &dist_px_sq, r_loc); - /* don't snap if handle is selected (moving), or if it is aligning to a moving handle */ + /* Don't snap if handle is selected (moving), + * or if it is aligning to a moving handle. */ if (!(nu->bezt[u].f1 & SELECT) && !(nu->bezt[u].h1 & HD_ALIGN && nu->bezt[u].f3 & SELECT)) { has_snap |= test_projected_vert_dist(&neasrest_precalc, diff --git a/source/blender/editors/undo/CMakeLists.txt b/source/blender/editors/undo/CMakeLists.txt index 7c1a074bb13..0f4152c9128 100644 --- a/source/blender/editors/undo/CMakeLists.txt +++ b/source/blender/editors/undo/CMakeLists.txt @@ -24,8 +24,8 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/clog + ../../../../intern/guardedalloc ) set(SRC diff --git a/source/blender/editors/undo/ed_undo.c b/source/blender/editors/undo/ed_undo.c index 08f1a13e0c2..49b5cada04a 100644 --- a/source/blender/editors/undo/ed_undo.c +++ b/source/blender/editors/undo/ed_undo.c @@ -476,15 +476,16 @@ int ED_undo_operator_repeat(bContext *C, wmOperator *op) if ((WM_operator_repeat_check(C, op)) && (WM_operator_poll(C, op->type)) && /* note, undo/redo cant run if there are jobs active, - * check for screen jobs only so jobs like material/texture/world preview - * (which copy their data), wont stop redo, see [#29579]], - * - * note, - WM_operator_check_ui_enabled() jobs test _must_ stay in sync with this */ + * check for screen jobs only so jobs like material/texture/world preview + * (which copy their data), wont stop redo, see [#29579]], + * + * note, - WM_operator_check_ui_enabled() jobs test _must_ stay in sync with this */ (WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY) == 0)) { int retval; - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("redo_cb: operator redo %s\n", op->type->name); + } WM_operator_free_all_after(wm, op); @@ -511,8 +512,9 @@ int ED_undo_operator_repeat(bContext *C, wmOperator *op) retval = WM_operator_repeat(C, op); if ((retval & OPERATOR_FINISHED) == 0) { - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("redo_cb: operator redo failed: %s, return %d\n", op->type->name, retval); + } ED_undo_redo(C); } else { diff --git a/source/blender/editors/undo/memfile_undo.c b/source/blender/editors/undo/memfile_undo.c index 36ce38091d4..0f495d64b29 100644 --- a/source/blender/editors/undo/memfile_undo.c +++ b/source/blender/editors/undo/memfile_undo.c @@ -115,7 +115,8 @@ static void memfile_undosys_step_decode(struct bContext *C, static void memfile_undosys_step_free(UndoStep *us_p) { - /* To avoid unnecessary slow down, free backwards (so we don't need to merge when clearing all). */ + /* To avoid unnecessary slow down, free backwards + * (so we don't need to merge when clearing all). */ MemFileUndoStep *us = (MemFileUndoStep *)us_p; if (us_p->next != NULL) { UndoStep *us_next_p = BKE_undosys_step_same_type_next(us_p); @@ -149,7 +150,8 @@ void ED_memfile_undosys_type(UndoType *ut) * \{ */ /** - * Ideally we wouldn't need to export global undo internals, there are some cases where it's needed though. + * Ideally we wouldn't need to export global undo internals, + * there are some cases where it's needed though. */ static struct MemFile *ed_undosys_step_get_memfile(UndoStep *us_p) { diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index a1893d8e6f1..3b49784d5eb 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -22,14 +22,14 @@ set(INC ../../blentranslation ../../bmesh ../../depsgraph - ../../imbuf ../../gpu + ../../imbuf ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/clog ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/util/ed_transverts.c b/source/blender/editors/util/ed_transverts.c index 4cc74bec7d9..f054d09094d 100644 --- a/source/blender/editors/util/ed_transverts.c +++ b/source/blender/editors/util/ed_transverts.c @@ -74,8 +74,9 @@ void ED_transverts_update_obedit(TransVertStore *tvs, Object *obedit) while (a--) { if (bezt->hide == 0) { bool skip_handle = false; - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { skip_handle = (mode & TM_SKIP_HANDLES) != 0; + } if ((bezt->f1 & SELECT) && !skip_handle) { BLI_assert(tv->loc == bezt->vec[0]); @@ -131,8 +132,9 @@ void ED_transverts_update_obedit(TransVertStore *tvs, Object *obedit) add_v3_v3(ebo->tail, diffvec); a++; - if (a < tvs->transverts_tot) + if (a < tvs->transverts_tot) { tv++; + } } } } @@ -150,14 +152,16 @@ void ED_transverts_update_obedit(TransVertStore *tvs, Object *obedit) } } } - if (arm->flag & ARM_MIRROR_EDIT) + if (arm->flag & ARM_MIRROR_EDIT) { ED_armature_edit_transform_mirror_update(obedit); + } } else if (obedit->type == OB_LATTICE) { Lattice *lt = obedit->data; - if (lt->editlatt->latt->flag & LT_OUTSIDE) + if (lt->editlatt->latt->flag & LT_OUTSIDE) { outside_lattice(lt->editlatt->latt); + } } } @@ -247,8 +251,9 @@ void ED_transverts_create_from_obedit(TransVertStore *tvs, Object *obedit, const } BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { - if (BM_elem_index_get(eve) == TM_INDEX_ON) + if (BM_elem_index_get(eve) == TM_INDEX_ON) { tvs->transverts_tot++; + } } } else { @@ -270,8 +275,9 @@ void ED_transverts_create_from_obedit(TransVertStore *tvs, Object *obedit, const } BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { - if (BM_elem_index_get(eve) == TM_INDEX_ON) + if (BM_elem_index_get(eve) == TM_INDEX_ON) { tvs->transverts_tot++; + } } } /* for any of the 3 loops above which all dirty the indices */ @@ -363,10 +369,12 @@ void ED_transverts_create_from_obedit(TransVertStore *tvs, Object *obedit, const ListBase *nurbs = BKE_curve_editNurbs_get(cu); for (nu = nurbs->first; nu; nu = nu->next) { - if (nu->type == CU_BEZIER) + if (nu->type == CU_BEZIER) { totmalloc += 3 * nu->pntsu; - else + } + else { totmalloc += nu->pntsu * nu->pntsv; + } } tv = tvs->transverts = MEM_callocN(totmalloc * sizeof(TransVert), __func__); @@ -378,8 +386,9 @@ void ED_transverts_create_from_obedit(TransVertStore *tvs, Object *obedit, const while (a--) { if (bezt->hide == 0) { bool skip_handle = false; - if (bezt->f2 & SELECT) + if (bezt->f2 & SELECT) { skip_handle = (mode & TM_SKIP_HANDLES) != 0; + } if ((bezt->f1 & SELECT) && !skip_handle) { copy_v3_v3(tv->oldloc, bezt->vec[0]); diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index 503910d1734..df1906ea8a8 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -271,20 +271,24 @@ void apply_keyb_grid( int shift, int ctrl, float *val, float fac1, float fac2, float fac3, int invert) { /* fac1 is for 'nothing', fac2 for CTRL, fac3 for SHIFT */ - if (invert) + if (invert) { ctrl = !ctrl; + } if (ctrl && shift) { - if (fac3 != 0.0f) + if (fac3 != 0.0f) { *val = fac3 * floorf(*val / fac3 + 0.5f); + } } else if (ctrl) { - if (fac2 != 0.0f) + if (fac2 != 0.0f) { *val = fac2 * floorf(*val / fac2 + 0.5f); + } } else { - if (fac1 != 0.0f) + if (fac1 != 0.0f) { *val = fac1 * floorf(*val / fac1 + 0.5f); + } } } @@ -326,7 +330,7 @@ void unpack_menu(bContext *C, break; case PF_EQUAL: BLI_snprintf(line, sizeof(line), IFACE_("Use %s (identical)"), local_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_LOCAL); + // uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_LOCAL); uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL); RNA_string_set(&props_ptr, "id", id_name); @@ -334,13 +338,13 @@ void unpack_menu(bContext *C, break; case PF_DIFFERS: BLI_snprintf(line, sizeof(line), IFACE_("Use %s (differs)"), local_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_LOCAL); + // uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_LOCAL); uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL); RNA_string_set(&props_ptr, "id", id_name); BLI_snprintf(line, sizeof(line), IFACE_("Overwrite %s"), local_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_LOCAL); + // uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_LOCAL); uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL); RNA_string_set(&props_ptr, "id", id_name); @@ -352,27 +356,27 @@ void unpack_menu(bContext *C, switch (checkPackedFile(BKE_main_blendfile_path(bmain), abs_name, pf)) { case PF_NOFILE: BLI_snprintf(line, sizeof(line), IFACE_("Create %s"), abs_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL); + // uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL); uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL); RNA_string_set(&props_ptr, "id", id_name); break; case PF_EQUAL: BLI_snprintf(line, sizeof(line), IFACE_("Use %s (identical)"), abs_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_ORIGINAL); + // uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_ORIGINAL); uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL); RNA_string_set(&props_ptr, "id", id_name); break; case PF_DIFFERS: BLI_snprintf(line, sizeof(line), IFACE_("Use %s (differs)"), abs_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_ORIGINAL); + // uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_ORIGINAL); uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL); RNA_string_set(&props_ptr, "id", id_name); BLI_snprintf(line, sizeof(line), IFACE_("Overwrite %s"), abs_name); - //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL); + // uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL); uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &props_ptr); RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL); RNA_string_set(&props_ptr, "id", id_name); @@ -391,8 +395,10 @@ void ED_region_draw_mouse_line_cb(const bContext *C, ARegion *ar, void *arg_info { wmWindow *win = CTX_wm_window(C); const float *mval_src = (float *)arg_info; - const float mval_dst[2] = {win->eventstate->x - ar->winrct.xmin, - win->eventstate->y - ar->winrct.ymin}; + const float mval_dst[2] = { + win->eventstate->x - ar->winrct.xmin, + win->eventstate->y - ar->winrct.ymin, + }; const uint shdr_pos = GPU_vertformat_attr_add( immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c index 0ab37d61ce4..8abd8db53c1 100644 --- a/source/blender/editors/util/numinput.c +++ b/source/blender/editors/util/numinput.c @@ -452,7 +452,8 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) utf8_buf = ascii; break; #if 0 - /* Those keys are not directly accessible in all layouts, preventing to generate matching events. + /* Those keys are not directly accessible in all layouts, + * preventing to generate matching events. * So we use a hack (ascii value) instead, see below. */ case EQUALKEY: diff --git a/source/blender/editors/util/select_utils.c b/source/blender/editors/util/select_utils.c index 13c623a2860..a26579b0d84 100644 --- a/source/blender/editors/util/select_utils.c +++ b/source/blender/editors/util/select_utils.c @@ -115,8 +115,8 @@ bool ED_select_similar_compare_float_tree(const KDTree_1d *tree, case SIM_CMP_GT: /* Compare against the shortest edge. */ /* -FLT_MAX leads to some precision issues and the wrong edge being selected. - * For example, in a tree with 1, 2 and 3, which is stored squared as 1, 4, 9, it returns as the nearest - * length/node the "4" instead of "1". */ + * For example, in a tree with 1, 2 and 3, which is stored squared as 1, 4, 9, + * it returns as the nearest length/node the "4" instead of "1". */ nearest_edge_length = -1.0f; break; case SIM_CMP_LT: diff --git a/source/blender/editors/uvedit/CMakeLists.txt b/source/blender/editors/uvedit/CMakeLists.txt index 240cfd382a4..d2ba9ab9591 100644 --- a/source/blender/editors/uvedit/CMakeLists.txt +++ b/source/blender/editors/uvedit/CMakeLists.txt @@ -26,9 +26,9 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/guardedalloc ../../../../intern/eigen ../../../../intern/glew-mx + ../../../../intern/guardedalloc ) set(INC_SYS diff --git a/source/blender/editors/uvedit/uvedit_buttons.c b/source/blender/editors/uvedit/uvedit_buttons.c index 16620436029..1482fea456d 100644 --- a/source/blender/editors/uvedit/uvedit_buttons.c +++ b/source/blender/editors/uvedit/uvedit_buttons.c @@ -69,8 +69,9 @@ static int uvedit_center(Scene *scene, Object *obedit, BMEditMesh *em, Image *im zero_v2(center); BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, f)) + if (!uvedit_face_visible_test(scene, obedit, ima, f)) { continue; + } BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { @@ -100,8 +101,9 @@ static void uvedit_translate( const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, f)) + if (!uvedit_face_visible_test(scene, obedit, ima, f)) { continue; + } BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { @@ -203,8 +205,9 @@ static void do_uvedit_vertex(bContext *C, void *UNUSED(arg), int event) float center[2], delta[2]; int imx, imy; - if (event != B_UVEDIT_VERTEX) + if (event != B_UVEDIT_VERTEX) { return; + } em = BKE_editmesh_from_object(obedit); @@ -255,6 +258,8 @@ void ED_uvedit_buttons_register(ARegionType *art) pt = MEM_callocN(sizeof(PanelType), "spacetype image panel uv"); strcpy(pt->idname, "IMAGE_PT_uv"); strcpy(pt->label, N_("UV Vertex")); /* XXX C panels unavailable through RNA bpy.types! */ + /* Could be 'Item' matching 3D view, avoid new tab for two buttons. */ + strcpy(pt->category, "Image"); pt->draw = image_panel_uv; pt->poll = image_panel_uv_poll; BLI_addtail(&art->paneltypes, pt); diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c index 5ff90097840..804b9c22104 100644 --- a/source/blender/editors/uvedit/uvedit_draw.c +++ b/source/blender/editors/uvedit/uvedit_draw.c @@ -72,15 +72,19 @@ static int draw_uvs_face_check(const ToolSettings *ts) { /* checks if we are selecting only faces */ if (ts->uv_flag & UV_SYNC_SELECTION) { - if (ts->selectmode == SCE_SELECT_FACE) + if (ts->selectmode == SCE_SELECT_FACE) { return 2; - else if (ts->selectmode & SCE_SELECT_FACE) + } + else if (ts->selectmode & SCE_SELECT_FACE) { return 1; - else + } + else { return 0; + } } - else + else { return (ts->uv_selectmode == UV_SELECT_FACE); + } } /* ------------------------- */ @@ -461,8 +465,9 @@ static void draw_uv_shadows_get( { *show_shadow = *show_texpaint = false; - if (ED_space_image_show_render(sima) || (sima->flag & SI_NO_DRAW_TEXPAINT)) + if (ED_space_image_show_render(sima) || (sima->flag & SI_NO_DRAW_TEXPAINT)) { return; + } if ((sima->mode == SI_MODE_PAINT) && obedit && obedit->type == OB_MESH) { struct BMEditMesh *em = BKE_editmesh_from_object(obedit); @@ -474,14 +479,12 @@ static void draw_uv_shadows_get( } void ED_uvedit_draw_main(SpaceImage *sima, - ARegion *ar, Scene *scene, ViewLayer *view_layer, Object *obedit, Object *obact, Depsgraph *depsgraph) { - ToolSettings *toolsettings = scene->toolsettings; bool show_uvedit, show_uvshadow, show_texpaint_uvshadow; show_uvedit = ED_space_image_show_uvedit(sima, obedit); @@ -504,8 +507,5 @@ void ED_uvedit_draw_main(SpaceImage *sima, else { draw_uvs_texpaint(scene, obact, depsgraph); } - - if (show_uvedit && !(toolsettings->use_uv_sculpt)) - ED_image_draw_cursor(ar, sima->cursor); } } diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 291dbdf6942..30ded60bd84 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -114,11 +114,13 @@ bool ED_uvedit_test(Object *obedit) BMEditMesh *em; int ret; - if (!obedit) + if (!obedit) { return 0; + } - if (obedit->type != OB_MESH) + if (obedit->type != OB_MESH) { return 0; + } em = BKE_editmesh_from_object(obedit); ret = EDBM_uv_check(em); @@ -126,15 +128,6 @@ bool ED_uvedit_test(Object *obedit) return ret; } -static bool ED_operator_uvedit_can_uv_sculpt(struct bContext *C) -{ - SpaceImage *sima = CTX_wm_space_image(C); - ToolSettings *toolsettings = CTX_data_tool_settings(C); - Object *obedit = CTX_data_edit_object(C); - - return ED_space_image_show_uvedit(sima, obedit) && !(toolsettings->use_uv_sculpt); -} - static int UNUSED_FUNCTION(ED_operator_uvmap_mesh)(bContext *C) { Object *ob = CTX_data_active_object(C); @@ -142,8 +135,9 @@ static int UNUSED_FUNCTION(ED_operator_uvmap_mesh)(bContext *C) if (ob && ob->type == OB_MESH) { Mesh *me = ob->data; - if (CustomData_get_layer(&me->fdata, CD_MTFACE) != NULL) + if (CustomData_get_layer(&me->fdata, CD_MTFACE) != NULL) { return 1; + } } return 0; @@ -172,8 +166,9 @@ bool ED_object_get_active_image(Object *ob, bNode *node = (ntree) ? nodeGetActiveTexture(ntree) : NULL; if (node && is_image_texture_node(node)) { - if (r_ima) + if (r_ima) { *r_ima = (Image *)node->id; + } if (r_iuser) { if (node->type == SH_NODE_TEX_IMAGE) { *r_iuser = &((NodeTexImage *)node->storage)->iuser; @@ -185,21 +180,27 @@ bool ED_object_get_active_image(Object *ob, *r_iuser = NULL; } } - if (r_node) + if (r_node) { *r_node = node; - if (r_ntree) + } + if (r_ntree) { *r_ntree = ntree; + } return true; } - if (r_ima) + if (r_ima) { *r_ima = NULL; - if (r_iuser) + } + if (r_iuser) { *r_iuser = NULL; - if (r_node) + } + if (r_node) { *r_node = node; - if (r_ntree) + } + if (r_ntree) { *r_ntree = ntree; + } return false; } @@ -263,10 +264,12 @@ static void uvedit_vertex_select_tagged(BMEditMesh *em, bool uvedit_face_visible_nolocal_ex(const ToolSettings *ts, BMFace *efa) { - if (ts->uv_flag & UV_SYNC_SELECTION) + if (ts->uv_flag & UV_SYNC_SELECTION) { return (BM_elem_flag_test(efa, BM_ELEM_HIDDEN) == 0); - else + } + else { return (BM_elem_flag_test(efa, BM_ELEM_HIDDEN) == 0 && BM_elem_flag_test(efa, BM_ELEM_SELECT)); + } } bool uvedit_face_visible_nolocal(Scene *scene, BMFace *efa) { @@ -301,8 +304,9 @@ bool uvedit_face_select_test_ex(const ToolSettings *ts, BMFace *efa, const int c BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - if (!(luv->flag & MLOOPUV_VERTSEL)) + if (!(luv->flag & MLOOPUV_VERTSEL)) { return false; + } } return true; @@ -432,10 +436,12 @@ void uvedit_edge_select_enable( ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) { - if (ts->selectmode & SCE_SELECT_FACE) + if (ts->selectmode & SCE_SELECT_FACE) { BM_face_select_set(em->bm, l->f, true); - else if (ts->selectmode & SCE_SELECT_EDGE) + } + else if (ts->selectmode & SCE_SELECT_EDGE) { BM_edge_select_set(em->bm, l->e, true); + } else { BM_vert_select_set(em->bm, l->e->v1, true); BM_vert_select_set(em->bm, l->e->v2, true); @@ -465,10 +471,12 @@ void uvedit_edge_select_disable(BMEditMesh *em, ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) { - if (ts->selectmode & SCE_SELECT_FACE) + if (ts->selectmode & SCE_SELECT_FACE) { BM_face_select_set(em->bm, l->f, false); - else if (ts->selectmode & SCE_SELECT_EDGE) + } + else if (ts->selectmode & SCE_SELECT_EDGE) { BM_edge_select_set(em->bm, l->e, false); + } else { BM_vert_select_set(em->bm, l->e->v1, false); BM_vert_select_set(em->bm, l->e->v2, false); @@ -488,10 +496,12 @@ void uvedit_edge_select_disable(BMEditMesh *em, bool uvedit_uv_select_test_ex(const ToolSettings *ts, BMLoop *l, const int cd_loop_uv_offset) { if (ts->uv_flag & UV_SYNC_SELECTION) { - if (ts->selectmode & SCE_SELECT_FACE) + if (ts->selectmode & SCE_SELECT_FACE) { return BM_elem_flag_test_bool(l->f, BM_ELEM_SELECT); - else + } + else { return BM_elem_flag_test_bool(l->v, BM_ELEM_SELECT); + } } else { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -524,10 +534,12 @@ void uvedit_uv_select_enable( ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) { - if (ts->selectmode & SCE_SELECT_FACE) + if (ts->selectmode & SCE_SELECT_FACE) { BM_face_select_set(em->bm, l->f, true); - else + } + else { BM_vert_select_set(em->bm, l->v, true); + } if (do_history) { BM_select_history_remove(em->bm, (BMElem *)l->v); @@ -544,10 +556,12 @@ void uvedit_uv_select_disable(BMEditMesh *em, Scene *scene, BMLoop *l, const int ToolSettings *ts = scene->toolsettings; if (ts->uv_flag & UV_SYNC_SELECTION) { - if (ts->selectmode & SCE_SELECT_FACE) + if (ts->selectmode & SCE_SELECT_FACE) { BM_face_select_set(em->bm, l->f, false); - else + } + else { BM_vert_select_set(em->bm, l->v, false); + } } else { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -623,8 +637,9 @@ bool ED_uvedit_minmax_multi(Scene *scene, const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { @@ -679,8 +694,9 @@ static bool ED_uvedit_median_multi( const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -756,8 +772,7 @@ bool uv_find_nearest_edge( if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; } - BM_ITER_ELEM_INDEX(l, &liter, efa, BM_LOOPS_OF_FACE, i) - { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); luv_next = BM_ELEM_CD_GET_VOID_P(l->next, cd_loop_uv_offset); @@ -901,8 +916,7 @@ bool uv_find_nearest_vert(Scene *scene, BMIter liter; BMLoop *l; int i; - BM_ITER_ELEM_INDEX(l, &liter, efa, BM_LOOPS_OF_FACE, i) - { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { float dist_test_sq; MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); if (penalty_dist != 0.0f && uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { @@ -1024,14 +1038,16 @@ static void uv_select_edgeloop_vertex_loop_flag(UvMapVert *first) int count = 0; for (iterv = first; iterv; iterv = iterv->next) { - if (iterv->separate && iterv != first) + if (iterv->separate && iterv != first) { break; + } count++; } - if (count < 5) + if (count < 5) { first->flag = 1; + } } static UvMapVert *uv_select_edgeloop_vertex_map_get(UvVertMap *vmap, BMFace *efa, BMLoop *l) @@ -1040,10 +1056,12 @@ static UvMapVert *uv_select_edgeloop_vertex_map_get(UvVertMap *vmap, BMFace *efa first = BM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v)); for (iterv = first; iterv; iterv = iterv->next) { - if (iterv->separate) + if (iterv->separate) { first = iterv; - if (iterv->poly_index == BM_elem_index_get(efa)) + } + if (iterv->poly_index == BM_elem_index_get(efa)) { return first; + } } return NULL; @@ -1060,18 +1078,21 @@ static bool uv_select_edgeloop_edge_tag_faces(BMEditMesh *em, /* count number of faces this edge has */ for (iterv1 = first1; iterv1; iterv1 = iterv1->next) { - if (iterv1->separate && iterv1 != first1) + if (iterv1->separate && iterv1 != first1) { break; + } for (iterv2 = first2; iterv2; iterv2 = iterv2->next) { - if (iterv2->separate && iterv2 != first2) + if (iterv2->separate && iterv2 != first2) { break; + } if (iterv1->poly_index == iterv2->poly_index) { /* if face already tagged, don't do this edge */ efa = BM_face_at_index(em->bm, iterv1->poly_index); - if (BM_elem_flag_test(efa, BM_ELEM_TAG)) + if (BM_elem_flag_test(efa, BM_ELEM_TAG)) { return false; + } tot++; break; @@ -1079,19 +1100,23 @@ static bool uv_select_edgeloop_edge_tag_faces(BMEditMesh *em, } } - if (*totface == 0) /* start edge */ + if (*totface == 0) { /* start edge */ *totface = tot; - else if (tot != *totface) /* check for same number of faces as start edge */ + } + else if (tot != *totface) { /* check for same number of faces as start edge */ return false; + } /* tag the faces */ for (iterv1 = first1; iterv1; iterv1 = iterv1->next) { - if (iterv1->separate && iterv1 != first1) + if (iterv1->separate && iterv1 != first1) { break; + } for (iterv2 = first2; iterv2; iterv2 = iterv2->next) { - if (iterv2->separate && iterv2 != first2) + if (iterv2->separate && iterv2 != first2) { break; + } if (iterv1->poly_index == iterv2->poly_index) { efa = BM_face_at_index(em->bm, iterv1->poly_index); @@ -1158,10 +1183,12 @@ static int uv_select_edgeloop(Scene *scene, uvedit_face_visible_test(scene, obedit, ima, efa)) { BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { /* check face not hidden and not tagged */ - if (!(iterv_curr = uv_select_edgeloop_vertex_map_get(vmap, efa, l))) + if (!(iterv_curr = uv_select_edgeloop_vertex_map_get(vmap, efa, l))) { continue; - if (!(iterv_next = uv_select_edgeloop_vertex_map_get(vmap, efa, l->next))) + } + if (!(iterv_next = uv_select_edgeloop_vertex_map_get(vmap, efa, l->next))) { continue; + } /* check if vertex is tagged and has right valence */ if (iterv_curr->flag || iterv_next->flag) { @@ -1255,8 +1282,9 @@ static void uv_select_linked_multi(Scene *scene, * keeping island-select working as is. */ vmap = BM_uv_vert_map_create(em->bm, limit, !select_faces, false); - if (vmap == NULL) + if (vmap == NULL) { return; + } stack = MEM_mallocN(sizeof(*stack) * (em->bm->totface + 1), "UvLinkStack"); flag = MEM_callocN(sizeof(*flag) * em->bm->totface, "UvLinkFlag"); @@ -1306,8 +1334,7 @@ static void uv_select_linked_multi(Scene *scene, efa = BM_face_at_index(em->bm, a); - BM_ITER_ELEM_INDEX(l, &liter, efa, BM_LOOPS_OF_FACE, i) - { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { /* make_uv_vert_map_EM sets verts tmp.l to the indices */ vlist = BM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v)); @@ -1315,15 +1342,18 @@ static void uv_select_linked_multi(Scene *scene, startv = vlist; for (iterv = vlist; iterv; iterv = iterv->next) { - if (iterv->separate) + if (iterv->separate) { startv = iterv; - if (iterv->poly_index == a) + } + if (iterv->poly_index == a) { break; + } } for (iterv = startv; iterv; iterv = iterv->next) { - if ((startv != iterv) && (iterv->separate)) + if ((startv != iterv) && (iterv->separate)) { break; + } else if (!flag[iterv->poly_index]) { flag[iterv->poly_index] = 1; stack[stacksize] = iterv->poly_index; @@ -1410,8 +1440,9 @@ static float *uv_sel_co_from_eve( const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); BM_ITER_ELEM (l, &liter, eve, BM_LOOPS_OF_VERT) { - if (!uvedit_face_visible_test(scene, obedit, ima, l->f)) + if (!uvedit_face_visible_test(scene, obedit, ima, l->f)) { continue; + } if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1623,8 +1654,9 @@ static void uv_weld_align(bContext *C, eUVWeldAlign tool) BMLoop *l; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { @@ -1656,8 +1688,9 @@ static void uv_weld_align(bContext *C, eUVWeldAlign tool) BMLoop *l; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { @@ -1675,8 +1708,9 @@ static void uv_weld_align(bContext *C, eUVWeldAlign tool) BMLoop *l; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { @@ -1701,8 +1735,9 @@ static void uv_weld_align(bContext *C, eUVWeldAlign tool) /* tag verts with a selected UV */ BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { BM_ITER_ELEM (l, &liter, eve, BM_LOOPS_OF_VERT) { - if (!uvedit_face_visible_test(scene, obedit, ima, l->f)) + if (!uvedit_face_visible_test(scene, obedit, ima, l->f)) { continue; + } if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { BM_elem_flag_enable(eve, BM_ELEM_TAG); @@ -1778,23 +1813,28 @@ static void uv_weld_align(bContext *C, eUVWeldAlign tool) eUVWeldAlign tool_local = tool; if (tool_local == UV_STRAIGHTEN_X) { - if (uv_start[1] == uv_end[1]) + if (uv_start[1] == uv_end[1]) { tool_local = UV_STRAIGHTEN; - else + } + else { a = (uv_end[0] - uv_start[0]) / (uv_end[1] - uv_start[1]); + } } else if (tool_local == UV_STRAIGHTEN_Y) { - if (uv_start[0] == uv_end[0]) + if (uv_start[0] == uv_end[0]) { tool_local = UV_STRAIGHTEN; - else + } + else { a = (uv_end[1] - uv_start[1]) / (uv_end[0] - uv_start[0]); + } } /* go over all verts except for endpoints */ for (i = 0; i < BLI_array_len(eve_line); i++) { BM_ITER_ELEM (l, &liter, eve_line[i], BM_LOOPS_OF_VERT) { - if (!uvedit_face_visible_test(scene, obedit, ima, l->f)) + if (!uvedit_face_visible_test(scene, obedit, ima, l->f)) { continue; + } if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1802,12 +1842,15 @@ static void uv_weld_align(bContext *C, eUVWeldAlign tool) * new_y = (y2 - y1) / (x2 - x1) * (x - x1) + y1 * Maybe this should be a BLI func? Or is it already existing? * Could use interp_v2_v2v2, but not sure it's worth it here...*/ - if (tool_local == UV_STRAIGHTEN_X) + if (tool_local == UV_STRAIGHTEN_X) { luv->uv[0] = a * (luv->uv[1] - uv_start[1]) + uv_start[0]; - else if (tool_local == UV_STRAIGHTEN_Y) + } + else if (tool_local == UV_STRAIGHTEN_Y) { luv->uv[1] = a * (luv->uv[0] - uv_start[0]) + uv_start[1]; - else + } + else { closest_to_line_segment_v2(luv->uv, luv->uv, uv_start, uv_end); + } changed = true; } } @@ -2160,7 +2203,7 @@ static int uv_remove_doubles_exec(bContext *C, wmOperator *op) static void UV_OT_remove_doubles(wmOperatorType *ot) { /* identifiers */ - ot->name = "Remove Doubles UV"; + ot->name = "Merge UVs by Distance"; ot->description = "Selected UV vertices that are within a radius of each other are welded together"; ot->idname = "UV_OT_remove_doubles"; @@ -2294,8 +2337,9 @@ static void uv_select_all_perform(Scene *scene, Image *ima, Object *obedit, int } else { BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -2384,25 +2428,33 @@ static bool uv_sticky_select( /* this function test if some vertex needs to selected * in addition to the existing ones due to sticky select */ - if (sticky == SI_STICKY_DISABLE) + if (sticky == SI_STICKY_DISABLE) { return false; + } for (i = 0; i < hitlen; i++) { if (hitv[i] == v) { if (sticky == SI_STICKY_LOC) { - if (fabsf(hituv[i][0] - uv[0]) < limit[0] && fabsf(hituv[i][1] - uv[1]) < limit[1]) + if (fabsf(hituv[i][0] - uv[0]) < limit[0] && fabsf(hituv[i][1] - uv[1]) < limit[1]) { return true; + } } - else if (sticky == SI_STICKY_VERTEX) + else if (sticky == SI_STICKY_VERTEX) { return true; + } } } return false; } -static int uv_mouse_select_multi( - bContext *C, Object **objects, uint objects_len, const float co[2], bool extend, bool loop) +static int uv_mouse_select_multi(bContext *C, + Object **objects, + uint objects_len, + const float co[2], + const bool extend, + const bool deselect_all, + const bool loop) { Depsgraph *depsgraph = CTX_data_depsgraph(C); SpaceImage *sima = CTX_wm_space_image(C); @@ -2416,6 +2468,7 @@ static int uv_mouse_select_multi( UvNearestHit hit = UV_NEAREST_HIT_INIT; int i, selectmode, sticky, sync, *hitv = NULL; bool select = true; + bool found_item = false; /* 0 == don't flush, 1 == sel, -1 == desel; only use when selection sync is enabled */ int flush = 0; int hitlen = 0; @@ -2439,12 +2492,15 @@ static int uv_mouse_select_multi( if (ts->uv_flag & UV_SYNC_SELECTION) { sync = 1; - if (ts->selectmode & SCE_SELECT_FACE) + if (ts->selectmode & SCE_SELECT_FACE) { selectmode = UV_SELECT_FACE; - else if (ts->selectmode & SCE_SELECT_EDGE) + } + else if (ts->selectmode & SCE_SELECT_EDGE) { selectmode = UV_SELECT_EDGE; - else + } + else { selectmode = UV_SELECT_VERTEX; + } sticky = SI_STICKY_DISABLE; } @@ -2457,80 +2513,86 @@ static int uv_mouse_select_multi( /* find nearest element */ if (loop) { /* find edge */ - if (!uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit)) { - return OPERATOR_CANCELLED; - } - - hitlen = 0; + found_item = uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit); } else if (selectmode == UV_SELECT_VERTEX) { /* find vertex */ - if (!uv_find_nearest_vert_multi(scene, ima, objects, objects_len, co, penalty_dist, &hit)) { - return OPERATOR_CANCELLED; - } + found_item = uv_find_nearest_vert_multi( + scene, ima, objects, objects_len, co, penalty_dist, &hit); + found_item = found_item && (!deselect_all || hit.dist_sq < penalty_dist); - /* mark 1 vertex as being hit */ - hitv = BLI_array_alloca(hitv, hit.efa->len); - hituv = BLI_array_alloca(hituv, hit.efa->len); - copy_vn_i(hitv, hit.efa->len, 0xFFFFFFFF); + if (found_item) { + /* mark 1 vertex as being hit */ + hitv = BLI_array_alloca(hitv, hit.efa->len); + hituv = BLI_array_alloca(hituv, hit.efa->len); + copy_vn_i(hitv, hit.efa->len, 0xFFFFFFFF); - hitv[hit.lindex] = BM_elem_index_get(hit.l->v); - hituv[hit.lindex] = hit.luv->uv; + hitv[hit.lindex] = BM_elem_index_get(hit.l->v); + hituv[hit.lindex] = hit.luv->uv; - hitlen = hit.efa->len; + hitlen = hit.efa->len; + } } else if (selectmode == UV_SELECT_EDGE) { /* find edge */ - if (!uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit)) { - return OPERATOR_CANCELLED; - } + found_item = uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit); + found_item = found_item && (!deselect_all || hit.dist_sq < penalty_dist); - /* mark 2 edge vertices as being hit */ - hitv = BLI_array_alloca(hitv, hit.efa->len); - hituv = BLI_array_alloca(hituv, hit.efa->len); - copy_vn_i(hitv, hit.efa->len, 0xFFFFFFFF); + if (found_item) { + /* mark 2 edge vertices as being hit */ + hitv = BLI_array_alloca(hitv, hit.efa->len); + hituv = BLI_array_alloca(hituv, hit.efa->len); + copy_vn_i(hitv, hit.efa->len, 0xFFFFFFFF); - hitv[hit.lindex] = BM_elem_index_get(hit.l->v); - hitv[(hit.lindex + 1) % hit.efa->len] = BM_elem_index_get(hit.l->next->v); - hituv[hit.lindex] = hit.luv->uv; - hituv[(hit.lindex + 1) % hit.efa->len] = hit.luv_next->uv; + hitv[hit.lindex] = BM_elem_index_get(hit.l->v); + hitv[(hit.lindex + 1) % hit.efa->len] = BM_elem_index_get(hit.l->next->v); + hituv[hit.lindex] = hit.luv->uv; + hituv[(hit.lindex + 1) % hit.efa->len] = hit.luv_next->uv; - hitlen = hit.efa->len; + hitlen = hit.efa->len; + } } else if (selectmode == UV_SELECT_FACE) { /* find face */ - if (!uv_find_nearest_face_multi(scene, ima, objects, objects_len, co, &hit)) { - return OPERATOR_CANCELLED; - } + found_item = uv_find_nearest_face_multi(scene, ima, objects, objects_len, co, &hit); + found_item = found_item && (!deselect_all || hit.dist_sq < penalty_dist); - BMEditMesh *em = BKE_editmesh_from_object(hit.ob); - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + if (found_item) { + BMEditMesh *em = BKE_editmesh_from_object(hit.ob); + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); - /* make active */ - BM_mesh_active_face_set(em->bm, hit.efa); + /* make active */ + BM_mesh_active_face_set(em->bm, hit.efa); - /* mark all face vertices as being hit */ + /* mark all face vertices as being hit */ - hitv = BLI_array_alloca(hitv, hit.efa->len); - hituv = BLI_array_alloca(hituv, hit.efa->len); - BM_ITER_ELEM_INDEX(l, &liter, hit.efa, BM_LOOPS_OF_FACE, i) - { - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - hituv[i] = luv->uv; - hitv[i] = BM_elem_index_get(l->v); - } + hitv = BLI_array_alloca(hitv, hit.efa->len); + hituv = BLI_array_alloca(hituv, hit.efa->len); + BM_ITER_ELEM_INDEX (l, &liter, hit.efa, BM_LOOPS_OF_FACE, i) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + hituv[i] = luv->uv; + hitv[i] = BM_elem_index_get(l->v); + } - hitlen = hit.efa->len; + hitlen = hit.efa->len; + } } else if (selectmode == UV_SELECT_ISLAND) { - if (!uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit)) { - return OPERATOR_CANCELLED; - } - - hitlen = 0; + found_item = uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit); + found_item = found_item && (!deselect_all || hit.dist_sq < penalty_dist); } - else { - hitlen = 0; + + if (!found_item) { + if (deselect_all) { + uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT); + + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + uv_select_tag_update_for_object(depsgraph, ts, obedit); + } + + return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED; + } return OPERATOR_CANCELLED; } @@ -2589,14 +2651,16 @@ static int uv_mouse_select_multi( BM_mesh_elem_index_ensure(em->bm, BM_VERT); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); if (uv_sticky_select( - limit, hitv, BM_elem_index_get(l->v), hituv, luv->uv, sticky, hitlen)) + limit, hitv, BM_elem_index_get(l->v), hituv, luv->uv, sticky, hitlen)) { uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); + } } } @@ -2625,17 +2689,20 @@ static int uv_mouse_select_multi( /* select sticky uvs */ if (sticky != SI_STICKY_DISABLE) { BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (sticky == SI_STICKY_DISABLE) + if (sticky == SI_STICKY_DISABLE) { continue; + } luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); if (uv_sticky_select( - limit, hitv, BM_elem_index_get(l->v), hituv, luv->uv, sticky, hitlen)) + limit, hitv, BM_elem_index_get(l->v), hituv, luv->uv, sticky, hitlen)) { uvedit_uv_select_enable(em, scene, l, false, cd_loop_uv_offset); + } flush = 1; } @@ -2649,8 +2716,10 @@ static int uv_mouse_select_multi( /* before bmesh */ #if 0 if (ts->selectmode != SCE_SELECT_FACE) { - if (flush == 1) EDBM_select_flush(em); - else if (flush == -1) EDBM_deselect_flush(em); + if (flush == 1) + EDBM_select_flush(em); + else if (flush == -1) + EDBM_deselect_flush(em); } #else if (flush != 0) { @@ -2677,13 +2746,14 @@ static int uv_mouse_select_multi( return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED; } -static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loop) +static int uv_mouse_select( + bContext *C, const float co[2], const bool extend, const bool deselect_all, const bool loop) { ViewLayer *view_layer = CTX_data_view_layer(C); uint objects_len = 0; Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs( view_layer, ((View3D *)NULL), &objects_len); - int ret = uv_mouse_select_multi(C, objects, objects_len, co, extend, loop); + int ret = uv_mouse_select_multi(C, objects, objects_len, co, extend, deselect_all, loop); MEM_freeN(objects); return ret; } @@ -2691,13 +2761,13 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo static int uv_select_exec(bContext *C, wmOperator *op) { float co[2]; - bool extend, loop; RNA_float_get_array(op->ptr, "location", co); - extend = RNA_boolean_get(op->ptr, "extend"); - loop = false; + const bool extend = RNA_boolean_get(op->ptr, "extend"); + const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all"); + const bool loop = false; - return uv_mouse_select(C, co, extend, loop); + return uv_mouse_select(C, co, extend, deselect_all, loop); } static int uv_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) @@ -2725,11 +2795,19 @@ static void UV_OT_select(wmOperatorType *ot) ot->poll = ED_operator_uvedit; /* requires space image */ /* properties */ + PropertyRNA *prop; RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection rather than clearing the existing selection"); + prop = RNA_def_boolean(ot->srna, + "deselect_all", + false, + "Deselect On Nothing", + "Deselect all when nothing under the cursor"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + RNA_def_float_vector( ot->srna, "location", @@ -2752,13 +2830,13 @@ static void UV_OT_select(wmOperatorType *ot) static int uv_select_loop_exec(bContext *C, wmOperator *op) { float co[2]; - bool extend, loop; RNA_float_get_array(op->ptr, "location", co); - extend = RNA_boolean_get(op->ptr, "extend"); - loop = true; + const bool extend = RNA_boolean_get(op->ptr, "extend"); + const bool deselect_all = false; + const bool loop = true; - return uv_mouse_select(C, co, extend, loop); + return uv_mouse_select(C, co, extend, deselect_all, loop); } static int uv_select_loop_invoke(bContext *C, wmOperator *op, const wmEvent *event) @@ -2810,7 +2888,7 @@ static void UV_OT_select_loop(wmOperatorType *ot) /** \name Select Linked Operator * \{ */ -static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent *event, int pick) +static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent *event, bool pick) { SpaceImage *sima = CTX_wm_space_image(C); Scene *scene = CTX_data_scene(C); @@ -2897,7 +2975,7 @@ static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent static int uv_select_linked_exec(bContext *C, wmOperator *op) { - return uv_select_linked_internal(C, op, NULL, 0); + return uv_select_linked_internal(C, op, NULL, false); } static void UV_OT_select_linked(wmOperatorType *ot) @@ -2911,6 +2989,9 @@ static void UV_OT_select_linked(wmOperatorType *ot) /* api callbacks */ ot->exec = uv_select_linked_exec; ot->poll = ED_operator_uvedit; /* requires space image */ + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /** \} */ @@ -2921,12 +3002,12 @@ static void UV_OT_select_linked(wmOperatorType *ot) static int uv_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - return uv_select_linked_internal(C, op, event, 1); + return uv_select_linked_internal(C, op, event, true); } static int uv_select_linked_pick_exec(bContext *C, wmOperator *op) { - return uv_select_linked_internal(C, op, NULL, 1); + return uv_select_linked_internal(C, op, NULL, true); } static void UV_OT_select_linked_pick(wmOperatorType *ot) @@ -2935,7 +3016,9 @@ static void UV_OT_select_linked_pick(wmOperatorType *ot) ot->name = "Select Linked Pick"; ot->description = "Select all UV vertices linked under the mouse"; ot->idname = "UV_OT_select_linked_pick"; - ot->flag = OPTYPE_UNDO; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* api callbacks */ ot->invoke = uv_select_linked_pick_invoke; @@ -2975,8 +3058,8 @@ static void UV_OT_select_linked_pick(wmOperatorType *ot) /** * \note This is based on similar use case to #MESH_OT_split(), which has a similar effect * but in this case they are not joined to begin with (only having the behavior of being joined) - * so its best to call this #uv_select_split() instead of just split(), but assigned to the same key - * as #MESH_OT_split - Campbell. + * so its best to call this #uv_select_split() instead of just split(), but assigned to the same + * key as #MESH_OT_split - Campbell. */ static int uv_select_split_exec(bContext *C, wmOperator *op) { @@ -3129,11 +3212,13 @@ static void uv_select_flush_from_tag_sticky_loc_internal(Scene *scene, vlist_iter = BM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v)); while (vlist_iter) { - if (vlist_iter->separate) + if (vlist_iter->separate) { start_vlist = vlist_iter; + } - if (efa_index == vlist_iter->poly_index) + if (efa_index == vlist_iter->poly_index) { break; + } vlist_iter = vlist_iter->next; } @@ -3141,8 +3226,9 @@ static void uv_select_flush_from_tag_sticky_loc_internal(Scene *scene, vlist_iter = start_vlist; while (vlist_iter) { - if (vlist_iter != start_vlist && vlist_iter->separate) + if (vlist_iter != start_vlist && vlist_iter->separate) { break; + } if (efa_index != vlist_iter->poly_index) { BMLoop *l_other; @@ -3161,10 +3247,12 @@ static void uv_select_flush_from_tag_sticky_loc_internal(Scene *scene, /** * Flush the selection from face tags based on sticky and selection modes. * - * needed because settings the selection a face is done in a number of places but it also needs to respect - * the sticky modes for the UV verts, so dealing with the sticky modes is best done in a separate function. + * needed because settings the selection a face is done in a number of places but it also + * needs to respect the sticky modes for the UV verts, so dealing with the sticky modes + * is best done in a separate function. * - * \note! This function is very similar to #uv_select_flush_from_tag_loop, be sure to update both upon changing. + * \note This function is very similar to #uv_select_flush_from_tag_loop, + * be sure to update both upon changing. */ static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, @@ -3245,10 +3333,12 @@ static void uv_select_flush_from_tag_face(SpaceImage *sima, /** * Flush the selection from loop tags based on sticky and selection modes. * - * needed because settings the selection a face is done in a number of places but it also needs to respect - * the sticky modes for the UV verts, so dealing with the sticky modes is best done in a separate function. + * needed because settings the selection a face is done in a number of places but it also needs + * to respect the sticky modes for the UV verts, so dealing with the sticky modes is best done + * in a separate function. * - * \note! This function is very similar to #uv_select_flush_from_tag_loop, be sure to update both upon changing. + * \note This function is very similar to #uv_select_flush_from_tag_loop, + * be sure to update both upon changing. */ static void uv_select_flush_from_tag_loop(SpaceImage *sima, Scene *scene, @@ -3413,8 +3503,9 @@ static int uv_box_select_exec(bContext *C, wmOperator *op) BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT, BM_ELEM_TAG, false); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -3824,8 +3915,9 @@ static int uv_snap_cursor_exec(bContext *C, wmOperator *op) } } - if (!changed) + if (!changed) { return OPERATOR_CANCELLED; + } WM_event_add_notifier(C, NC_SPACE | ND_SPACE_IMAGE, sima); @@ -3873,8 +3965,9 @@ static bool uv_snap_uvs_to_cursor(Scene *scene, Image *ima, Object *obedit, cons const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { @@ -3900,8 +3993,9 @@ static bool uv_snap_uvs_offset(Scene *scene, Image *ima, Object *obedit, const f const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { @@ -3989,8 +4083,9 @@ static bool uv_snap_uvs_to_pixels(SpaceImage *sima, Scene *scene, Object *obedit h = (float)height; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { @@ -4327,8 +4422,9 @@ static int uv_hide_exec(bContext *C, wmOperator *op) } } } - if (!swap) + if (!swap) { uvedit_face_select_disable(scene, em, efa, cd_loop_uv_offset); + } } } else if (em->selectmode == SCE_SELECT_FACE) { @@ -4343,8 +4439,9 @@ static int uv_hide_exec(bContext *C, wmOperator *op) luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); if (UV_SEL_TEST(luv, !swap)) { BM_vert_select_set(em->bm, l->v, false); - if (!swap) + if (!swap) { luv->flag &= ~MLOOPUV_VERTSEL; + } } } } @@ -4352,8 +4449,9 @@ static int uv_hide_exec(bContext *C, wmOperator *op) } /* flush vertex selection changes */ - if (em->selectmode != SCE_SELECT_FACE) + if (em->selectmode != SCE_SELECT_FACE) { EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX | SCE_SELECT_EDGE); + } BM_select_history_validate(em->bm); @@ -4537,8 +4635,9 @@ static int uv_set_2d_cursor_exec(bContext *C, wmOperator *op) { SpaceImage *sima = CTX_wm_space_image(C); - if (!sima) + if (!sima) { return OPERATOR_CANCELLED; + } RNA_float_get_array(op->ptr, "location", sima->cursor); @@ -4648,20 +4747,23 @@ static int uv_seams_from_islands_exec(bContext *C, wmOperator *op) UvMapVert *mv2cache = NULL, *mv2sep = NULL; mvinit1 = vmap->vert[BM_elem_index_get(editedge->v1)]; - if (mark_seams) + if (mark_seams) { BM_elem_flag_disable(editedge, BM_ELEM_SEAM); + } for (mv1 = mvinit1; mv1 && !faces_separated; mv1 = mv1->next) { - if (mv1->separate && commonFaces) + if (mv1->separate && commonFaces) { v1coincident = 0; + } separated2 = 0; efa1 = BM_face_at_index(bm, mv1->poly_index); mvinit2 = vmap->vert[BM_elem_index_get(editedge->v2)]; for (mv2 = mvinit2; mv2; mv2 = mv2->next) { - if (mv2->separate) + if (mv2->separate) { mv2sep = mv2; + } efa2 = BM_face_at_index(bm, mv2->poly_index); if (efa1 == efa2) { @@ -4672,11 +4774,13 @@ static int uv_seams_from_islands_exec(bContext *C, wmOperator *op) /* flag seam unless proved to be coincident with previous hit */ separated2 = 1; for (mviter = mv2cache; mviter; mviter = mviter->next) { - if (mviter->separate && mviter != mv2cache) + if (mviter->separate && mviter != mv2cache) { break; + } /* coincident with previous hit, do not flag seam */ - if (mviter == mv2) + if (mviter == mv2) { separated2 = 0; + } } } /* First hit case, store the hit in the cache */ @@ -4685,8 +4789,9 @@ static int uv_seams_from_islands_exec(bContext *C, wmOperator *op) commonFaces = 1; } } - else + else { separated1 = 1; + } if (separated1 || separated2) { faces_separated = 1; @@ -4697,10 +4802,12 @@ static int uv_seams_from_islands_exec(bContext *C, wmOperator *op) } if (faces_separated) { - if (mark_seams) + if (mark_seams) { BM_elem_flag_enable(editedge, BM_ELEM_SEAM); - if (mark_sharp) + } + if (mark_sharp) { BM_elem_flag_disable(editedge, BM_ELEM_SMOOTH); + } } } @@ -4897,7 +5004,7 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf) wmKeyMap *keymap; keymap = WM_keymap_ensure(keyconf, "UV Editor", 0, 0); - keymap->poll = ED_operator_uvedit_can_uv_sculpt; + keymap->poll = ED_operator_uvedit; } /** \} */ diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c index 69183d02ab9..10b2df48f2f 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.c +++ b/source/blender/editors/uvedit/uvedit_parametrizer.c @@ -255,8 +255,9 @@ static PHash *phash_new(PHashLink **list, int sizehint) ph->cursize_id = 0; ph->list = list; - while (PHashSizes[ph->cursize_id] < sizehint) + while (PHashSizes[ph->cursize_id] < sizehint) { ph->cursize_id++; + } ph->cursize = PHashSizes[ph->cursize_id]; ph->buckets = (PHashLink **)MEM_callocN(ph->cursize * sizeof(*ph->buckets), "PHashBuckets"); @@ -316,11 +317,14 @@ static PHashLink *phash_lookup(PHash *ph, PHashKey key) PHashLink *link; uintptr_t hash = PHASH_hash(ph, key); - for (link = ph->buckets[hash]; link; link = link->next) - if (link->key == key) + for (link = ph->buckets[hash]; link; link = link->next) { + if (link->key == key) { return link; - else if (PHASH_hash(ph, link->key) != hash) + } + else if (PHASH_hash(ph, link->key) != hash) { return NULL; + } + } return link; } @@ -329,11 +333,14 @@ static PHashLink *phash_next(PHash *ph, PHashKey key, PHashLink *link) { uintptr_t hash = PHASH_hash(ph, key); - for (link = link->next; link; link = link->next) - if (link->key == key) + for (link = link->next; link; link = link->next) { + if (link->key == key) { return link; - else if (PHASH_hash(ph, link->key) != hash) + } + else if (PHASH_hash(ph, link->key) != hash) { return NULL; + } + } return link; } @@ -362,12 +369,15 @@ static float p_vec_angle(float *v1, float *v2, float *v3) { float dot = p_vec_angle_cos(v1, v2, v3); - if (dot <= -1.0f) + if (dot <= -1.0f) { return (float)M_PI; - else if (dot >= 1.0f) + } + else if (dot >= 1.0f) { return 0.0f; - else + } + else { return acosf(dot); + } } static float p_vec2_angle(float *v1, float *v2, float *v3) @@ -523,8 +533,9 @@ static PBool p_intersect_line_2d_dir(float *v1, float *dir1, float *v2, float *d div = dir2[0] * dir1[1] - dir2[1] * dir1[0]; - if (div == 0.0f) + if (div == 0.0f) { return P_FALSE; + } lmbda = ((v1[1] - v2[1]) * dir1[0] - (v1[0] - v2[0]) * dir1[1]) / div; isect[0] = v1[0] + lmbda * dir2[0]; @@ -645,8 +656,9 @@ static void p_vert_load_pin_select_uvs(PHandle *handle, PVert *v) e = v->edge; do { if (e->orig_uv) { - if (e->flag & PEDGE_SELECT) + if (e->flag & PEDGE_SELECT) { v->flag |= PVERT_SELECT; + } if (e->flag & PEDGE_PIN) { pinuv[0] += e->orig_uv[0] * handle->aspx; @@ -765,10 +777,12 @@ static PVert *p_vert_lookup(PHandle *handle, PHashKey key, const float co[3], PE { PVert *v = (PVert *)phash_lookup(handle->hash_verts, key); - if (v) + if (v) { return v; - else + } + else { return p_vert_add(handle, key, co, e); + } } static PVert *p_vert_copy(PChart *chart, PVert *v) @@ -791,10 +805,12 @@ static PEdge *p_edge_lookup(PHandle *handle, PHashKey *vkeys) PEdge *e = (PEdge *)phash_lookup(handle->hash_edges, key); while (e) { - if ((e->vert->u.key == vkeys[0]) && (e->next->vert->u.key == vkeys[1])) + if ((e->vert->u.key == vkeys[0]) && (e->next->vert->u.key == vkeys[1])) { return e; - else if ((e->vert->u.key == vkeys[1]) && (e->next->vert->u.key == vkeys[0])) + } + else if ((e->vert->u.key == vkeys[1]) && (e->next->vert->u.key == vkeys[0])) { return e; + } e = (PEdge *)phash_next(handle->hash_edges, key, (PHashLink *)e); } @@ -811,12 +827,14 @@ static int p_face_exists(ParamHandle *phandle, ParamKey *pvkeys, int i1, int i2, while (e) { if ((e->vert->u.key == vkeys[i1]) && (e->next->vert->u.key == vkeys[i2])) { - if (e->next->next->vert->u.key == vkeys[i3]) + if (e->next->next->vert->u.key == vkeys[i3]) { return P_TRUE; + } } else if ((e->vert->u.key == vkeys[i2]) && (e->next->vert->u.key == vkeys[i1])) { - if (e->next->next->vert->u.key == vkeys[i3]) + if (e->next->next->vert->u.key == vkeys[i3]) { return P_TRUE; + } } e = (PEdge *)phash_next(handle->hash_edges, key, (PHashLink *)e); @@ -881,8 +899,9 @@ static PBool p_edge_has_pair(PHandle *handle, PEdge *e, PEdge **pair, PBool impl PHashKey key1 = e->vert->u.key; PHashKey key2 = e->next->vert->u.key; - if (e->flag & PEDGE_SEAM) + if (e->flag & PEDGE_SEAM) { return P_FALSE; + } key = PHASH_edge(key1, key2); pe = (PEdge *)phash_lookup(handle->hash_edges, key); @@ -925,8 +944,9 @@ static PBool p_edge_connect_pair(PHandle *handle, PEdge *e, PEdge ***stack, PBoo PEdge *pair = NULL; if (!e->pair && p_edge_has_pair(handle, e, &pair, impl)) { - if (e->vert == pair->vert) + if (e->vert == pair->vert) { p_face_flip(pair->face); + } e->pair = pair; pair->pair = e; @@ -952,8 +972,9 @@ static int p_connect_pairs(PHandle *handle, PBool impl) /* connect pairs, count edges, set vertex-edge pointer to a pairless edge */ for (first = chart->faces; first; first = first->nextlink) { - if (first->flag & PFACE_CONNECTED) + if (first->flag & PFACE_CONNECTED) { continue; + } *stack = first->edge; stack++; @@ -970,12 +991,15 @@ static int p_connect_pairs(PHandle *handle, PBool impl) /* assign verts to charts so we can sort them later */ f->u.chart = ncharts; - if (!p_edge_connect_pair(handle, e, &stack, impl)) + if (!p_edge_connect_pair(handle, e, &stack, impl)) { e->vert->edge = e; - if (!p_edge_connect_pair(handle, e1, &stack, impl)) + } + if (!p_edge_connect_pair(handle, e1, &stack, impl)) { e1->vert->edge = e1; - if (!p_edge_connect_pair(handle, e2, &stack, impl)) + } + if (!p_edge_connect_pair(handle, e2, &stack, impl)) { e2->vert->edge = e2; + } } ncharts++; @@ -996,18 +1020,21 @@ static void p_split_vert(PChart *chart, PEdge *e) chart->flag |= PCHART_HAS_PINS; } - if (e->flag & PEDGE_VERTEX_SPLIT) + if (e->flag & PEDGE_VERTEX_SPLIT) { return; + } /* rewind to start */ lastwe = e; - for (we = p_wheel_edge_prev(e); we && (we != e); we = p_wheel_edge_prev(we)) + for (we = p_wheel_edge_prev(e); we && (we != e); we = p_wheel_edge_prev(we)) { lastwe = we; + } /* go over all edges in wheel */ for (we = lastwe; we; we = p_wheel_edge_next(we)) { - if (we->flag & PEDGE_VERTEX_SPLIT) + if (we->flag & PEDGE_VERTEX_SPLIT) { break; + } we->flag |= PEDGE_VERTEX_SPLIT; @@ -1046,8 +1073,9 @@ static PChart **p_split_charts(PHandle *handle, PChart *chart, int ncharts) PFace *f, *nextf; int i; - for (i = 0; i < ncharts; i++) + for (i = 0; i < ncharts; i++) { charts[i] = p_chart_new(handle); + } f = chart->faces; while (f) { @@ -1133,21 +1161,27 @@ static PFace *p_face_add_construct(PHandle *handle, e3->orig_uv = uv[i3]; if (pin) { - if (pin[i1]) + if (pin[i1]) { e1->flag |= PEDGE_PIN; - if (pin[i2]) + } + if (pin[i2]) { e2->flag |= PEDGE_PIN; - if (pin[i3]) + } + if (pin[i3]) { e3->flag |= PEDGE_PIN; + } } if (select) { - if (select[i1]) + if (select[i1]) { e1->flag |= PEDGE_SELECT; - if (select[i2]) + } + if (select[i2]) { e2->flag |= PEDGE_SELECT; - if (select[i3]) + } + if (select[i3]) { e3->flag |= PEDGE_SELECT; + } } /* insert into hash */ @@ -1205,12 +1239,14 @@ static PBool p_quad_split_direction(PHandle *handle, float **co, PHashKey *vkeys * triangles, resulting in two identical triangles. for example in * suzanne's nose. */ if (dir) { - if (p_face_exists(handle, vkeys, 0, 1, 2) || p_face_exists(handle, vkeys, 0, 2, 3)) + if (p_face_exists(handle, vkeys, 0, 1, 2) || p_face_exists(handle, vkeys, 0, 2, 3)) { return !dir; + } } else { - if (p_face_exists(handle, vkeys, 0, 1, 3) || p_face_exists(handle, vkeys, 1, 2, 3)) + if (p_face_exists(handle, vkeys, 0, 1, 3) || p_face_exists(handle, vkeys, 1, 2, 3)) { return !dir; + } } return dir; @@ -1223,17 +1259,21 @@ static void p_chart_boundaries(PChart *chart, int *nboundaries, PEdge **outer) PEdge *e, *be; float len, maxlen = -1.0; - if (nboundaries) + if (nboundaries) { *nboundaries = 0; - if (outer) + } + if (outer) { *outer = NULL; + } for (e = chart->edges; e; e = e->nextlink) { - if (e->pair || (e->flag & PEDGE_DONE)) + if (e->pair || (e->flag & PEDGE_DONE)) { continue; + } - if (nboundaries) + if (nboundaries) { (*nboundaries)++; + } len = 0.0f; @@ -1250,8 +1290,9 @@ static void p_chart_boundaries(PChart *chart, int *nboundaries, PEdge **outer) } } - for (e = chart->edges; e; e = e->nextlink) + for (e = chart->edges; e; e = e->nextlink) { e->flag &= ~PEDGE_DONE; + } } static float p_edge_boundary_angle(PEdge *e) @@ -1364,8 +1405,9 @@ static void p_chart_fill_boundaries(PChart *chart, PEdge *outer) for (e = chart->edges; e; e = e->nextlink) { /* enext = e->nextlink; - as yet unused */ - if (e->pair || (e->flag & PEDGE_FILLED)) + if (e->pair || (e->flag & PEDGE_FILLED)) { continue; + } nedges = 0; be = e; @@ -1375,8 +1417,9 @@ static void p_chart_fill_boundaries(PChart *chart, PEdge *outer) nedges++; } while (be != e); - if (e != outer) + if (e != outer) { p_chart_fill_boundary(chart, e, nedges); + } } } @@ -1393,7 +1436,12 @@ static int p_polygon_point_in(float *cp1, float *cp2, float *p) return (p_area_signed(cp1, cp2, p) >= 0.0f); } -static void p_polygon_kernel_clip(float (*oldpoints)[2], int noldpoints, float (*newpoints)[2], int *nnewpoints, float *cp1, float *cp2) +static void p_polygon_kernel_clip(float (*oldpoints)[2], + int noldpoints, + float (*newpoints)[2], + int *nnewpoints, + float *cp1, + float *cp2) { float *p2, *p1, isect[2]; int i, p2in, p1in; @@ -1438,7 +1486,7 @@ static void p_polygon_kernel_clip(float (*oldpoints)[2], int noldpoints, float ( static void p_polygon_kernel_center(float (*points)[2], int npoints, float *center) { int i, size, nnewpoints = npoints; - float (*oldpoints)[2], (*newpoints)[2], *p1, *p2; + float(*oldpoints)[2], (*newpoints)[2], *p1, *p2; size = npoints * 3; oldpoints = MEM_mallocN(sizeof(float) * 2 * size, "PPolygonOldPoints"); @@ -1477,7 +1525,7 @@ static void p_polygon_kernel_center(float (*points)[2], int npoints, float *cent newpoints = MEM_mallocN(sizeof(float) * 2 * size, "newpoints"); } else { - float (*sw_points)[2] = oldpoints; + float(*sw_points)[2] = oldpoints; oldpoints = newpoints; newpoints = sw_points; } @@ -1616,7 +1664,7 @@ static void p_vert_harmonic_insert(PVert *v) * weights fails */ int npoints = 0, i; - float (*points)[2]; + float(*points)[2]; e = v->edge; do { @@ -1939,8 +1987,7 @@ static PBool p_collapse_allowed(PEdge *edge, PEdge *pair) if (oldv->flag & PVERT_PIN) return P_FALSE; - return (p_collapse_allowed_topologic(edge, pair) && - p_collapse_allowed_geometric(edge, pair)); + return (p_collapse_allowed_topologic(edge, pair) && p_collapse_allowed_geometric(edge, pair)); } static float p_collapse_cost(PEdge *edge, PEdge *pair) @@ -2346,8 +2393,9 @@ static void p_abf_setup_system(PAbfSystem *sys) sys->bstar = (float *)MEM_mallocN(sizeof(float) * sys->nfaces, "ABFbstar"); sys->dstar = (float *)MEM_mallocN(sizeof(float) * sys->nfaces, "ABFdstar"); - for (i = 0; i < sys->ninterior; i++) + for (i = 0; i < sys->ninterior; i++) { sys->lambdaLength[i] = 1.0; + } sys->minangle = 1.0 * M_PI / 180.0; sys->maxangle = (float)M_PI - sys->minangle; @@ -2400,16 +2448,18 @@ static float p_abf_compute_sin_product(PAbfSystem *sys, PVert *v, int aid) sin1 *= sys->cosine[e1->u.id]; sin2 = 0.0; } - else + else { sin1 *= sys->sine[e1->u.id]; + } if (aid == e2->u.id) { /* see above */ sin1 = 0.0; sin2 *= sys->cosine[e2->u.id]; } - else + else { sin2 *= sys->sine[e2->u.id]; + } e = e->next->next->pair; } while (e && (e != v->edge)); @@ -2500,8 +2550,9 @@ static PBool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart) context = EIG_linear_solver_new(0, nvar, 1); - for (i = 0; i < nvar; i++) + for (i = 0; i < nvar; i++) { EIG_linear_solver_right_hand_side_add(context, 0, i, sys->bInterior[i]); + } for (f = chart->faces; f; f = f->nextlink) { float wi1, wi2, wi3, b, si, beta[3], j2[3][3], W[3][3]; @@ -2611,29 +2662,37 @@ static PBool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart) for (i = 0; i < 3; i++) { int r = vid[i]; - if (r == -1) + if (r == -1) { continue; + } for (j = 0; j < 6; j++) { int c = vid[j]; - if (c == -1) + if (c == -1) { continue; + } - if (i == 0) + if (i == 0) { EIG_linear_solver_matrix_add(context, r, c, j2[0][i] * row1[j]); - else + } + else { EIG_linear_solver_matrix_add(context, r + ninterior, c, j2[0][i] * row1[j]); + } - if (i == 1) + if (i == 1) { EIG_linear_solver_matrix_add(context, r, c, j2[1][i] * row2[j]); - else + } + else { EIG_linear_solver_matrix_add(context, r + ninterior, c, j2[1][i] * row2[j]); + } - if (i == 2) + if (i == 2) { EIG_linear_solver_matrix_add(context, r, c, j2[2][i] * row3[j]); - else + } + else { EIG_linear_solver_matrix_add(context, r + ninterior, c, j2[2][i] * row3[j]); + } } } } @@ -2689,10 +2748,12 @@ static PBool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart) /* clamp */ e = f->edge; do { - if (sys->alpha[e->u.id] > (float)M_PI) + if (sys->alpha[e->u.id] > (float)M_PI) { sys->alpha[e->u.id] = (float)M_PI; - else if (sys->alpha[e->u.id] < 0.0f) + } + else if (sys->alpha[e->u.id] < 0.0f) { sys->alpha[e->u.id] = 0.0f; + } } while (e != f->edge); } @@ -2724,8 +2785,9 @@ static PBool p_chart_abf_solve(PChart *chart) v->flag |= PVERT_INTERIOR; v->u.id = sys.ninterior++; } - else + else { v->flag &= ~PVERT_INTERIOR; + } } for (f = chart->faces; f; f = f->nextlink) { @@ -2751,18 +2813,24 @@ static PBool p_chart_abf_solve(PChart *chart) e3 = e2->next; p_face_angles(f, &a1, &a2, &a3); - if (a1 < sys.minangle) + if (a1 < sys.minangle) { a1 = sys.minangle; - else if (a1 > sys.maxangle) + } + else if (a1 > sys.maxangle) { a1 = sys.maxangle; - if (a2 < sys.minangle) + } + if (a2 < sys.minangle) { a2 = sys.minangle; - else if (a2 > sys.maxangle) + } + else if (a2 > sys.maxangle) { a2 = sys.maxangle; - if (a3 < sys.minangle) + } + if (a3 < sys.minangle) { a3 = sys.minangle; - else if (a3 > sys.maxangle) + } + else if (a3 > sys.maxangle) { a3 = sys.maxangle; + } sys.alpha[e1->u.id] = sys.beta[e1->u.id] = a1; sys.alpha[e2->u.id] = sys.beta[e2->u.id] = a2; @@ -2804,8 +2872,9 @@ static PBool p_chart_abf_solve(PChart *chart) /* lastnorm = norm; */ /* UNUSED */ - if (norm < limit) + if (norm < limit) { break; + } if (!p_abf_matrix_invert(&sys, chart)) { param_warning("ABF failed to invert matrix"); @@ -2902,12 +2971,14 @@ static PBool p_chart_symmetry_pins(PChart *chart, PEdge *outer, PVert **pin1, PV if ((be->vert->flag & PVERT_SPLIT) || (lastbe->vert->flag & nextbe->vert->flag & PVERT_SPLIT)) { if (!cure) { - if (be == outer) + if (be == outer) { firste1 = be; + } cure = be; } - else + else { curlen += p_edge_length(lastbe); + } } else if (cure) { if (curlen > maxlen) { @@ -2940,8 +3011,9 @@ static PBool p_chart_symmetry_pins(PChart *chart, PEdge *outer, PVert **pin1, PV } } - if (!maxe1 || !maxe2 || (maxlen < 0.5f * totlen)) + if (!maxe1 || !maxe2 || (maxlen < 0.5f * totlen)) { return P_FALSE; + } /* find pin1 in the split vertices */ be1 = maxe1; @@ -3050,12 +3122,14 @@ static void p_chart_lscm_begin(PChart *chart, PBool live, PBool abf) for (v = chart->verts; v; v = v->nextlink) { if (v->flag & PVERT_PIN) { npins++; - if (v->flag & PVERT_SELECT) + if (v->flag & PVERT_SELECT) { select = P_TRUE; + } } - if (!(v->flag & PVERT_SELECT)) + if (!(v->flag & PVERT_SELECT)) { deselect = P_TRUE; + } } if ((live && (!select || !deselect)) || (npins == 1)) { @@ -3068,8 +3142,9 @@ static void p_chart_lscm_begin(PChart *chart, PBool live, PBool abf) #endif if (abf) { - if (!p_chart_abf_solve(chart)) + if (!p_chart_abf_solve(chart)) { param_warning("ABF solving failed: falling back to LSCM.\n"); + } } if (npins <= 1) { @@ -3087,8 +3162,9 @@ static void p_chart_lscm_begin(PChart *chart, PBool live, PBool abf) chart->u.lscm.pin2 = pin2; } - for (v = chart->verts; v; v = v->nextlink) + for (v = chart->verts; v; v = v->nextlink) { v->u.id = id++; + } chart->u.lscm.context = EIG_linear_least_squares_solver_new( 2 * chart->nfaces, 2 * chart->nverts, 1); @@ -3109,9 +3185,11 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart) /* TODO: make loading pins work for simplify/complexify. */ #endif - for (v = chart->verts; v; v = v->nextlink) - if (v->flag & PVERT_PIN) + for (v = chart->verts; v; v = v->nextlink) { + if (v->flag & PVERT_PIN) { p_vert_load_pin_select_uvs(handle, v); /* reload for live */ + } + } if (chart->u.lscm.pin1) { EIG_linear_solver_variable_lock(context, 2 * pin1->u.id); @@ -3148,10 +3226,12 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart) if ((v1->flag & PVERT_PIN) && (v2->flag & PVERT_PIN) && (v3->flag & PVERT_PIN)) { float area = p_face_uv_area_signed(f); - if (area > 0.0f) + if (area > 0.0f) { area_pinned_up += area; - else + } + else { area_pinned_down -= area; + } } } @@ -3172,8 +3252,9 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart) a2 = *(alpha++); a3 = *(alpha++); } - else + else { p_face_angles(f, &a1, &a2, &a3); + } if (flip_faces) { SWAP(float, a2, a3); @@ -3236,8 +3317,9 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart) static void p_chart_lscm_end(PChart *chart) { - if (chart->u.lscm.context) + if (chart->u.lscm.context) { EIG_linear_solver_delete(chart->u.lscm.context); + } if (chart->u.lscm.abf_alpha) { MEM_freeN(chart->u.lscm.abf_alpha); @@ -3257,11 +3339,14 @@ static void p_stretch_pin_boundary(PChart *chart) { PVert *v; - for (v = chart->verts; v; v = v->nextlink) - if (v->edge->pair == NULL) + for (v = chart->verts; v; v = v->nextlink) { + if (v->edge->pair == NULL) { v->flag |= PVERT_PIN; - else + } + else { v->flag &= ~PVERT_PIN; + } + } } static float p_face_stretch(PFace *f) @@ -3274,8 +3359,9 @@ static float p_face_stretch(PFace *f) area = p_face_uv_area_signed(f); - if (area <= 0.0f) /* flipped face -> infinite stretch */ + if (area <= 0.0f) { /* flipped face -> infinite stretch */ return 1e10f; + } w = 1.0f / (2.0f * area); @@ -3311,8 +3397,9 @@ static float p_face_stretch(PFace *f) c = dot_v3v3(Pt, Pt); T = sqrtf(0.5f * (a + c)); - if (f->flag & PFACE_FILLED) + if (f->flag & PFACE_FILLED) { T *= 0.2f; + } return T; } @@ -3339,8 +3426,9 @@ static void p_chart_stretch_minimize(PChart *chart, RNG *rng) float orig_uv[2], dir[2], random_angle, trusted_radius; for (v = chart->verts; v; v = v->nextlink) { - if ((v->flag & PVERT_PIN) || !(v->flag & PVERT_SELECT)) + if ((v->flag & PVERT_PIN) || !(v->flag & PVERT_SELECT)) { continue; + } orig_stretch = p_stretch_compute_vertex(v); orig_uv[0] = v->uv[0]; @@ -3390,8 +3478,9 @@ static void p_chart_stretch_minimize(PChart *chart, RNG *rng) } /* no luck, stretch has increased, reset to old values */ - if (stretch >= orig_stretch) + if (stretch >= orig_stretch) { copy_v2_v2(v->uv, orig_uv); + } } } @@ -3402,18 +3491,23 @@ static int p_compare_geometric_uv(const void *a, const void *b) const PVert *v1 = *(const PVert *const *)a; const PVert *v2 = *(const PVert *const *)b; - if (v1->uv[0] < v2->uv[0]) + if (v1->uv[0] < v2->uv[0]) { return -1; + } else if (v1->uv[0] == v2->uv[0]) { - if (v1->uv[1] < v2->uv[1]) + if (v1->uv[1] < v2->uv[1]) { return -1; - else if (v1->uv[1] == v2->uv[1]) + } + else if (v1->uv[1] == v2->uv[1]) { return 0; - else + } + else { return 1; + } } - else + else { return 1; + } } static PBool p_chart_convex_hull(PChart *chart, PVert ***verts, int *nverts, int *right) @@ -3427,8 +3521,9 @@ static PBool p_chart_convex_hull(PChart *chart, PVert ***verts, int *nverts, int p_chart_boundaries(chart, NULL, &be); - if (!be) + if (!be) { return P_FALSE; + } e = be; do { @@ -3451,10 +3546,12 @@ static PBool p_chart_convex_hull(PChart *chart, PVert ***verts, int *nverts, int ulen = llen = 0; for (p = points, i = 0; i < npoints; i++, p++) { - while ((ulen > 1) && (p_area_signed(U[ulen - 2]->uv, (*p)->uv, U[ulen - 1]->uv) <= 0)) + while ((ulen > 1) && (p_area_signed(U[ulen - 2]->uv, (*p)->uv, U[ulen - 1]->uv) <= 0)) { ulen--; - while ((llen > 1) && (p_area_signed(L[llen - 2]->uv, (*p)->uv, L[llen - 1]->uv) >= 0)) + } + while ((llen > 1) && (p_area_signed(L[llen - 2]->uv, (*p)->uv, L[llen - 1]->uv) >= 0)) { llen--; + } U[ulen] = *p; ulen++; @@ -3463,12 +3560,14 @@ static PBool p_chart_convex_hull(PChart *chart, PVert ***verts, int *nverts, int } npoints = 0; - for (p = points, i = 0; i < ulen; i++, p++, npoints++) + for (p = points, i = 0; i < ulen; i++, p++, npoints++) { *p = U[i]; + } /* the first and last point in L are left out, since they are also in U */ - for (i = llen - 2; i > 0; i--, p++, npoints++) + for (i = llen - 2; i > 0; i--, p++, npoints++) { *p = L[i]; + } *verts = points; *nverts = npoints; @@ -3490,14 +3589,17 @@ static float p_rectangle_area(float *p1, float *dir, float *p2, float *p3, float orthodir[0] = dir[1]; orthodir[1] = -dir[0]; - if (!p_intersect_line_2d_dir(p1, dir, p2, orthodir, corner1)) + if (!p_intersect_line_2d_dir(p1, dir, p2, orthodir, corner1)) { return 1e10; + } - if (!p_intersect_line_2d_dir(p1, dir, p4, orthodir, corner2)) + if (!p_intersect_line_2d_dir(p1, dir, p4, orthodir, corner2)) { return 1e10; + } - if (!p_intersect_line_2d_dir(p3, dir, p4, orthodir, corner3)) + if (!p_intersect_line_2d_dir(p3, dir, p4, orthodir, corner3)) { return 1e10; + } return len_v2v2(corner1, corner2) * len_v2v2(corner2, corner3); } @@ -3513,8 +3615,9 @@ static float p_chart_minimum_area_angle(PChart *chart) PVert **points, *p1, *p2, *p3, *p4, *p1n; /* compute convex hull */ - if (!p_chart_convex_hull(chart, &points, &npoints, &right)) + if (!p_chart_convex_hull(chart, &points, &npoints, &right)) { return 0.0; + } /* find left/top/right/bottom points, and compute angle for each point */ angles = MEM_mallocN(sizeof(float) * npoints, "PMinAreaAngles"); @@ -3573,11 +3676,12 @@ static float p_chart_minimum_area_angle(PChart *chart) i_min = 0; mina = 1e10; - for (i = 0; i < 4; i++) + for (i = 0; i < 4; i++) { if (a[i] < mina) { mina = a[i]; i_min = i; } + } rotated += mina; nextidx = (idx[i_min] + 1) % npoints; @@ -3614,8 +3718,9 @@ static float p_chart_minimum_area_angle(PChart *chart) } /* try keeping rotation as small as possible */ - if (minangle > (float)(M_PI / 4)) + if (minangle > (float)(M_PI / 4)) { minangle -= (float)(M_PI / 2.0); + } MEM_freeN(angles); MEM_freeN(points); @@ -3708,8 +3813,9 @@ static SmoothNode *p_node_new( node->tri = tri; node->ntri = ntri; - if (ntri <= 10 || depth >= 15) + if (ntri <= 10 || depth >= 15) { return node; + } t1 = MEM_mallocN(sizeof(*t1) * ntri, "PNodeTri1"); t2 = MEM_mallocN(sizeof(*t2) * ntri, "PNodeTri1"); @@ -3757,12 +3863,15 @@ static SmoothNode *p_node_new( static void p_node_delete(SmoothNode *node) { - if (node->c1) + if (node->c1) { p_node_delete(node->c1); - if (node->c2) + } + if (node->c2) { p_node_delete(node->c2); - if (node->tri) + } + if (node->tri) { MEM_freeN(node->tri); + } } static PBool p_node_intersect(SmoothNode *node, float co[2]) @@ -3770,17 +3879,21 @@ static PBool p_node_intersect(SmoothNode *node, float co[2]) int i; if (node->tri) { - for (i = 0; i < node->ntri; i++) - if (p_triangle_inside(node->tri[i], co)) + for (i = 0; i < node->ntri; i++) { + if (p_triangle_inside(node->tri[i], co)) { return P_TRUE; + } + } return P_FALSE; } else { - if (co[node->axis] < node->split) + if (co[node->axis] < node->split) { return p_node_intersect(node->c1, co); - else + } + else { return p_node_intersect(node->c2, co); + } } } @@ -3791,12 +3904,15 @@ static int p_compare_float(const void *a_, const void *b_) const float a = *(const float *)a_; const float b = *(const float *)b_; - if (a < b) + if (a < b) { return -1; - else if (a == b) + } + else if (a == b) { return 0; - else + } + else { return 1; + } } static float p_smooth_median_edge_length(PChart *chart) @@ -3807,8 +3923,9 @@ static float p_smooth_median_edge_length(PChart *chart) int i; /* ok, so i'm lazy */ - for (i = 0, e = chart->edges; e; e = e->nextlink, i++) + for (i = 0, e = chart->edges; e; e = e->nextlink, i++) { lengths[i] = p_edge_length(e); + } qsort(lengths, i, sizeof(float), p_compare_float); @@ -3841,14 +3958,16 @@ static void p_smooth(PChart *chart) SmoothNode *root; MemArena *arena; - if (nedges == 0) + if (nedges == 0) { return; + } p_chart_uv_bbox(chart, minv, maxv); median = p_smooth_median_edge_length(chart) * 0.10f; - if (median == 0.0f) + if (median == 0.0f) { return; + } invmedian = 1.0f / median; @@ -3901,8 +4020,9 @@ static void p_smooth(PChart *chart) gridx = gridx * 2 + 1; gridy = gridy * 2 + 1; - if ((gridx <= 2) || (gridy <= 2)) + if ((gridx <= 2) || (gridy <= 2)) { return; + } edgesx = gridx - 1; edgesy = gridy - 1; @@ -3918,20 +4038,27 @@ static void p_smooth(PChart *chart) vedges = MEM_mallocN(sizeof(float) * esize, "PSmoothVEdges"); if (!nodes || !nodesx || !nodesy || !oldnodesx || !oldnodesy || !hedges || !vedges) { - if (nodes) + if (nodes) { MEM_freeN(nodes); - if (nodesx) + } + if (nodesx) { MEM_freeN(nodesx); - if (nodesy) + } + if (nodesy) { MEM_freeN(nodesy); - if (oldnodesx) + } + if (oldnodesx) { MEM_freeN(oldnodesx); - if (oldnodesy) + } + if (oldnodesy) { MEM_freeN(oldnodesy); - if (hedges) + } + if (hedges) { MEM_freeN(hedges); - if (vedges) + } + if (vedges) { MEM_freeN(vedges); + } // printf("Not enough memory for area smoothing grid"); return; @@ -4058,12 +4185,14 @@ static void p_smooth(PChart *chart) } } - if (d < dlimit) + if (d < dlimit) { break; + } } - if (moved < climit) + if (moved < climit) { break; + } } MEM_freeN(oldnodesx); @@ -4080,10 +4209,12 @@ static void p_smooth(PChart *chart) MEM_freeN(nodesx); MEM_freeN(nodesy); - if (triangles) + if (triangles) { MEM_freeN(triangles); - if (tri) + } + if (tri) { MEM_freeN(tri); + } // printf("Not enough memory for area smoothing grid"); return; @@ -4145,9 +4276,11 @@ static void p_smooth(PChart *chart) arena = BLI_memarena_new(MEM_SIZE_OPTIMAL(1 << 16), "param smooth arena"); root = p_node_new(arena, tri, esize * 2, minv, maxv, 0); - for (v = chart->verts; v; v = v->nextlink) - if (!p_node_intersect(root, v->uv)) + for (v = chart->verts; v; v = v->nextlink) { + if (!p_node_intersect(root, v->uv)) { param_warning("area smoothing error: couldn't find mapping triangle\n"); + } + } p_node_delete(root); BLI_memarena_free(arena); @@ -4193,11 +4326,13 @@ void param_delete(ParamHandle *handle) param_assert((phandle->state == PHANDLE_STATE_ALLOCATED) || (phandle->state == PHANDLE_STATE_CONSTRUCTED)); - for (i = 0; i < phandle->ncharts; i++) + for (i = 0; i < phandle->ncharts; i++) { p_chart_delete(phandle->charts[i]); + } - if (phandle->charts) + if (phandle->charts) { MEM_freeN(phandle->charts); + } if (phandle->construction_chart) { p_chart_delete(phandle->construction_chart); @@ -4319,8 +4454,9 @@ void param_edge_set_seam(ParamHandle *handle, ParamKey *vkeys) param_assert(phandle->state == PHANDLE_STATE_ALLOCATED); e = p_edge_lookup(phandle, vkeys); - if (e) + if (e) { e->flag |= PEDGE_SEAM; + } } void param_construct_end(ParamHandle *handle, ParamBool fill, ParamBool impl) @@ -4357,11 +4493,13 @@ void param_construct_end(ParamHandle *handle, ParamBool fill, ParamBool impl) phandle->charts[j] = chart; j++; - if (fill && (nboundaries > 1)) + if (fill && (nboundaries > 1)) { p_chart_fill_boundaries(chart, outer); + } - for (v = chart->verts; v; v = v->nextlink) + for (v = chart->verts; v; v = v->nextlink) { p_vert_load_pin_select_uvs(handle, v); + } } phandle->ncharts = j; @@ -4379,8 +4517,9 @@ void param_lscm_begin(ParamHandle *handle, ParamBool live, ParamBool abf) phandle->state = PHANDLE_STATE_LSCM; for (i = 0; i < phandle->ncharts; i++) { - for (f = phandle->charts[i]->faces; f; f = f->nextlink) + for (f = phandle->charts[i]->faces; f; f = f->nextlink) { p_face_backup_uvs(f); + } p_chart_lscm_begin(phandle->charts[i], (PBool)live, (PBool)abf); } } @@ -4400,11 +4539,13 @@ void param_lscm_solve(ParamHandle *handle) if (chart->u.lscm.context) { result = p_chart_lscm_solve(phandle, chart); - if (result && !(chart->flag & PCHART_HAS_PINS)) + if (result && !(chart->flag & PCHART_HAS_PINS)) { p_chart_rotate_minimum_area(chart); + } - if (!result || (chart->u.lscm.pin1)) + if (!result || (chart->u.lscm.pin1)) { p_chart_lscm_end(chart); + } } } } @@ -4443,8 +4584,9 @@ void param_stretch_begin(ParamHandle *handle) for (i = 0; i < phandle->ncharts; i++) { chart = phandle->charts[i]; - for (v = chart->verts; v; v = v->nextlink) + for (v = chart->verts; v; v = v->nextlink) { v->flag &= ~PVERT_PIN; /* don't use user-defined pins */ + } p_stretch_pin_boundary(chart); @@ -4499,8 +4641,9 @@ void param_smooth_area(ParamHandle *handle) PChart *chart = phandle->charts[i]; PVert *v; - for (v = chart->verts; v; v = v->nextlink) + for (v = chart->verts; v; v = v->nextlink) { v->flag &= ~PVERT_PIN; + } p_smooth(chart); } @@ -4553,16 +4696,18 @@ void param_pack(ParamHandle *handle, float margin, bool do_rotate, bool ignore_p PHandle *phandle = (PHandle *)handle; - if (phandle->ncharts == 0) + if (phandle->ncharts == 0) { return; + } /* this could be its own function */ if (do_rotate) { param_pack_rotate(handle, ignore_pinned); } - if (phandle->aspx != phandle->aspy) + if (phandle->aspx != phandle->aspy) { param_scale(handle, 1.0f / phandle->aspx, 1.0f / phandle->aspy); + } /* we may not use all these boxes */ boxarray = MEM_mallocN(phandle->ncharts * sizeof(BoxPack), "BoxPack box"); @@ -4588,8 +4733,9 @@ void param_pack(ParamHandle *handle, float margin, bool do_rotate, bool ignore_p box->h = chart->u.pack.size[1] + trans[1]; box->index = i; /* warning this index skips PCHART_HAS_PINS boxes */ - if (margin > 0.0f) + if (margin > 0.0f) { area += (double)sqrtf(box->w * box->h); + } } if (margin > 0.0f) { @@ -4618,10 +4764,12 @@ void param_pack(ParamHandle *handle, float margin, bool do_rotate, bool ignore_p BLI_box_pack_2d(boxarray, phandle->ncharts - unpacked, &tot_width, &tot_height); - if (tot_height > tot_width) + if (tot_height > tot_width) { scale = 1.0f / tot_height; - else + } + else { scale = 1.0f / tot_width; + } for (i = 0; i < phandle->ncharts - unpacked; i++) { box = boxarray + i; @@ -4634,8 +4782,9 @@ void param_pack(ParamHandle *handle, float margin, bool do_rotate, bool ignore_p } MEM_freeN(boxarray); - if (phandle->aspx != phandle->aspy) + if (phandle->aspx != phandle->aspy) { param_scale(handle, phandle->aspx, phandle->aspy); + } } void param_average(ParamHandle *handle, bool ignore_pinned) @@ -4647,8 +4796,9 @@ void param_average(ParamHandle *handle, bool ignore_pinned) float minv[2], maxv[2], trans[2]; PHandle *phandle = (PHandle *)handle; - if (phandle->ncharts == 0) + if (phandle->ncharts == 0) { return; + } for (i = 0; i < phandle->ncharts; i++) { PFace *f; @@ -4725,13 +4875,16 @@ void param_flush(ParamHandle *handle) for (i = 0; i < phandle->ncharts; i++) { chart = phandle->charts[i]; - if ((phandle->state == PHANDLE_STATE_LSCM) && !chart->u.lscm.context) + if ((phandle->state == PHANDLE_STATE_LSCM) && !chart->u.lscm.context) { continue; + } - if (phandle->blend == 0.0f) + if (phandle->blend == 0.0f) { p_flush_uvs(phandle, chart); - else + } + else { p_flush_uvs_blend(phandle, chart, phandle->blend); + } } } @@ -4745,7 +4898,8 @@ void param_flush_restore(ParamHandle *handle) for (i = 0; i < phandle->ncharts; i++) { chart = phandle->charts[i]; - for (f = chart->faces; f; f = f->nextlink) + for (f = chart->faces; f; f = f->nextlink) { p_face_restore_uvs(f); + } } } diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c index 71a3fdf055e..b938f963d9a 100644 --- a/source/blender/editors/uvedit/uvedit_smart_stitch.c +++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c @@ -466,11 +466,13 @@ static void stitch_calculate_island_snapping(StitchState *state, float rotation_mat[2][2]; /* check to avoid divide by 0 */ - if (island_stitch_data[i].num_rot_elements > 1) + if (island_stitch_data[i].num_rot_elements > 1) { island_stitch_data[i].rotation /= island_stitch_data[i].num_rot_elements; + } - if (island_stitch_data[i].num_rot_elements_neg > 1) + if (island_stitch_data[i].num_rot_elements_neg > 1) { island_stitch_data[i].rotation_neg /= island_stitch_data[i].num_rot_elements_neg; + } if (island_stitch_data[i].numOfElements > 1) { island_stitch_data[i].medianPoint[0] /= island_stitch_data[i].numOfElements; @@ -609,8 +611,9 @@ static void stitch_island_calculate_vert_rotation(UvElement *element, int rot_elem = 0, rot_elem_neg = 0; BMLoop *l; - if (element->island == ssc->static_island && !ssc->midpoints) + if (element->island == ssc->static_island && !ssc->midpoints) { return; + } l = element->l; @@ -625,8 +628,9 @@ static void stitch_island_calculate_vert_rotation(UvElement *element, float normal[2]; /* only calculate rotation against static island uv verts */ - if (!ssc->midpoints && element_iter->island != ssc->static_island) + if (!ssc->midpoints && element_iter->island != ssc->static_island) { continue; + } index_tmp1 = element_iter - state->element_map->buf; index_tmp1 = state->map[index_tmp1]; @@ -717,8 +721,9 @@ static void stitch_uv_edge_generate_linked_edges(GHash *edge_hash, StitchState * for (i = 0; i < state->total_separate_edges; i++) { UvEdge *edge = edges + i; - if (edge->first) + if (edge->first) { continue; + } /* only boundary edges can be stitched. Yes. Sorry about that :p */ if (edge->flag & STITCH_BOUNDARY) { @@ -736,10 +741,12 @@ static void stitch_uv_edge_generate_linked_edges(GHash *edge_hash, StitchState * UvElement *iter2 = NULL; /* check to see if other vertex of edge belongs to same vertex as */ - if (BM_elem_index_get(iter1->l->next->v) == elemindex2) + if (BM_elem_index_get(iter1->l->next->v) == elemindex2) { iter2 = BM_uv_element_get(element_map, iter1->l->f, iter1->l->next); - else if (BM_elem_index_get(iter1->l->prev->v) == elemindex2) + } + else if (BM_elem_index_get(iter1->l->prev->v) == elemindex2) { iter2 = BM_uv_element_get(element_map, iter1->l->f, iter1->l->prev); + } if (iter2) { int index1 = map[iter1 - first_element]; @@ -852,8 +859,9 @@ static void stitch_setup_face_preview_for_uv_group(UvElement *element, StitchPreviewer *preview = state->stitch_preview; /* static island does not change so returning immediately */ - if (ssc->snap_islands && !ssc->midpoints && ssc->static_island == element->island) + if (ssc->snap_islands && !ssc->midpoints && ssc->static_island == element->island) { return; + } if (ssc->snap_islands) { island_stitch_data[element->island].addedForPreview = 1; @@ -892,8 +900,9 @@ static void stitch_validate_uv_stitchability(UvElement *element, for (; element_iter; element_iter = element_iter->next) { if (element_iter->separate) { - if (element_iter == element) + if (element_iter == element) { continue; + } if (stitch_check_uvs_state_stitchable(element, element_iter, ssc, state)) { if ((element_iter->island == ssc->static_island) || (element->island == ssc->static_island)) { @@ -930,8 +939,9 @@ static void stitch_validate_edge_stitchability(UvEdge *edge, UvEdge *edge_iter = edge->first; for (; edge_iter; edge_iter = edge_iter->next) { - if (edge_iter == edge) + if (edge_iter == edge) { continue; + } if (stitch_check_edges_state_stitchable(edge, edge_iter, ssc, state)) { if ((edge_iter->element->island == ssc->static_island) || (edge->element->island == ssc->static_island)) { @@ -1029,8 +1039,9 @@ static int stitch_process_data(StitchStateContainer *ssc, /* cleanup previous preview */ stitch_preview_delete(state->stitch_preview); preview = state->stitch_preview = stitch_preview_init(); - if (preview == NULL) + if (preview == NULL) { return 0; + } preview_position = MEM_mallocN(bm->totface * sizeof(*preview_position), "stitch_face_preview_position"); @@ -1248,8 +1259,7 @@ static int stitch_process_data(StitchStateContainer *ssc, int face_preview_pos = preview_position[index].data_position; if (face_preview_pos != STITCH_NO_PREVIEW) { preview->uvs_per_polygon[preview_position[index].polycount_position] = efa->len; - BM_ITER_ELEM_INDEX(l, &liter, efa, BM_LOOPS_OF_FACE, i) - { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); copy_v2_v2(preview->preview_polys + face_preview_pos + i * 2, luv->uv); } @@ -1260,8 +1270,7 @@ static int stitch_process_data(StitchStateContainer *ssc, BMLoop *fl = BM_FACE_FIRST_LOOP(efa); MLoopUV *fuv = CustomData_bmesh_get(&bm->ldata, fl->head.data, CD_MLOOPUV); - BM_ITER_ELEM_INDEX(l, &liter, efa, BM_LOOPS_OF_FACE, i) - { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { if (i < numoftris) { /* using next since the first uv is already accounted for */ BMLoop *lnext = l->next; @@ -1316,8 +1325,9 @@ static int stitch_process_data(StitchStateContainer *ssc, copy_v2_v2(final_position[i].uv, luv->uv); final_position[i].count = 1; - if (ssc->snap_islands && element->island == ssc->static_island && !stitch_midpoints) + if (ssc->snap_islands && element->island == ssc->static_island && !stitch_midpoints) { continue; + } element_iter = state->element_map->vert[BM_elem_index_get(l->v)]; @@ -1366,8 +1376,10 @@ static int stitch_process_data(StitchStateContainer *ssc, state->uvs[edge->uv1]->flag |= STITCH_STITCHABLE; state->uvs[edge->uv2]->flag |= STITCH_STITCHABLE; - if (ssc->snap_islands && edge->element->island == ssc->static_island && !stitch_midpoints) + if (ssc->snap_islands && edge->element->island == ssc->static_island && + !stitch_midpoints) { continue; + } for (edge_iter = edge->first; edge_iter; edge_iter = edge_iter->next) { if (stitch_check_edges_state_stitchable(edge, edge_iter, ssc, state)) { @@ -1414,8 +1426,9 @@ static int stitch_process_data(StitchStateContainer *ssc, l = element->l; luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); - /* accumulate each islands' translation from stitchable elements. it is important to do here - * because in final pass MTFaces get modified and result is zero. */ + /* accumulate each islands' translation from stitchable elements. + * It is important to do here because in final pass MTFaces + * get modified and result is zero. */ island_stitch_data[element->island].translation[0] += final_position[i].uv[0] - luv->uv[0]; island_stitch_data[element->island].translation[1] += final_position[i].uv[1] - @@ -1468,8 +1481,9 @@ static int stitch_process_data(StitchStateContainer *ssc, l = element->l; luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); - /* accumulate each islands' translation from stitchable elements. it is important to do here - * because in final pass MTFaces get modified and result is zero. */ + /* accumulate each islands' translation from stitchable elements. + * it is important to do here because in final pass MTFaces + * get modified and result is zero. */ island_stitch_data[element->island].translation[0] += final_position[i].uv[0] - luv->uv[0]; island_stitch_data[element->island].translation[1] += final_position[i].uv[1] - @@ -1587,8 +1601,9 @@ static void stitch_select_edge(UvEdge *edge, StitchState *state, int always_sele for (eiter = edge->first; eiter; eiter = eiter->next) { if (eiter->flag & STITCH_SELECTED) { int i; - if (always_select) + if (always_select) { continue; + } eiter->flag &= ~STITCH_SELECTED; for (i = 0; i < state->selection_size; i++) { @@ -1622,8 +1637,9 @@ static void stitch_select_uv(UvElement *element, StitchState *state, int always_ /* only separators go to selection */ if (element_iter->flag & STITCH_SELECTED) { int i; - if (always_select) + if (always_select) { continue; + } element_iter->flag &= ~STITCH_SELECTED; for (i = 0; i < state->selection_size; i++) { @@ -1660,8 +1676,9 @@ static void stitch_set_selection_mode(StitchState *state, const char from_stitch UvElement *element1 = state->uvs[edge->uv1]; UvElement *element2 = state->uvs[edge->uv2]; - if ((element1->flag & STITCH_SELECTED) && (element2->flag & STITCH_SELECTED)) + if ((element1->flag & STITCH_SELECTED) && (element2->flag & STITCH_SELECTED)) { stitch_select_edge(edge, state, true); + } } /* unselect selected uvelements */ @@ -1770,8 +1787,9 @@ static void stitch_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void *ar /* Preview Polys */ if (stitch_preview->preview_polys) { - for (int i = 0; i < stitch_preview->num_polys; i++) + for (int i = 0; i < stitch_preview->num_polys; i++) { num_line += stitch_preview->uvs_per_polygon[i]; + } num_tri = num_line - 2 * stitch_preview->num_polys; @@ -2143,8 +2161,7 @@ static StitchState *stitch_init(bContext *C, "uv_stitch_selection_stack"); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - BM_ITER_ELEM_INDEX(l, &liter, efa, BM_LOOPS_OF_FACE, i) - { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { UvElement *element = BM_uv_element_get(state->element_map, efa, l); if (element) { @@ -2238,8 +2255,9 @@ static bool goto_next_island(StitchStateContainer *ssc) static int stitch_init_all(bContext *C, wmOperator *op) { ARegion *ar = CTX_wm_region(C); - if (!ar) + if (!ar) { return 0; + } Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; @@ -2261,10 +2279,12 @@ static int stitch_init_all(bContext *C, wmOperator *op) } else { if (ts->uv_flag & UV_SYNC_SELECTION) { - if (ts->selectmode & SCE_SELECT_VERTEX) + if (ts->selectmode & SCE_SELECT_VERTEX) { ssc->mode = STITCH_VERT; - else + } + else { ssc->mode = STITCH_EDGE; + } } else { if (ts->uv_selectmode & UV_SELECT_VERTEX) { @@ -2386,8 +2406,9 @@ static int stitch_init_all(bContext *C, wmOperator *op) static int stitch_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - if (!stitch_init_all(C, op)) + if (!stitch_init_all(C, op)) { return OPERATOR_CANCELLED; + } WM_event_add_modal_handler(C, op); @@ -2470,8 +2491,9 @@ static void stitch_exit(bContext *C, wmOperator *op, int finished) MEM_freeN(objs_selection_count); } - if (sa) + if (sa) { ED_workspace_status_text(C, NULL); + } ED_region_draw_cb_exit(CTX_wm_region(C)->type, ssc->draw_handle); @@ -2505,8 +2527,9 @@ static int stitch_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); - if (!stitch_init_all(C, op)) + if (!stitch_init_all(C, op)) { return OPERATOR_CANCELLED; + } if (stitch_process_data_all((StitchStateContainer *)op->customdata, scene, 1)) { stitch_exit(C, op, 1); return OPERATOR_FINISHED; diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index 0caa478ffa9..85393925802 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -84,10 +84,12 @@ static void modifier_unwrap_state(Object *obedit, Scene *scene, bool *r_use_subs /* subsurf will take the modifier settings only if modifier is first or right after mirror */ if (subsurf) { - if (md && md->type == eModifierType_Subsurf) + if (md && md->type == eModifierType_Subsurf) { subsurf = true; - else + } + else { subsurf = false; + } } *r_use_subsurf = subsurf; @@ -105,14 +107,17 @@ static bool ED_uvedit_ensure_uvs(bContext *C, Scene *UNUSED(scene), Object *obed SpaceImage *sima; int cd_loop_uv_offset; - if (ED_uvedit_test(obedit)) + if (ED_uvedit_test(obedit)) { return 1; + } - if (em && em->bm->totface && !CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV)) + if (em && em->bm->totface && !CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV)) { ED_mesh_uv_texture_add(obedit->data, NULL, true, true); + } - if (!ED_uvedit_test(obedit)) + if (!ED_uvedit_test(obedit)) { return 0; + } cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); @@ -129,10 +134,12 @@ static bool ED_uvedit_ensure_uvs(bContext *C, Scene *UNUSED(scene), Object *obed ima = sima->image; if (ima) { - if (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE) + if (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE) { ima = NULL; - else + } + else { break; + } } } } @@ -176,19 +183,23 @@ static bool uvedit_have_selection(Scene *scene, BMEditMesh *em, const UnwrapOpti * so we can cancel the operator early */ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { if (scene->toolsettings->uv_flag & UV_SYNC_SELECTION) { - if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) + if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { continue; + } } - else if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + else if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { break; + } } - if (options->topology_from_uvs && !l) + if (options->topology_from_uvs && !l) { continue; + } return true; } @@ -251,8 +262,7 @@ static void construct_param_handle_face_add( /* let parametrizer split the ngon, it can make better decisions * about which split is best for unwrapping than scanfill */ - BM_ITER_ELEM_INDEX(l, &liter, efa, BM_LOOPS_OF_FACE, i) - { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); vkeys[i] = (ParamKey)BM_elem_index_get(l->v); @@ -287,8 +297,9 @@ static ParamHandle *construct_param_handle(Scene *scene, ED_uvedit_get_aspect(scene, ob, bm, &aspx, &aspy); - if (aspx != aspy) + if (aspx != aspy) { param_aspect_ratio(handle, aspx, aspy); + } } /* we need the vert indices */ @@ -433,8 +444,9 @@ static void texface_from_original_index(BMFace *efa, *pin = 0; *select = 1; - if (index == ORIGINDEX_NONE) + if (index == ORIGINDEX_NONE) { return; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (BM_elem_index_get(l->v) == index) { @@ -447,8 +459,11 @@ static void texface_from_original_index(BMFace *efa, } } -/* unwrap handle initialization for subsurf aware-unwrapper. The many modifications required to make the original function(see above) - * work justified the existence of a new function. */ +/** + * Unwrap handle initialization for subsurf aware-unwrapper. + * The many modifications required to make the original function(see above) + * work justified the existence of a new function. + */ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, Object *ob, BMEditMesh *em, @@ -493,8 +508,9 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, ED_uvedit_get_aspect(scene, ob, em->bm, &aspx, &aspy); - if (aspx != aspy) + if (aspx != aspy) { param_aspect_ratio(handle, aspx, aspy); + } } /* number of subdivisions to perform */ @@ -529,8 +545,9 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BM_mesh_elem_table_ensure(em->bm, BM_EDGE | BM_FACE); /* map subsurfed faces to original editFaces */ - for (i = 0; i < numOfFaces; i++) + for (i = 0; i < numOfFaces; i++) { faceMap[i] = BM_face_at_index(em->bm, origPolyIndices[i]); + } edgeMap = MEM_mallocN(numOfEdges * sizeof(BMEdge *), "unwrap_edit_edge_map"); @@ -551,8 +568,9 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMFace *origFace = faceMap[i]; if (scene->toolsettings->uv_flag & UV_SYNC_SELECTION) { - if (BM_elem_flag_test(origFace, BM_ELEM_HIDDEN)) + if (BM_elem_flag_test(origFace, BM_ELEM_HIDDEN)) { continue; + } } else { if (BM_elem_flag_test(origFace, BM_ELEM_HIDDEN) || @@ -576,7 +594,8 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, co[2] = subsurfedVerts[mloop[2].v].co; co[3] = subsurfedVerts[mloop[3].v].co; - /* This is where all the magic is done. If the vertex exists in the, we pass the original uv pointer to the solver, thus + /* This is where all the magic is done. + * If the vertex exists in the, we pass the original uv pointer to the solver, thus * flushing the solution to the edit mesh. */ texface_from_original_index(origFace, origVertIndices[mloop[0].v], @@ -675,8 +694,9 @@ static bool minimize_stretch_init(bContext *C, wmOperator *op) ms->lasttime = PIL_check_seconds_timer(); param_stretch_begin(ms->handle); - if (ms->blend != 0.0f) + if (ms->blend != 0.0f) { param_stretch_blend(ms->handle, ms->blend); + } op->customdata = ms; @@ -735,13 +755,16 @@ static void minimize_stretch_exit(bContext *C, wmOperator *op, bool cancel) ED_area_status_text(sa, NULL); ED_workspace_status_text(C, NULL); - if (ms->timer) + if (ms->timer) { WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), ms->timer); + } - if (cancel) + if (cancel) { param_flush_restore(ms->handle); - else + } + else { param_flush(ms->handle); + } param_stretch_end(ms->handle); param_delete(ms->handle); @@ -767,12 +790,14 @@ static int minimize_stretch_exec(bContext *C, wmOperator *op) { int i, iterations; - if (!minimize_stretch_init(C, op)) + if (!minimize_stretch_init(C, op)) { return OPERATOR_CANCELLED; + } iterations = RNA_int_get(op->ptr, "iterations"); - for (i = 0; i < iterations; i++) + for (i = 0; i < iterations; i++) { minimize_stretch_iteration(C, op, false); + } minimize_stretch_exit(C, op, false); return OPERATOR_FINISHED; @@ -782,8 +807,9 @@ static int minimize_stretch_invoke(bContext *C, wmOperator *op, const wmEvent *U { MinStretch *ms; - if (!minimize_stretch_init(C, op)) + if (!minimize_stretch_init(C, op)) { return OPERATOR_CANCELLED; + } minimize_stretch_iteration(C, op, true); @@ -961,10 +987,12 @@ static int pack_islands_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - if (RNA_struct_property_is_set(op->ptr, "margin")) + if (RNA_struct_property_is_set(op->ptr, "margin")) { scene->toolsettings->uvcalc_margin = RNA_float_get(op->ptr, "margin"); - else + } + else { RNA_float_set(op->ptr, "margin", scene->toolsettings->uvcalc_margin); + } uvedit_pack_islands_multi(scene, objects, objects_len, &options, rotate, ignore_pinned); @@ -1078,10 +1106,12 @@ void ED_uvedit_live_unwrap_begin(Scene *scene, Object *obedit) .correct_aspect = (scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT) == 0, }; - if (use_subsurf) + if (use_subsurf) { handle = construct_param_handle_subsurfed(scene, obedit, em, &options); - else + } + else { handle = construct_param_handle(scene, obedit, em->bm, &options); + } param_lscm_begin(handle, PARAM_TRUE, abf); @@ -1116,8 +1146,9 @@ void ED_uvedit_live_unwrap_end(short cancel) if (g_live_unwrap.handles) { for (int i = 0; i < g_live_unwrap.len; i++) { param_lscm_end(g_live_unwrap.handles[i]); - if (cancel) + if (cancel) { param_flush_restore(g_live_unwrap.handles[i]); + } param_delete(g_live_unwrap.handles[i]); } MEM_freeN(g_live_unwrap.handles); @@ -1229,10 +1260,12 @@ static void uv_map_rotation_matrix_ex(float result[4][4], float sideangle = 0.0f, upangle = 0.0f; /* get rotation of the current view matrix */ - if (rv3d) + if (rv3d) { copy_m4_m4(viewmatrix, rv3d->viewmat); - else + } + else { unit_m4(viewmatrix); + } /* but shifting */ copy_v4_fl(viewmatrix[3], 0.0f); @@ -1297,17 +1330,21 @@ static void uv_map_transform(bContext *C, wmOperator *op, float rotmat[4][4]) } else { upangledeg = 0.0f; - if (align == POLAR_ZY) + if (align == POLAR_ZY) { sideangledeg = 0.0f; - else + } + else { sideangledeg = 90.0f; + } } /* be compatible to the "old" sphere/cylinder mode */ - if (direction == ALIGN_TO_OBJECT) + if (direction == ALIGN_TO_OBJECT) { unit_m4(rotmat); - else + } + else { uv_map_rotation_matrix(rotmat, rv3d, obedit, upangledeg, sideangledeg, radius); + } } static void uv_transform_properties(wmOperatorType *ot, int radius) @@ -1340,7 +1377,7 @@ static void uv_transform_properties(wmOperatorType *ot, int radius) VIEW_ON_EQUATOR, "Align", "How to determine rotation around the pole"); - if (radius) + if (radius) { RNA_def_float(ot->srna, "radius", 1.0f, @@ -1350,6 +1387,7 @@ static void uv_transform_properties(wmOperatorType *ot, int radius) "Radius of the sphere or cylinder", 0.0001f, 100.0f); + } } static void correct_uv_aspect(Scene *scene, Object *ob, BMEditMesh *em) @@ -1364,15 +1402,17 @@ static void correct_uv_aspect(Scene *scene, Object *ob, BMEditMesh *em) ED_uvedit_get_aspect(scene, ob, em->bm, &aspx, &aspy); - if (aspx == aspy) + if (aspx == aspy) { return; + } if (aspx > aspy) { scale = aspy / aspx; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1384,8 +1424,9 @@ static void correct_uv_aspect(Scene *scene, Object *ob, BMEditMesh *em) scale = aspx / aspy; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1439,14 +1480,16 @@ static void uv_map_clip_correct_multi(Scene *scene, const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); /* correct for image aspect ratio */ - if (correct_aspect) + if (correct_aspect) { correct_uv_aspect(scene, ob, em); + } if (scale_to_bounds) { /* find uv limits */ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1457,8 +1500,9 @@ static void uv_map_clip_correct_multi(Scene *scene, else if (clip_to_bounds) { /* clipping and wrapping */ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1474,10 +1518,12 @@ static void uv_map_clip_correct_multi(Scene *scene, dx = (max[0] - min[0]); dy = (max[1] - min[1]); - if (dx > 0.0f) + if (dx > 0.0f) { dx = 1.0f / dx; - if (dy > 0.0f) + } + if (dy > 0.0f) { dy = 1.0f / dy; + } for (uint ob_index = 0; ob_index < objects_len; ob_index++) { Object *ob = objects[ob_index]; @@ -1486,8 +1532,9 @@ static void uv_map_clip_correct_multi(Scene *scene, const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1519,10 +1566,12 @@ static void uvedit_unwrap(Scene *scene, Object *obedit, const UnwrapOptions *opt modifier_unwrap_state(obedit, scene, &use_subsurf); ParamHandle *handle; - if (use_subsurf) + if (use_subsurf) { handle = construct_param_handle_subsurfed(scene, obedit, em, options); - else + } + else { handle = construct_param_handle(scene, obedit, em->bm, options); + } param_lscm_begin(handle, PARAM_FALSE, scene->toolsettings->unwrapper == 0); param_lscm_solve(handle); @@ -1652,31 +1701,41 @@ static int unwrap_exec(bContext *C, wmOperator *op) } /* remember last method for live unwrap */ - if (RNA_struct_property_is_set(op->ptr, "method")) + if (RNA_struct_property_is_set(op->ptr, "method")) { scene->toolsettings->unwrapper = method; - else + } + else { RNA_enum_set(op->ptr, "method", scene->toolsettings->unwrapper); + } /* remember packing margin */ - if (RNA_struct_property_is_set(op->ptr, "margin")) + if (RNA_struct_property_is_set(op->ptr, "margin")) { scene->toolsettings->uvcalc_margin = RNA_float_get(op->ptr, "margin"); - else + } + else { RNA_float_set(op->ptr, "margin", scene->toolsettings->uvcalc_margin); + } - if (options.fill_holes) + if (options.fill_holes) { scene->toolsettings->uvcalc_flag |= UVCALC_FILLHOLES; - else + } + else { scene->toolsettings->uvcalc_flag &= ~UVCALC_FILLHOLES; + } - if (options.correct_aspect) + if (options.correct_aspect) { scene->toolsettings->uvcalc_flag &= ~UVCALC_NO_ASPECT_CORRECT; - else + } + else { scene->toolsettings->uvcalc_flag |= UVCALC_NO_ASPECT_CORRECT; + } - if (use_subsurf) + if (use_subsurf) { scene->toolsettings->uvcalc_flag |= UVCALC_USESUBSURF; - else + } + else { scene->toolsettings->uvcalc_flag &= ~UVCALC_USESUBSURF; + } /* execute unwrap */ uvedit_unwrap_multi(scene, objects, objects_len, &options); @@ -1745,11 +1804,13 @@ static int uv_from_view_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE PropertyRNA *prop; prop = RNA_struct_find_property(op->ptr, "camera_bounds"); - if (!RNA_property_is_set(op->ptr, prop)) + if (!RNA_property_is_set(op->ptr, prop)) { RNA_property_boolean_set(op->ptr, prop, (camera != NULL)); + } prop = RNA_struct_find_property(op->ptr, "correct_aspect"); - if (!RNA_property_is_set(op->ptr, prop)) + if (!RNA_property_is_set(op->ptr, prop)) { RNA_property_boolean_set(op->ptr, prop, (camera == NULL)); + } return uv_from_view_exec(C, op); } @@ -1805,8 +1866,9 @@ static int uv_from_view_exec(bContext *C, wmOperator *op) uv_map_rotation_matrix_ex(rotmat, rv3d, obedit, 90.0f, 0.0f, 1.0f, objects_pos_offset); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1825,8 +1887,9 @@ static int uv_from_view_exec(bContext *C, wmOperator *op) if (uci) { BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1842,8 +1905,9 @@ static int uv_from_view_exec(bContext *C, wmOperator *op) copy_m4_m4(rotmat, obedit->obmat); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1883,8 +1947,9 @@ static bool uv_from_view_poll(bContext *C) { RegionView3D *rv3d = CTX_wm_region_view3d(C); - if (!ED_operator_uvmap(C)) + if (!ED_operator_uvmap(C)) { return 0; + } return (rv3d != NULL); } @@ -1977,8 +2042,9 @@ static void uv_sphere_project(float target[2], map_to_sphere(&target[0], &target[1], pv[0], pv[1], pv[2]); /* split line is always zero */ - if (target[0] >= 1.0f) + if (target[0] >= 1.0f) { target[0] -= 1.0f; + } } static void uv_map_mirror(BMEditMesh *em, BMFace *efa) @@ -1992,22 +2058,24 @@ static void uv_map_mirror(BMEditMesh *em, BMFace *efa) const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); - BM_ITER_ELEM_INDEX(l, &liter, efa, BM_LOOPS_OF_FACE, i) - { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); uvs[i] = luv->uv; } mi = 0; - for (i = 1; i < efa->len; i++) - if (uvs[i][0] > uvs[mi][0]) + for (i = 1; i < efa->len; i++) { + if (uvs[i][0] > uvs[mi][0]) { mi = i; + } + } for (i = 0; i < efa->len; i++) { if (i != mi) { dx = uvs[mi][0] - uvs[i][0]; - if (dx > 0.5f) + if (dx > 0.5f) { uvs[i][0] += 1.0f; + } } } } @@ -2045,8 +2113,9 @@ static int sphere_project_exec(bContext *C, wmOperator *op) uv_map_transform_center(scene, v3d, obedit, em, center, NULL); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -2100,8 +2169,9 @@ static void uv_cylinder_project(float target[2], map_to_tube(&target[0], &target[1], pv[0], pv[1], pv[2]); /* split line is always zero */ - if (target[0] >= 1.0f) + if (target[0] >= 1.0f) { target[0] -= 1.0f; + } } static int cylinder_project_exec(bContext *C, wmOperator *op) @@ -2137,8 +2207,9 @@ static int cylinder_project_exec(bContext *C, wmOperator *op) uv_map_transform_center(scene, v3d, obedit, em, center, NULL); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -2207,8 +2278,9 @@ static void uvedit_unwrap_cube_project(BMesh *bm, BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { /* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */ - if (use_select && !BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (use_select && !BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } axis_dominant_v3(&cox, &coy, efa->no); @@ -2338,6 +2410,7 @@ void ED_uvedit_add_simple_uvs(Main *bmain, Scene *scene, Object *ob) BM_mesh_bm_to_me(bmain, bm, me, (&(struct BMeshToMeshParams){0})); BM_mesh_free(bm); - if (sync_selection) + if (sync_selection) { scene->toolsettings->uv_flag |= UV_SYNC_SELECTION; + } } |