static int buttons_context_path_data(ButsContextPath *path, int type) { Object *ob; PointerRNA *ptr = &path->ptr[path->len - 1]; /* if we already have a data, we're done */ if (RNA_struct_is_a(ptr->type, &RNA_Mesh) && (type == -1 || type == OB_MESH)) return 1; else if (RNA_struct_is_a(ptr->type, &RNA_Curve) && (type == -1 || ELEM(type, OB_CURVE, OB_SURF, OB_FONT))) return 1; else if (RNA_struct_is_a(ptr->type, &RNA_Armature) && (type == -1 || type == OB_ARMATURE)) return 1; else if (RNA_struct_is_a(ptr->type, &RNA_MetaBall) && (type == -1 || type == OB_MBALL)) return 1; else if (RNA_struct_is_a(ptr->type, &RNA_Lattice) && (type == -1 || type == OB_LATTICE)) return 1; else if (RNA_struct_is_a(ptr->type, &RNA_Camera) && (type == -1 || type == OB_CAMERA)) return 1; else if (RNA_struct_is_a(ptr->type, &RNA_Lamp) && (type == -1 || type == OB_LAMP)) return 1; else if (RNA_struct_is_a(ptr->type, &RNA_Speaker) && (type == -1 || type == OB_SPEAKER)) return 1; /* try to get an object in the path, no pinning supported here */ else if (buttons_context_path_object(path)) { ob = path->ptr[path->len - 1].data; if (ob && (type == -1 || type == ob->type)) { RNA_id_pointer_create(ob->data, &path->ptr[path->len]); path->len++; return 1; } } /* no path to data possible */ return 0; }
static int copy_to_selected_list(bContext *C, PointerRNA *ptr, ListBase *lb) { if(RNA_struct_is_a(ptr->type, &RNA_Object)) *lb = CTX_data_collection_get(C, "selected_editable_objects"); else if(RNA_struct_is_a(ptr->type, &RNA_EditBone)) *lb = CTX_data_collection_get(C, "selected_editable_bones"); else if(RNA_struct_is_a(ptr->type, &RNA_PoseBone)) *lb = CTX_data_collection_get(C, "selected_pose_bones"); else if(RNA_struct_is_a(ptr->type, &RNA_Sequence)) *lb = CTX_data_collection_get(C, "selected_editable_sequences"); else return 0; return 1; }
static int buttons_context_path_brush(ButsContextPath *path) { Scene *scene; Brush *br = NULL; PointerRNA *ptr = &path->ptr[path->len - 1]; /* if we already have a (pinned) brush, we're done */ if (RNA_struct_is_a(ptr->type, &RNA_Brush)) { return 1; } /* if we have a scene, use the toolsettings brushes */ else if (buttons_context_path_scene(path)) { scene = path->ptr[path->len - 1].data; if (scene) br = BKE_paint_brush(BKE_paint_get_active(scene)); if (br) { RNA_id_pointer_create((ID *)br, &path->ptr[path->len]); path->len++; return 1; } } /* no path to a brush possible */ return 0; }
/* note: this function can return 1 without adding a world to the path * so the buttons stay visible, but be sure to check the ID type if a ID_WO */ static int buttons_context_path_world(ButsContextPath *path) { Scene *scene; World *world; PointerRNA *ptr = &path->ptr[path->len - 1]; /* if we already have a (pinned) world, we're done */ if (RNA_struct_is_a(ptr->type, &RNA_World)) { return 1; } /* if we have a scene, use the scene's world */ else if (buttons_context_path_scene(path)) { scene = path->ptr[path->len - 1].data; world = scene->world; if (world) { RNA_id_pointer_create(&scene->world->id, &path->ptr[path->len]); path->len++; return 1; } else { return 1; } } /* no path to a world possible */ return 0; }
static int buttons_context_path_object(ButsContextPath *path) { Scene *scene; Object *ob; PointerRNA *ptr = &path->ptr[path->len - 1]; /* if we already have a (pinned) object, we're done */ if (RNA_struct_is_a(ptr->type, &RNA_Object)) { return 1; } /* if we have a scene, use the scene's active object */ else if (buttons_context_path_scene(path)) { scene = path->ptr[path->len - 1].data; ob = (scene->basact) ? scene->basact->object : NULL; if (ob) { RNA_id_pointer_create(&ob->id, &path->ptr[path->len]); path->len++; return 1; } } /* no path to a object possible */ return 0; }
static int buttons_context_path_pose_bone(ButsContextPath *path) { PointerRNA *ptr = &path->ptr[path->len - 1]; /* if we already have a (pinned) PoseBone, we're done */ if (RNA_struct_is_a(ptr->type, &RNA_PoseBone)) { return 1; } /* if we have an armature, get the active bone */ if (buttons_context_path_object(path)) { Object *ob = path->ptr[path->len - 1].data; bArmature *arm = ob->data; /* path->ptr[path->len-1].data - works too */ if (ob->type != OB_ARMATURE || arm->edbo) { return 0; } else { if (arm->act_bone) { bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, arm->act_bone->name); if (pchan) { RNA_pointer_create(&ob->id, &RNA_PoseBone, pchan, &path->ptr[path->len]); path->len++; return 1; } } } } /* no path to a bone possible */ return 0; }
static int buttons_context_path_material(ButsContextPath *path, int for_texture) { Object *ob; PointerRNA *ptr= &path->ptr[path->len-1]; Material *ma; /* if we already have a (pinned) material, we're done */ if(RNA_struct_is_a(ptr->type, &RNA_Material)) { return 1; } /* if we have an object, use the object material slot */ else if(buttons_context_path_object(path)) { ob= path->ptr[path->len-1].data; if(ob && ob->type && (ob->type<OB_LAMP)) { ma= give_current_material(ob, ob->actcol); RNA_id_pointer_create(&ma->id, &path->ptr[path->len]); path->len++; if(for_texture && give_current_material_texture_node(ma)) return 1; ma= give_node_material(ma); if(ma) { RNA_id_pointer_create(&ma->id, &path->ptr[path->len]); path->len++; } return 1; } } /* no path to a material possible */ return 0; }
PyObject *pyrna_callback_remove(BPy_StructRNA *self, PyObject *args) { PyObject *py_handle; void *handle; void *customdata; if (!PyArg_ParseTuple(args, "O!:callback_remove", &PyCapsule_Type, &py_handle)) return NULL; handle = PyCapsule_GetPointer(py_handle, RNA_CAPSULE_ID); if (handle == NULL) { PyErr_SetString(PyExc_ValueError, "callback_remove(handle): NULL handle given, invalid or already removed"); return NULL; } if (RNA_struct_is_a(self->ptr.type, &RNA_Region)) { customdata = ED_region_draw_cb_customdata(handle); Py_DECREF((PyObject *)customdata); ED_region_draw_cb_exit(((ARegion *)self->ptr.data)->type, handle); } else { PyErr_SetString(PyExc_TypeError, "callback_remove(): type does not support callbacks"); return NULL; } /* don't allow reuse */ PyCapsule_SetName(py_handle, RNA_CAPSULE_ID_INVALID); Py_RETURN_NONE; }
static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix) { StructRNA *srna; srna= srna_from_self(value, ""); if(!srna) { if(PyErr_Occurred()) { PyObject *msg= PyC_ExceptionBuffer(); char *msg_char= _PyUnicode_AsString(msg); PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from PropertyGroup, failed with: %s", error_prefix, msg_char); Py_DECREF(msg); } else { PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from PropertyGroup, failed with type '%s'", error_prefix, Py_TYPE(value)->tp_name); } return NULL; } if(!RNA_struct_is_a(srna, &RNA_PropertyGroup)) { PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from PropertyGroup", error_prefix); return NULL; } return srna; }
static void template_texture_select(bContext *C, void *user_p, void *UNUSED(arg)) { /* callback when selecting a texture user in the menu */ SpaceButs *sbuts = CTX_wm_space_buts(C); ButsContextTexture *ct= (sbuts)? sbuts->texuser: NULL; ButsTextureUser *user = (ButsTextureUser*)user_p; PointerRNA texptr; Tex *tex; if(!ct) return; /* set user as active */ if(user->node) { ED_node_set_active(CTX_data_main(C), user->ntree, user->node); ct->texture = NULL; } else { texptr = RNA_property_pointer_get(&user->ptr, user->prop); tex = (RNA_struct_is_a(texptr.type, &RNA_Texture))? texptr.data: NULL; ct->texture = tex; } ct->user = user; ct->index = user->index; }
static int buttons_context_path_scene(ButsContextPath *path) { PointerRNA *ptr = &path->ptr[path->len - 1]; /* this one just verifies */ return RNA_struct_is_a(ptr->type, &RNA_Scene); }
static PyObject *Freestyle_evaluateCurveMappingF(PyObject *self, PyObject *args) { BPy_StructRNA *py_srna; CurveMapping *cumap; int cur; float value; if (!(PyArg_ParseTuple(args, "O!if", &pyrna_struct_Type, &py_srna, &cur, &value))) return NULL; if (!RNA_struct_is_a(py_srna->ptr.type, &RNA_CurveMapping)) { PyErr_SetString(PyExc_TypeError, "1st argument is not a CurveMapping object"); return NULL; } if (cur < 0 || cur > 3) { PyErr_SetString(PyExc_ValueError, "2nd argument is out of range"); return NULL; } cumap = (CurveMapping *)py_srna->ptr.data; curvemapping_initialize(cumap); /* disable extrapolation if enabled */ if ((cumap->cm[cur].flag & CUMA_EXTEND_EXTRAPOLATE)) { cumap->cm[cur].flag &= ~(CUMA_EXTEND_EXTRAPOLATE); curvemapping_changed(cumap, 0); } return PyFloat_FromDouble(curvemapping_evaluateF(cumap, cur, value)); }
static int buttons_context_path_particle(ButsContextPath *path) { Object *ob; ParticleSystem *psys; PointerRNA *ptr = &path->ptr[path->len - 1]; /* if we already have (pinned) particle settings, we're done */ if (RNA_struct_is_a(ptr->type, &RNA_ParticleSettings)) { return 1; } /* if we have an object, get the active particle system */ if (buttons_context_path_object(path)) { ob = path->ptr[path->len - 1].data; if (ob && ob->type == OB_MESH) { psys = psys_get_current(ob); RNA_pointer_create(&ob->id, &RNA_ParticleSystem, psys, &path->ptr[path->len]); path->len++; return 1; } } /* no path to a particle system possible */ return 0; }
void buttons_texture_context_compute(const bContext *C, SpaceProperties *sbuts) { /* gather available texture users in context. runs on every draw of * properties editor, before the buttons are created. */ ButsContextTexture *ct = sbuts->texuser; ID *pinid = sbuts->pinid; if (!ct) { ct = MEM_callocN(sizeof(ButsContextTexture), "ButsContextTexture"); sbuts->texuser = ct; } else { BLI_freelistN(&ct->users); } buttons_texture_users_from_context(&ct->users, C, sbuts); if (pinid && GS(pinid->name) == ID_TE) { ct->user = NULL; ct->texture = (Tex *)pinid; } else { /* set one user as active based on active index */ if (ct->index >= BLI_listbase_count_at_most(&ct->users, ct->index + 1)) { ct->index = 0; } ct->user = BLI_findlink(&ct->users, ct->index); ct->texture = NULL; if (ct->user) { if (ct->user->ptr.data) { PointerRNA texptr; Tex *tex; /* get texture datablock pointer if it's a property */ texptr = RNA_property_pointer_get(&ct->user->ptr, ct->user->prop); tex = (RNA_struct_is_a(texptr.type, &RNA_Texture)) ? texptr.data : NULL; ct->texture = tex; } else if (ct->user->node && !(ct->user->node->flag & NODE_ACTIVE_TEXTURE)) { ButsTextureUser *user; /* detect change of active texture node in same node tree, in that * case we also automatically switch to the other node */ for (user = ct->users.first; user; user = user->next) { if (user->ntree == ct->user->ntree && user->node != ct->user->node) { if (user->node->flag & NODE_ACTIVE_TEXTURE) { ct->user = user; ct->index = BLI_findindex(&ct->users, user); break; } } } } } } }
/** Jump to the object or bone referenced by the pointer, or check if it is possible. */ static bool jump_to_target_ptr(bContext *C, PointerRNA ptr, const bool poll) { if (RNA_pointer_is_null(&ptr)) { return false; } /* Verify pointer type. */ char bone_name[MAXBONENAME]; const StructRNA *target_type = NULL; if (ELEM(ptr.type, &RNA_EditBone, &RNA_PoseBone, &RNA_Bone)) { RNA_string_get(&ptr, "name", bone_name); if (bone_name[0] != '\0') { target_type = &RNA_Bone; } } else if (RNA_struct_is_a(ptr.type, &RNA_Object)) { target_type = &RNA_Object; } if (target_type == NULL) { return false; } /* Find the containing Object. */ ViewLayer *view_layer = CTX_data_view_layer(C); Base *base = NULL; const short id_type = GS(((ID *)ptr.id.data)->name); if (id_type == ID_OB) { base = BKE_view_layer_base_find(view_layer, ptr.id.data); } else if (OB_DATA_SUPPORT_ID(id_type)) { base = ED_object_find_first_by_data_id(view_layer, ptr.id.data); } bool ok = false; if ((base == NULL) || ((target_type == &RNA_Bone) && (base->object->type != OB_ARMATURE))) { /* pass */ } else if (poll) { ok = true; } else { /* Make optional. */ const bool reveal_hidden = true; /* Select and activate the target. */ if (target_type == &RNA_Bone) { ok = ED_object_jump_to_bone(C, base->object, bone_name, reveal_hidden); } else if (target_type == &RNA_Object) { ok = ED_object_jump_to_object(C, base->object, reveal_hidden); } else { BLI_assert(0); } } return ok; }
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type) { PointerRNA ptr = CTX_data_pointer_get(C, member); if(ptr.data && RNA_struct_is_a(ptr.type, type)) return ptr; return PointerRNA_NULL; }
static bool copy_to_selected_list( bContext *C, PointerRNA *ptr, PropertyRNA *prop, ListBase *r_lb, bool *r_use_path_from_id, char **r_path) { *r_use_path_from_id = false; *r_path = NULL; if (RNA_struct_is_a(ptr->type, &RNA_EditBone)) { *r_lb = CTX_data_collection_get(C, "selected_editable_bones"); } else if (RNA_struct_is_a(ptr->type, &RNA_PoseBone)) { *r_lb = CTX_data_collection_get(C, "selected_pose_bones"); } else if (RNA_struct_is_a(ptr->type, &RNA_Sequence)) { *r_lb = CTX_data_collection_get(C, "selected_editable_sequences"); } else if (ptr->id.data) { ID *id = ptr->id.data; if (GS(id->name) == ID_OB) { *r_lb = CTX_data_collection_get(C, "selected_editable_objects"); *r_use_path_from_id = true; *r_path = RNA_path_from_ID_to_property(ptr, prop); } else if (GS(id->name) == ID_SCE) { /* Sequencer's ID is scene :/ */ /* Try to recursively find an RNA_Sequence ancestor, to handle situations like T41062... */ if ((*r_path = RNA_path_resolve_from_type_to_property(ptr, prop, &RNA_Sequence)) != NULL) { *r_lb = CTX_data_collection_get(C, "selected_editable_sequences"); } } return (*r_path != NULL); } else { return false; } return true; }
static int copy_to_selected_list(bContext *C, PointerRNA *ptr, ListBase *lb, int *use_path) { *use_path = FALSE; if (RNA_struct_is_a(ptr->type, &RNA_EditBone)) *lb = CTX_data_collection_get(C, "selected_editable_bones"); else if (RNA_struct_is_a(ptr->type, &RNA_PoseBone)) *lb = CTX_data_collection_get(C, "selected_pose_bones"); else if (RNA_struct_is_a(ptr->type, &RNA_Sequence)) *lb = CTX_data_collection_get(C, "selected_editable_sequences"); else { ID *id = ptr->id.data; if (id && GS(id->name) == ID_OB) { *lb = CTX_data_collection_get(C, "selected_editable_objects"); *use_path = TRUE; } else return 0; } return 1; }
static PointerRNA *get_pointer_type(ButsContextPath *path, StructRNA *type) { PointerRNA *ptr; int a; for (a = 0; a < path->len; a++) { ptr = &path->ptr[a]; if (RNA_struct_is_a(ptr->type, type)) return ptr; } return NULL; }
int UI_rnaptr_icon_get(bContext *C, PointerRNA *ptr, int rnaicon, const bool big) { ID *id = NULL; if (!ptr->data) return rnaicon; /* try ID, material, texture or dynapaint slot */ if (RNA_struct_is_ID(ptr->type)) { id = ptr->id.data; } else if (RNA_struct_is_a(ptr->type, &RNA_MaterialSlot)) { id = RNA_pointer_get(ptr, "material").data; } else if (RNA_struct_is_a(ptr->type, &RNA_TextureSlot)) { id = RNA_pointer_get(ptr, "texture").data; } else if (RNA_struct_is_a(ptr->type, &RNA_DynamicPaintSurface)) { DynamicPaintSurface *surface = (DynamicPaintSurface *)ptr->data; if (surface->format == MOD_DPAINT_SURFACE_F_PTEX) return ICON_TEXTURE_SHADED; else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) return ICON_OUTLINER_DATA_MESH; else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) return ICON_FILE_IMAGE; } /* get icon from ID */ if (id) { int icon = ui_id_icon_get(C, id, big); return icon ? icon : rnaicon; } return rnaicon; }
static int set_pointer_type(ButsContextPath *path, bContextDataResult *result, StructRNA *type) { PointerRNA *ptr; int a; for (a = 0; a < path->len; a++) { ptr = &path->ptr[a]; if (RNA_struct_is_a(ptr->type, type)) { CTX_data_pointer_set(result, ptr->id.data, ptr->type, ptr->data); return 1; } } return 0; }
static void template_texture_select(bContext *C, void *user_p, void *UNUSED(arg)) { /* callback when selecting a texture user in the menu */ SpaceProperties *sbuts = CTX_wm_space_properties(C); ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; ButsTextureUser *user = (ButsTextureUser *)user_p; PointerRNA texptr; Tex *tex; if (!ct) { return; } /* set user as active */ if (user->node) { ED_node_set_active(CTX_data_main(C), user->ntree, user->node); ct->texture = NULL; } else { texptr = RNA_property_pointer_get(&user->ptr, user->prop); tex = (RNA_struct_is_a(texptr.type, &RNA_Texture)) ? texptr.data : NULL; ct->texture = tex; if (user->ptr.type == &RNA_ParticleSettingsTextureSlot) { /* stupid exception for particle systems which still uses influence * from the old texture system, set the active texture slots as well */ ParticleSettings *part = user->ptr.id.data; int a; for (a = 0; a < MAX_MTEX; a++) { if (user->ptr.data == part->mtex[a]) { part->texact = a; } } } if (sbuts && tex) { sbuts->preview = 1; } } ct->user = user; ct->index = user->index; }
static PyObject *Freestyle_evaluateColorRamp(PyObject *self, PyObject *args) { BPy_StructRNA *py_srna; ColorBand *coba; float in, out[4]; if (!(PyArg_ParseTuple(args, "O!f", &pyrna_struct_Type, &py_srna, &in))) return NULL; if (!RNA_struct_is_a(py_srna->ptr.type, &RNA_ColorRamp)) { PyErr_SetString(PyExc_TypeError, "1st argument is not a ColorRamp object"); return NULL; } coba = (ColorBand *)py_srna->ptr.data; if (!do_colorband(coba, in, out)) { PyErr_SetString(PyExc_ValueError, "failed to evaluate the color ramp"); return NULL; } return Vector_CreatePyObject(out, 4, Py_NEW, NULL); }
PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args) { void *handle; PyObject *cb_func, *cb_args; char *cb_event_str = NULL; int cb_event; if (!PyArg_ParseTuple(args, "OO!|s:bpy_struct.callback_add", &cb_func, &PyTuple_Type, &cb_args, &cb_event_str)) return NULL; if (!PyCallable_Check(cb_func)) { PyErr_SetString(PyExc_TypeError, "callback_add(): first argument isn't callable"); return NULL; } if (RNA_struct_is_a(self->ptr.type, &RNA_Region)) { if (cb_event_str) { static EnumPropertyItem region_draw_mode_items[] = { {REGION_DRAW_POST_PIXEL, "POST_PIXEL", 0, "Post Pixel", ""}, {REGION_DRAW_POST_VIEW, "POST_VIEW", 0, "Post View", ""}, {REGION_DRAW_PRE_VIEW, "PRE_VIEW", 0, "Pre View", ""}, {0, NULL, 0, NULL, NULL}}; if (pyrna_enum_value_from_id(region_draw_mode_items, cb_event_str, &cb_event, "bpy_struct.callback_add()") < 0) { return NULL; } } else { cb_event = REGION_DRAW_POST_PIXEL; } handle = ED_region_draw_cb_activate(((ARegion *)self->ptr.data)->type, cb_region_draw, (void *)args, cb_event); Py_INCREF(args); } else { PyErr_SetString(PyExc_TypeError, "callback_add(): type does not suppport callbacks"); return NULL; } return PyCapsule_New((void *)handle, RNA_CAPSULE_ID, NULL); }
EnumPropertyItem *rna_Sensor_type_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free) { EnumPropertyItem *item = NULL; Object *ob = NULL; int totitem = 0; if (ptr->type == &RNA_Sensor || RNA_struct_is_a(ptr->type, &RNA_Sensor)) { ob = (Object *)ptr->id.data; } else { /* can't use ob from ptr->id.data because that enum is also used by operators */ ob = CTX_data_active_object(C); } RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ACTUATOR); RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ALWAYS); if (ob != NULL) { if (ob->type == OB_ARMATURE) { RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ARMATURE); } } RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_COLLISION); RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_DELAY); RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_JOYSTICK); RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_KEYBOARD); RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_MESSAGE); RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_MOUSE); RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_MY); RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_NEAR); RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_PROPERTY); RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RADAR); RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RANDOM); RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RAY); RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_TOUCH); RNA_enum_item_end(&item, &totitem); *free = 1; return item; }
static int buttons_context_path_material(ButsContextPath *path, bool for_texture, bool new_shading) { Object *ob; PointerRNA *ptr = &path->ptr[path->len - 1]; Material *ma; /* if we already have a (pinned) material, we're done */ if (RNA_struct_is_a(ptr->type, &RNA_Material)) { return 1; } /* if we have an object, use the object material slot */ else if (buttons_context_path_object(path)) { ob = path->ptr[path->len - 1].data; if (ob && OB_TYPE_SUPPORT_MATERIAL(ob->type)) { ma = give_current_material(ob, ob->actcol); RNA_id_pointer_create(&ma->id, &path->ptr[path->len]); path->len++; if (for_texture && give_current_material_texture_node(ma)) return 1; if (!new_shading) { /* Only try to get mat from node in case of old shading system (see T40331). */ ma = give_node_material(ma); if (ma) { RNA_id_pointer_create(&ma->id, &path->ptr[path->len]); path->len++; } } return 1; } } /* no path to a material possible */ return 0; }
static int buttons_context_path_linestyle(ButsContextPath *path) { Scene *scene; FreestyleLineStyle *linestyle; PointerRNA *ptr = &path->ptr[path->len - 1]; /* if we already have a (pinned) linestyle, we're done */ if (RNA_struct_is_a(ptr->type, &RNA_FreestyleLineStyle)) { return 1; } /* if we have a scene, use the lineset's linestyle */ else if (buttons_context_path_scene(path)) { scene = path->ptr[path->len - 1].data; linestyle = BKE_linestyle_active_from_scene(scene); if (linestyle) { RNA_id_pointer_create(&linestyle->id, &path->ptr[path->len]); path->len++; return 1; } } /* no path to a linestyle possible */ return 0; }
PyObject *pyrna_callback_classmethod_add(PyObject *UNUSED(self), PyObject *args) { void *handle; PyObject *cls; PyObject *cb_func, *cb_args; char *cb_regiontype_str; char *cb_event_str; int cb_event; int cb_regiontype; StructRNA *srna; if (PyTuple_GET_SIZE(args) < 2) { PyErr_SetString(PyExc_ValueError, "handler_add(handle): expected at least 2 args"); return NULL; } cls = PyTuple_GET_ITEM(args, 0); if (!(srna = pyrna_struct_as_srna(cls, false, "handler_add"))) { return NULL; } cb_func = PyTuple_GET_ITEM(args, 1); if (!PyCallable_Check(cb_func)) { PyErr_SetString(PyExc_TypeError, "first argument isn't callable"); return NULL; } /* class specific callbacks */ if (RNA_struct_is_a(srna, &RNA_Space)) { if (!PyArg_ParseTuple(args, "OOO!ss:Space.draw_handler_add", &cls, &cb_func, /* already assigned, no matter */ &PyTuple_Type, &cb_args, &cb_regiontype_str, &cb_event_str)) { return NULL; } if (pyrna_enum_value_from_id(region_draw_mode_items, cb_event_str, &cb_event, "bpy_struct.callback_add()") == -1) { return NULL; } else if (pyrna_enum_value_from_id(region_type_items, cb_regiontype_str, &cb_regiontype, "bpy_struct.callback_add()") == -1) { return NULL; } else { const eSpace_Type spaceid = rna_Space_refine_reverse(srna); if (spaceid == -1) { PyErr_Format(PyExc_TypeError, "unknown space type '%.200s'", RNA_struct_identifier(srna)); return NULL; } else { SpaceType *st = BKE_spacetype_from_id(spaceid); ARegionType *art = BKE_regiontype_from_id(st, cb_regiontype); handle = ED_region_draw_cb_activate(art, cb_region_draw, (void *)args, cb_event); Py_INCREF(args); } } } else { PyErr_SetString(PyExc_TypeError, "callback_add(): type does not support callbacks"); return NULL; } return PyCapsule_New((void *)handle, RNA_CAPSULE_ID, NULL); }
static int buttons_context_path_texture(ButsContextPath *path, ButsContextTexture *ct) { if (ct) { /* new shading system */ PointerRNA *ptr = &path->ptr[path->len - 1]; ID *id; /* if we already have a (pinned) texture, we're done */ if (RNA_struct_is_a(ptr->type, &RNA_Texture)) return 1; if (!ct->user) return 0; id = ct->user->id; if (id) { if (GS(id->name) == ID_BR) buttons_context_path_brush(path); else if (GS(id->name) == ID_MA) buttons_context_path_material(path, false, true); else if (GS(id->name) == ID_WO) buttons_context_path_world(path); else if (GS(id->name) == ID_LA) buttons_context_path_data(path, OB_LAMP); else if (GS(id->name) == ID_PA) buttons_context_path_particle(path); else if (GS(id->name) == ID_OB) buttons_context_path_object(path); else if (GS(id->name) == ID_LS) buttons_context_path_linestyle(path); } if (ct->texture) { RNA_id_pointer_create(&ct->texture->id, &path->ptr[path->len]); path->len++; } return 1; } else { /* old shading system */ Material *ma; Lamp *la; World *wo; ParticleSystem *psys; FreestyleLineStyle *ls; Tex *tex; PointerRNA *ptr = &path->ptr[path->len - 1]; /* if we already have a (pinned) texture, we're done */ if (RNA_struct_is_a(ptr->type, &RNA_Texture)) { return 1; } /* try world */ else if ((path->tex_ctx == SB_TEXC_WORLD) && buttons_context_path_world(path)) { wo = path->ptr[path->len - 1].data; if (wo && GS(wo->id.name) == ID_WO) { tex = give_current_world_texture(wo); RNA_id_pointer_create(&tex->id, &path->ptr[path->len]); path->len++; return 1; } } /* try particles */ else if ((path->tex_ctx == SB_TEXC_PARTICLES) && buttons_context_path_particle(path)) { if (path->ptr[path->len - 1].type == &RNA_ParticleSettings) { ParticleSettings *part = path->ptr[path->len - 1].data; tex = give_current_particle_texture(part); RNA_id_pointer_create(&tex->id, &path->ptr[path->len]); path->len++; return 1; } else { psys = path->ptr[path->len - 1].data; if (psys && psys->part && GS(psys->part->id.name) == ID_PA) { tex = give_current_particle_texture(psys->part); RNA_id_pointer_create(&tex->id, &path->ptr[path->len]); path->len++; return 1; } } } /* try material */ else if ((path->tex_ctx == SB_TEXC_MATERIAL) && buttons_context_path_material(path, true, false)) { ma = path->ptr[path->len - 1].data; if (ma) { tex = give_current_material_texture(ma); RNA_id_pointer_create(&tex->id, &path->ptr[path->len]); path->len++; return 1; } } /* try lamp */ else if ((path->tex_ctx == SB_TEXC_LAMP) && buttons_context_path_data(path, OB_LAMP)) { la = path->ptr[path->len - 1].data; if (la) { tex = give_current_lamp_texture(la); RNA_id_pointer_create(&tex->id, &path->ptr[path->len]); path->len++; return 1; } } /* try linestyle */ else if ((path->tex_ctx == SB_TEXC_LINESTYLE) && buttons_context_path_linestyle(path)) { ls = path->ptr[path->len - 1].data; if (ls) { tex = give_current_linestyle_texture(ls); RNA_id_pointer_create(&tex->id, &path->ptr[path->len]); path->len++; return 1; } } } /* no path to a texture possible */ return 0; }
PyObject *pyrna_callback_classmethod_remove(PyObject *UNUSED(self), PyObject *args) { PyObject *cls; PyObject *py_handle; void *handle; void *customdata; StructRNA *srna; char *cb_regiontype_str; int cb_regiontype; if (PyTuple_GET_SIZE(args) < 2) { PyErr_SetString(PyExc_ValueError, "callback_remove(handle): expected at least 2 args"); return NULL; } cls = PyTuple_GET_ITEM(args, 0); if (!(srna = pyrna_struct_as_srna(cls, false, "callback_remove"))) { return NULL; } py_handle = PyTuple_GET_ITEM(args, 1); handle = PyCapsule_GetPointer(py_handle, RNA_CAPSULE_ID); if (handle == NULL) { PyErr_SetString(PyExc_ValueError, "callback_remove(handle): NULL handle given, invalid or already removed"); return NULL; } if (RNA_struct_is_a(srna, &RNA_Space)) { if (!PyArg_ParseTuple(args, "OO!s:Space.draw_handler_remove", &cls, &PyCapsule_Type, &py_handle, /* already assigned, no matter */ &cb_regiontype_str)) { return NULL; } customdata = ED_region_draw_cb_customdata(handle); Py_DECREF((PyObject *)customdata); if (pyrna_enum_value_from_id(region_type_items, cb_regiontype_str, &cb_regiontype, "bpy_struct.callback_remove()") == -1) { return NULL; } else { const eSpace_Type spaceid = rna_Space_refine_reverse(srna); if (spaceid == -1) { PyErr_Format(PyExc_TypeError, "unknown space type '%.200s'", RNA_struct_identifier(srna)); return NULL; } else { SpaceType *st = BKE_spacetype_from_id(spaceid); ARegionType *art = BKE_regiontype_from_id(st, cb_regiontype); ED_region_draw_cb_exit(art, handle); } } } else { PyErr_SetString(PyExc_TypeError, "callback_remove(): type does not support callbacks"); return NULL; } /* don't allow reuse */ PyCapsule_SetName(py_handle, RNA_CAPSULE_ID_INVALID); Py_RETURN_NONE; }