forked from bartvdbraak/blender
make ui_def_but_rna into 2 functions, once which takes a prop, another which takes a propname, no functional change yet but lets us avoid duplicate hash lookups.
This commit is contained in:
parent
dc4dede802
commit
2f5809d831
@ -2490,16 +2490,26 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str,
|
||||
return but;
|
||||
}
|
||||
|
||||
static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip)
|
||||
/* ui_def_but_rna_propname and ui_def_but_rna
|
||||
* both take the same args except for propname vs prop, this is done so we can
|
||||
* avoid an extra lookup on 'prop' when its already available.
|
||||
*
|
||||
* When this kind of change won't disrupt branches, best look into making more
|
||||
* of our UI functions take prop rather then propname.
|
||||
*/
|
||||
|
||||
#define UI_DEF_BUT_RNA_DISABLE(but) \
|
||||
but->flag |= UI_BUT_DISABLED; \
|
||||
but->lock = 1; \
|
||||
but->lockstr = ""
|
||||
|
||||
|
||||
static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, float a1, float a2, const char *tip)
|
||||
{
|
||||
uiBut *but;
|
||||
PropertyRNA *prop;
|
||||
PropertyType proptype;
|
||||
int freestr= 0, icon= 0;
|
||||
|
||||
prop= RNA_struct_find_property(ptr, propname);
|
||||
|
||||
if(prop) {
|
||||
proptype= RNA_property_type(prop);
|
||||
|
||||
/* use rna values if parameters are not specified */
|
||||
@ -2604,16 +2614,10 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
|
||||
max= UI_MAX_DRAW_STR;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
RNA_warning("ui_def_but_rna: property not found: %s.%s\n", RNA_struct_identifier(ptr->type), propname);
|
||||
str= propname;
|
||||
}
|
||||
|
||||
/* now create button */
|
||||
but= ui_def_but(block, type, retval, str, x1, y1, x2, y2, NULL, min, max, a1, a2, tip);
|
||||
|
||||
if(prop) {
|
||||
but->rnapoin= *ptr;
|
||||
but->rnaprop= prop;
|
||||
|
||||
@ -2621,7 +2625,6 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
|
||||
but->rnaindex= index;
|
||||
else
|
||||
but->rnaindex= 0;
|
||||
}
|
||||
|
||||
if(icon) {
|
||||
but->icon= (BIFIconID)icon;
|
||||
@ -2629,10 +2632,8 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
|
||||
but->flag|= UI_ICON_LEFT;
|
||||
}
|
||||
|
||||
if (!prop || !RNA_property_editable(&but->rnapoin, prop)) {
|
||||
but->flag |= UI_BUT_DISABLED;
|
||||
but->lock = 1;
|
||||
but->lockstr = "";
|
||||
if (!RNA_property_editable(&but->rnapoin, prop)) {
|
||||
UI_DEF_BUT_RNA_DISABLE(but);
|
||||
}
|
||||
|
||||
/* If this button uses units, calculate the step from this */
|
||||
@ -2645,6 +2646,23 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s
|
||||
return but;
|
||||
}
|
||||
|
||||
static uiBut *ui_def_but_rna_propname(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, const char *propname, int index, float min, float max, float a1, float a2, const char *tip)
|
||||
{
|
||||
PropertyRNA *prop= RNA_struct_find_property(ptr, propname);
|
||||
uiBut *but;
|
||||
|
||||
if(prop) {
|
||||
but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, prop, index, min, max, a1, a2, tip);
|
||||
}
|
||||
else {
|
||||
but= ui_def_but(block, type, retval, propname, x1, y1, x2, y2, NULL, min, max, a1, a2, tip);
|
||||
|
||||
UI_DEF_BUT_RNA_DISABLE(but);
|
||||
}
|
||||
|
||||
return but;
|
||||
}
|
||||
|
||||
static uiBut *ui_def_but_operator(uiBlock *block, int type, const char *opname, int opcontext, const char *str, int x1, int y1, short x2, short y2, const char *tip)
|
||||
{
|
||||
uiBut *but;
|
||||
@ -2857,7 +2875,7 @@ uiBut *uiDefButR(uiBlock *block, int type, int retval, const char *str, int x1,
|
||||
{
|
||||
uiBut *but;
|
||||
|
||||
but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
|
||||
but= ui_def_but_rna_propname(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
|
||||
if(but)
|
||||
ui_check_but(but);
|
||||
|
||||
@ -2942,7 +2960,7 @@ uiBut *uiDefIconButR(uiBlock *block, int type, int retval, int icon, int x1, int
|
||||
{
|
||||
uiBut *but;
|
||||
|
||||
but= ui_def_but_rna(block, type, retval, "", x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
|
||||
but= ui_def_but_rna_propname(block, type, retval, "", x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
|
||||
if(but) {
|
||||
if(icon) {
|
||||
but->icon= (BIFIconID) icon;
|
||||
@ -3027,7 +3045,7 @@ uiBut *uiDefIconTextButR(uiBlock *block, int type, int retval, int icon, const c
|
||||
{
|
||||
uiBut *but;
|
||||
|
||||
but= ui_def_but_rna(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
|
||||
but= ui_def_but_rna_propname(block, type, retval, str, x1, y1, x2, y2, ptr, propname, index, min, max, a1, a2, tip);
|
||||
if(but) {
|
||||
if(icon) {
|
||||
but->icon= (BIFIconID) icon;
|
||||
|
Loading…
Reference in New Issue
Block a user