From 573678df48b3c6296a22ba807b507a5421563990 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 16 Aug 2009 03:40:00 +0000 Subject: - replace rna context.mode_string with an enum context.mode, that way its self documenting and is used as a string from py anyway. - view3d use select menus use the context.mode enum value. - if selectmenu in dir(bpy.types) # creates a list of 1400+ strings, does a lookup and throws them away, better avoid this for redrawing. --- source/blender/blenkernel/BKE_context.h | 20 ++++++++++ source/blender/blenkernel/intern/context.c | 59 +++++++++++++++++++++--------- 2 files changed, 62 insertions(+), 17 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h index 81dea204dd0..035b7e2e5b9 100644 --- a/source/blender/blenkernel/BKE_context.h +++ b/source/blender/blenkernel/BKE_context.h @@ -86,6 +86,25 @@ typedef struct bContextStore { int used; } bContextStore; +/* for the conrtext's rna mode enum + * keep aligned with data_mode_strings in context.c */ +enum { + CTX_MODE_EDIT_MESH = 0, + CTX_MODE_EDIT_CURVE, + CTX_MODE_EDIT_SURFACE, + CTX_MODE_EDIT_TEXT, + CTX_MODE_EDIT_ARMATURE, + CTX_MODE_EDIT_METABALL, + CTX_MODE_EDIT_LATTICE, + CTX_MODE_POSE, + CTX_MODE_SCULPT, + CTX_MODE_PAINT_WEIGHT, + CTX_MODE_PAINT_VERTEX, + CTX_MODE_PAINT_TEXTURE, + CTX_MODE_PARTICLE, + CTX_MODE_OBJECT +}; + /* Context */ bContext *CTX_create(void); @@ -192,6 +211,7 @@ struct Scene *CTX_data_scene(const bContext *C); struct ToolSettings *CTX_data_tool_settings(const bContext *C); char *CTX_data_mode_string(const bContext *C); +int CTX_data_mode_enum(const bContext *C); void CTX_data_main_set(bContext *C, struct Main *bmain); void CTX_data_scene_set(bContext *C, struct Scene *bmain); diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index 9ffd3aa704f..c38b994849a 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -661,42 +661,67 @@ Scene *CTX_data_scene(const bContext *C) return C->data.scene; } -char *CTX_data_mode_string(const bContext *C) +int CTX_data_mode_enum(const bContext *C) { Object *obedit= CTX_data_edit_object(C); if(obedit) { switch(obedit->type) { case OB_MESH: - return "mesh_edit"; + return CTX_MODE_EDIT_MESH; case OB_CURVE: - return "curve_edit"; + return CTX_MODE_EDIT_CURVE; case OB_SURF: - return "surface_edit"; + return CTX_MODE_EDIT_SURFACE; case OB_FONT: - return "text_edit"; + return CTX_MODE_EDIT_TEXT; case OB_ARMATURE: - return "armature_edit"; + return CTX_MODE_EDIT_ARMATURE; case OB_MBALL: - return "mball_edit"; + return CTX_MODE_EDIT_METABALL; case OB_LATTICE: - return "lattice_edit"; + return CTX_MODE_EDIT_LATTICE; } } else { Object *ob = CTX_data_active_object(C); - + if(ob) { - if(ob->mode & OB_MODE_POSE) return "posemode"; - else if(ob->mode & OB_MODE_SCULPT) return "sculpt_mode"; - else if(ob->mode & OB_MODE_WEIGHT_PAINT) return "weightpaint"; - else if(ob->mode & OB_MODE_VERTEX_PAINT) return "vertexpaint"; - else if(ob->mode & OB_MODE_TEXTURE_PAINT) return "texturepaint"; - else if(ob->mode & OB_MODE_PARTICLE_EDIT) return "particlemode"; + if(ob->mode & OB_MODE_POSE) return CTX_MODE_POSE; + else if(ob->mode & OB_MODE_SCULPT) return CTX_MODE_SCULPT; + else if(ob->mode & OB_MODE_WEIGHT_PAINT) return CTX_MODE_PAINT_WEIGHT; + else if(ob->mode & OB_MODE_VERTEX_PAINT) return CTX_MODE_PAINT_VERTEX; + else if(ob->mode & OB_MODE_TEXTURE_PAINT) return CTX_MODE_PAINT_TEXTURE; + else if(ob->mode & OB_MODE_PARTICLE_EDIT) return CTX_MODE_PARTICLE; } } - - return "objectmode"; + + return CTX_MODE_OBJECT; +} + + +/* would prefer if we can use the enum version below over this one - Campbell */ +/* must be aligned with above enum */ +static char *data_mode_strings[] = { + "mesh_edit", + "curve_edit", + "surface_edit", + "text_edit", + "armature_edit", + "mball_edit", + "lattice_edit", + "posemode", + "sculpt_mode", + "weightpaint", + "vertexpaint", + "texturepaint", + "particlemode", + "objectmode", + 0 +}; +char *CTX_data_mode_string(const bContext *C) +{ + return data_mode_strings[CTX_data_mode_enum(C)]; } void CTX_data_scene_set(bContext *C, Scene *scene) -- cgit v1.2.3