bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) { ID *newid = NULL; PointerRNA idptr; if (id) { /* if property isn't editable, we're going to have an extra block hanging around until we save */ if (RNA_property_editable(ptr, prop)) { if (id_copy(id, &newid, false) && newid) { /* copy animation actions too */ BKE_copy_animdata_id_action(id); /* us is 1 by convention, but RNA_property_pointer_set * will also increment it, so set it to zero */ newid->us = 0; /* assign copy */ RNA_id_pointer_create(newid, &idptr); RNA_property_pointer_set(ptr, prop, idptr); RNA_property_update(C, ptr, prop); return true; } } } return false; }
static int datadropper_init(bContext *C, wmOperator *op) { DataDropper *ddr; int index_dummy; StructRNA *type; SpaceType *st; ARegionType *art; st = BKE_spacetype_from_id(SPACE_VIEW3D); art = BKE_regiontype_from_id(st, RGN_TYPE_WINDOW); op->customdata = ddr = MEM_callocN(sizeof(DataDropper), "DataDropper"); uiContextActiveProperty(C, &ddr->ptr, &ddr->prop, &index_dummy); if ((ddr->ptr.data == NULL) || (ddr->prop == NULL) || (RNA_property_editable(&ddr->ptr, ddr->prop) == false) || (RNA_property_type(ddr->prop) != PROP_POINTER)) { return false; } ddr->art = art; ddr->draw_handle_pixel = ED_region_draw_cb_activate(art, datadropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL); type = RNA_property_pointer_type(&ddr->ptr, ddr->prop); ddr->idcode = RNA_type_to_ID_code(type); BLI_assert(ddr->idcode != 0); ddr->idcode_name = BKE_idcode_to_name(ddr->idcode); return true; }
static int eyedropper_init(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Eyedropper *eye; op->customdata = eye = MEM_callocN(sizeof(Eyedropper), "Eyedropper"); uiContextActiveProperty(C, &eye->ptr, &eye->prop, &eye->index); if ((eye->ptr.data == NULL) || (eye->prop == NULL) || (RNA_property_editable(&eye->ptr, eye->prop) == FALSE) || (RNA_property_array_length(&eye->ptr, eye->prop) < 3) || (RNA_property_type(eye->prop) != PROP_FLOAT)) { return FALSE; } if (RNA_property_subtype(eye->prop) == PROP_COLOR) { const char *display_device; display_device = scene->display_settings.display_device; eye->display = IMB_colormanagement_display_get_named(display_device); } return TRUE; }
static bool eyedropper_init(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Eyedropper *eye; op->customdata = eye = MEM_callocN(sizeof(Eyedropper), "Eyedropper"); UI_context_active_but_prop_get(C, &eye->ptr, &eye->prop, &eye->index); if ((eye->ptr.data == NULL) || (eye->prop == NULL) || (RNA_property_editable(&eye->ptr, eye->prop) == false) || (RNA_property_array_length(&eye->ptr, eye->prop) < 3) || (RNA_property_type(eye->prop) != PROP_FLOAT)) { return false; } if (RNA_property_subtype(eye->prop) == PROP_COLOR) { const char *display_device; float col[4]; display_device = scene->display_settings.display_device; eye->display = IMB_colormanagement_display_get_named(display_device); /* store inital color */ RNA_property_float_get_array(&eye->ptr, eye->prop, col); if (eye->display) { IMB_colormanagement_scene_linear_to_display_v3(col, eye->display); } copy_v3_v3(eye->init_col, col); } return true; }
/** * called from both exec & poll * * \note: normally we wouldn't call a loop from within a poll function, * However this is a special case, and for regular poll calls, getting * the context from the button will fail early. */ static bool copy_to_selected_button(bContext *C, bool all, bool poll) { PointerRNA ptr, lptr, idptr; PropertyRNA *prop, *lprop; bool success = false; int index; /* try to reset the nominated setting to its default value */ uiContextActiveProperty(C, &ptr, &prop, &index); /* if there is a valid property that is editable... */ if (ptr.data && prop) { char *path = NULL; bool use_path; CollectionPointerLink *link; ListBase lb; if (!copy_to_selected_list(C, &ptr, &lb, &use_path)) return success; if (!use_path || (path = RNA_path_from_ID_to_property(&ptr, prop))) { for (link = lb.first; link; link = link->next) { if (link->ptr.data != ptr.data) { if (use_path) { lprop = NULL; RNA_id_pointer_create(link->ptr.id.data, &idptr); RNA_path_resolve_property(&idptr, path, &lptr, &lprop); } else { lptr = link->ptr; lprop = prop; } if (lprop == prop) { if (RNA_property_editable(&lptr, lprop)) { if (poll) { success = true; break; } else { if (RNA_property_copy(&lptr, &ptr, prop, (all) ? -1 : index)) { RNA_property_update(C, &lptr, prop); success = true; } } } } } } if (path) MEM_freeN(path); } BLI_freelistN(&lb); } return success; }
static bool reset_default_button_poll(bContext *C) { PointerRNA ptr; PropertyRNA *prop; int index; UI_context_active_but_prop_get(C, &ptr, &prop, &index); return (ptr.data && prop && RNA_property_editable(&ptr, prop)); }
static int reset_default_button_poll(bContext *C) { PointerRNA ptr; PropertyRNA *prop; int index; uiContextActiveProperty(C, &ptr, &prop, &index); return (ptr.data && prop && RNA_property_editable(&ptr, prop)); }
static int eyedropper_init(bContext *C, wmOperator *op) { Eyedropper *eye; op->customdata= eye= MEM_callocN(sizeof(Eyedropper), "Eyedropper"); uiContextActiveProperty(C, &eye->ptr, &eye->prop, &eye->index); return (eye->ptr.data && eye->prop && RNA_property_editable(&eye->ptr, eye->prop)); }
static int copy_to_selected_button_exec(bContext *C, wmOperator *op) { PointerRNA ptr, lptr, idptr; PropertyRNA *prop, *lprop; int success = 0; int index, all = RNA_boolean_get(op->ptr, "all"); /* try to reset the nominated setting to its default value */ uiContextActiveProperty(C, &ptr, &prop, &index); /* if there is a valid property that is editable... */ if (ptr.data && prop) { char *path = NULL; int use_path; CollectionPointerLink *link; ListBase lb; if (!copy_to_selected_list(C, &ptr, &lb, &use_path)) return success; if (!use_path || (path = RNA_path_from_ID_to_property(&ptr, prop))) { for (link = lb.first; link; link = link->next) { if (link->ptr.data != ptr.data) { if (use_path) { lprop = NULL; RNA_id_pointer_create(link->ptr.id.data, &idptr); RNA_path_resolve(&idptr, path, &lptr, &lprop); } else { lptr = link->ptr; lprop = prop; } if (lprop == prop) { if (RNA_property_editable(&lptr, lprop)) { if (RNA_property_copy(&lptr, &ptr, prop, (all) ? -1 : index)) { RNA_property_update(C, &lptr, prop); success = 1; } } } } } if (path) MEM_freeN(path); } BLI_freelistN(&lb); } return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; }
static int copy_to_selected_button_poll(bContext *C) { PointerRNA ptr, lptr, idptr; PropertyRNA *prop, *lprop; int index, success = 0; uiContextActiveProperty(C, &ptr, &prop, &index); if (ptr.data && prop) { char *path = NULL; int use_path; CollectionPointerLink *link; ListBase lb; if (!copy_to_selected_list(C, &ptr, &lb, &use_path)) return success; if (!use_path || (path = RNA_path_from_ID_to_property(&ptr, prop))) { for (link = lb.first; link; link = link->next) { if (link->ptr.data != ptr.data) { if (use_path) { lprop = NULL; RNA_id_pointer_create(link->ptr.id.data, &idptr); RNA_path_resolve(&idptr, path, &lptr, &lprop); } else { lptr = link->ptr; lprop = prop; } if (lprop == prop) { if (RNA_property_editable(&lptr, prop)) success = 1; } } } if (path) MEM_freeN(path); } BLI_freelistN(&lb); } return success; }
static int reset_default_button_exec(bContext *C, wmOperator *op) { PointerRNA ptr; PropertyRNA *prop; int index, all = RNA_boolean_get(op->ptr, "all"); /* try to reset the nominated setting to its default value */ uiContextActiveProperty(C, &ptr, &prop, &index); /* if there is a valid property that is editable... */ if (ptr.data && prop && RNA_property_editable(&ptr, prop)) { if (RNA_property_reset(&ptr, prop, (all) ? -1 : index)) return operator_button_property_finish(C, &ptr, prop); } return OPERATOR_CANCELLED; }
static bool assign_default_button_poll(bContext *C) { PointerRNA ptr; PropertyRNA *prop; int index; UI_context_active_but_prop_get(C, &ptr, &prop, &index); if (ptr.data && prop && RNA_property_editable(&ptr, prop)) { PropertyType type = RNA_property_type(prop); return RNA_property_is_idprop(prop) && !RNA_property_array_check(prop) && ELEM(type, PROP_INT, PROP_FLOAT); } return false; }
static int depthdropper_init(bContext *C, wmOperator *op) { int index_dummy; SpaceType *st; ARegionType *art; st = BKE_spacetype_from_id(SPACE_VIEW3D); art = BKE_regiontype_from_id(st, RGN_TYPE_WINDOW); DepthDropper *ddr = MEM_callocN(sizeof(DepthDropper), __func__); uiBut *but = UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &index_dummy); /* fallback to the active camera's dof */ if (ddr->prop == NULL) { RegionView3D *rv3d = CTX_wm_region_view3d(C); if (rv3d && rv3d->persp == RV3D_CAMOB) { View3D *v3d = CTX_wm_view3d(C); if (v3d->camera && v3d->camera->data && !ID_IS_LINKED(v3d->camera->data)) { RNA_id_pointer_create(v3d->camera->data, &ddr->ptr); ddr->prop = RNA_struct_find_property(&ddr->ptr, "dof_distance"); ddr->is_undo = true; } } } else { ddr->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO); } if ((ddr->ptr.data == NULL) || (ddr->prop == NULL) || (RNA_property_editable(&ddr->ptr, ddr->prop) == false) || (RNA_property_type(ddr->prop) != PROP_FLOAT)) { MEM_freeN(ddr); return false; } op->customdata = ddr; ddr->art = art; ddr->draw_handle_pixel = ED_region_draw_cb_activate( art, depthdropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL); ddr->init_depth = RNA_property_float_get(&ddr->ptr, ddr->prop); return true; }
static int assign_default_button_exec(bContext *C, wmOperator *UNUSED(op)) { PointerRNA ptr; PropertyRNA *prop; int index; /* try to reset the nominated setting to its default value */ UI_context_active_but_prop_get(C, &ptr, &prop, &index); /* if there is a valid property that is editable... */ if (ptr.data && prop && RNA_property_editable(&ptr, prop)) { if (RNA_property_assign_default(&ptr, prop)) { return operator_button_property_finish(C, &ptr, prop); } } return OPERATOR_CANCELLED; }
static int unset_property_button_exec(bContext *C, wmOperator *UNUSED(op)) { PointerRNA ptr; PropertyRNA *prop; int index; /* try to unset the nominated property */ UI_context_active_but_prop_get(C, &ptr, &prop, &index); /* if there is a valid property that is editable... */ if (ptr.data && prop && RNA_property_editable(&ptr, prop) && /* RNA_property_is_idprop(prop) && */ RNA_property_is_set(&ptr, prop)) { RNA_property_unset(&ptr, prop); return operator_button_property_finish(C, &ptr, prop); } return OPERATOR_CANCELLED; }
static bool driverdropper_init(bContext *C, wmOperator *op) { DriverDropper *ddr; uiBut *but; op->customdata = ddr = MEM_callocN(sizeof(DriverDropper), "DriverDropper"); but = UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &ddr->index); if ((ddr->ptr.data == NULL) || (ddr->prop == NULL) || (RNA_property_editable(&ddr->ptr, ddr->prop) == false) || (RNA_property_animateable(&ddr->ptr, ddr->prop) == false) || (but->flag & UI_BUT_DRIVEN)) { return false; } return true; }
static int datadropper_init(bContext *C, wmOperator *op) { int index_dummy; StructRNA *type; SpaceType *st; ARegionType *art; st = BKE_spacetype_from_id(SPACE_VIEW3D); art = BKE_regiontype_from_id(st, RGN_TYPE_WINDOW); DataDropper *ddr = MEM_callocN(sizeof(DataDropper), __func__); uiBut *but = UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &index_dummy); if ((ddr->ptr.data == NULL) || (ddr->prop == NULL) || (RNA_property_editable(&ddr->ptr, ddr->prop) == false) || (RNA_property_type(ddr->prop) != PROP_POINTER)) { MEM_freeN(ddr); return false; } op->customdata = ddr; ddr->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO); ddr->art = art; ddr->draw_handle_pixel = ED_region_draw_cb_activate( art, datadropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL); type = RNA_property_pointer_type(&ddr->ptr, ddr->prop); ddr->idcode = RNA_type_to_ID_code(type); BLI_assert(ddr->idcode != 0); /* Note we can translate here (instead of on draw time), * because this struct has very short lifetime. */ ddr->idcode_name = TIP_(BKE_idcode_to_name(ddr->idcode)); PointerRNA ptr = RNA_property_pointer_get(&ddr->ptr, ddr->prop); ddr->init_id = ptr.id.data; return true; }
static int reset_default_button_exec(bContext *C, wmOperator *op) { PointerRNA ptr; PropertyRNA *prop; int success= 0; int index, all = RNA_boolean_get(op->ptr, "all"); /* try to reset the nominated setting to its default value */ uiContextActiveProperty(C, &ptr, &prop, &index); /* if there is a valid property that is editable... */ if (ptr.data && prop && RNA_property_editable(&ptr, prop)) { if(RNA_property_reset(&ptr, prop, (all)? -1: index)) { /* perform updates required for this property */ RNA_property_update(C, &ptr, prop); success= 1; } } return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED; }
static int depthdropper_init(bContext *C, wmOperator *op) { DepthDropper *ddr; int index_dummy; SpaceType *st; ARegionType *art; st = BKE_spacetype_from_id(SPACE_VIEW3D); art = BKE_regiontype_from_id(st, RGN_TYPE_WINDOW); op->customdata = ddr = MEM_callocN(sizeof(DepthDropper), "DepthDropper"); UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &index_dummy); /* fallback to the active camera's dof */ if (ddr->prop == NULL) { RegionView3D *rv3d = CTX_wm_region_view3d(C); if (rv3d && rv3d->persp == RV3D_CAMOB) { View3D *v3d = CTX_wm_view3d(C); if (v3d->camera && v3d->camera->data && (((ID *)v3d->camera->data)->lib == NULL)) { RNA_id_pointer_create(v3d->camera->data, &ddr->ptr); ddr->prop = RNA_struct_find_property(&ddr->ptr, "dof_distance"); } } } if ((ddr->ptr.data == NULL) || (ddr->prop == NULL) || (RNA_property_editable(&ddr->ptr, ddr->prop) == false) || (RNA_property_type(ddr->prop) != PROP_FLOAT)) { return false; } ddr->art = art; ddr->draw_handle_pixel = ED_region_draw_cb_activate(art, depthdropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL); return true; }
static int reset_default_button_exec(bContext *C, wmOperator *op) { PointerRNA ptr; PropertyRNA *prop; int success= 0; int index, all = RNA_boolean_get(op->ptr, "all"); /* try to reset the nominated setting to its default value */ uiContextActiveProperty(C, &ptr, &prop, &index); /* if there is a valid property that is editable... */ if (ptr.data && prop && RNA_property_editable(&ptr, prop)) { if(RNA_property_reset(&ptr, prop, (all)? -1: index)) { /* perform updates required for this property */ RNA_property_update(C, &ptr, prop); /* as if we pressed the button */ uiContextActivePropertyHandle(C); success= 1; } } /* Since we dont want to undo _all_ edits to settings, eg window * edits on the screen or on operator settings. * it might be better to move undo's inline - campbell */ if(success) { ID *id= ptr.id.data; if(id && ID_CHECK_UNDO(id)) { /* do nothing, go ahead with undo */ } else { return OPERATOR_CANCELLED; } } /* end hack */ return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED; }
static int copy_to_selected_button_poll(bContext *C) { PointerRNA ptr; PropertyRNA *prop; int index, success= 0; uiContextActiveProperty(C, &ptr, &prop, &index); if (ptr.data && prop) { CollectionPointerLink *link; ListBase lb; if(copy_to_selected_list(C, &ptr, &lb)) { for(link= lb.first; link; link=link->next) if(link->ptr.data != ptr.data && RNA_property_editable(&link->ptr, prop)) success= 1; BLI_freelistN(&lb); } } return success; }
/** * called from both exec & poll * * \note: normally we wouldn't call a loop from within a poll function, * However this is a special case, and for regular poll calls, getting * the context from the button will fail early. */ static bool copy_to_selected_button(bContext *C, bool all, bool poll) { Main *bmain = CTX_data_main(C); PointerRNA ptr, lptr, idptr; PropertyRNA *prop, *lprop; bool success = false; int index; /* try to reset the nominated setting to its default value */ UI_context_active_but_prop_get(C, &ptr, &prop, &index); /* if there is a valid property that is editable... */ if (ptr.data && prop) { char *path = NULL; bool use_path_from_id; CollectionPointerLink *link; ListBase lb = {NULL}; if (UI_context_copy_to_selected_list(C, &ptr, prop, &lb, &use_path_from_id, &path) && !BLI_listbase_is_empty(&lb)) { for (link = lb.first; link; link = link->next) { if (link->ptr.data != ptr.data) { if (use_path_from_id) { /* Path relative to ID. */ lprop = NULL; RNA_id_pointer_create(link->ptr.id.data, &idptr); RNA_path_resolve_property(&idptr, path, &lptr, &lprop); } else if (path) { /* Path relative to elements from list. */ lprop = NULL; RNA_path_resolve_property(&link->ptr, path, &lptr, &lprop); } else { lptr = link->ptr; lprop = prop; } if (lptr.data == ptr.data) { /* lptr might not be the same as link->ptr! */ continue; } if (lprop == prop) { if (RNA_property_editable(&lptr, lprop)) { if (poll) { success = true; break; } else { if (RNA_property_copy(bmain, &lptr, &ptr, prop, (all) ? -1 : index)) { RNA_property_update(C, &lptr, prop); success = true; } } } } } } } MEM_SAFE_FREE(path); BLI_freelistN(&lb); } return success; }