diff options
author | Joerg Mueller <nexyon@gmail.com> | 2011-08-23 00:31:46 +0400 |
---|---|---|
committer | Joerg Mueller <nexyon@gmail.com> | 2011-08-23 00:31:46 +0400 |
commit | f0d5abfcb2b54f6fd7a24220e81e0c88a914d87f (patch) | |
tree | 328a631d447ea7c7be2a757d092065c721090f82 /source/blender/editors/interface | |
parent | 1d529d83a0693693878749110a05d8b0fa929d0f (diff) | |
parent | 6a374d266d8213629f74a9f4c9a4984ddf59ef4c (diff) |
Merging trunk up to r39637.
Diffstat (limited to 'source/blender/editors/interface')
7 files changed, 88 insertions, 61 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index ccc5ac52744..0dee7a3813a 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -710,6 +710,27 @@ int uiButActiveOnly(const bContext *C, uiBlock *block, uiBut *but) return 1; } +/* use to check if we need to disable undo, but dont make any changes + * returns FALSE if undo needs to be disabled. */ +static int ui_but_is_rna_undo(uiBut *but) +{ + if(but->rnapoin.id.data) { + /* avoid undo push for buttons who's ID are screen or wm level + * we could disable undo for buttons with no ID too but may have + * unforseen conciquences, so best check for ID's we _know_ are not + * handled by undo - campbell */ + ID *id= but->rnapoin.id.data; + if(ELEM(GS(id->name), ID_SCR, ID_WM)) { + return FALSE; + } + else { + return TRUE; + } + } + + return TRUE; +} + /* assigns automatic keybindings to menu items for fast access * (underline key in menu) */ static void ui_menu_block_set_keyaccels(uiBlock *block) @@ -1245,14 +1266,14 @@ int ui_is_but_float(uiBut *but) int ui_is_but_unit(uiBut *but) { - Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); - int unit_type= uiButGetUnitType(but); + UnitSettings *unit= but->block->unit; + const int unit_type= uiButGetUnitType(but); if(unit_type == PROP_UNIT_NONE) return 0; #if 1 // removed so angle buttons get correct snapping - if (scene->unit.system_rotation == USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION) + if (unit->system_rotation == USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION) return 0; #endif @@ -1260,7 +1281,7 @@ int ui_is_but_unit(uiBut *but) if (unit_type == PROP_UNIT_TIME) return 0; - if (scene->unit.system == USER_UNIT_NONE) { + if (unit->system == USER_UNIT_NONE) { if (unit_type != PROP_UNIT_ROTATION) { return 0; } @@ -1293,19 +1314,19 @@ double ui_get_but_val(uiBut *but) switch(RNA_property_type(prop)) { case PROP_BOOLEAN: - if(RNA_property_array_length(&but->rnapoin, prop)) + if(RNA_property_array_check(prop)) value= RNA_property_boolean_get_index(&but->rnapoin, prop, but->rnaindex); else value= RNA_property_boolean_get(&but->rnapoin, prop); break; case PROP_INT: - if(RNA_property_array_length(&but->rnapoin, prop)) + if(RNA_property_array_check(prop)) value= RNA_property_int_get_index(&but->rnapoin, prop, but->rnaindex); else value= RNA_property_int_get(&but->rnapoin, prop); break; case PROP_FLOAT: - if(RNA_property_array_length(&but->rnapoin, prop)) + if(RNA_property_array_check(prop)) value= RNA_property_float_get_index(&but->rnapoin, prop, but->rnaindex); else value= RNA_property_float_get(&but->rnapoin, prop); @@ -1459,19 +1480,20 @@ int ui_get_but_string_max_length(uiBut *but) static double ui_get_but_scale_unit(uiBut *but, double value) { - Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); + UnitSettings *unit= but->block->unit; int unit_type= uiButGetUnitType(but); if(unit_type == PROP_UNIT_LENGTH) { - return value * (double)scene->unit.scale_length; + return value * (double)unit->scale_length; } else if(unit_type == PROP_UNIT_AREA) { - return value * pow(scene->unit.scale_length, 2); + return value * pow(unit->scale_length, 2); } else if(unit_type == PROP_UNIT_VOLUME) { - return value * pow(scene->unit.scale_length, 3); + return value * pow(unit->scale_length, 3); } else if(unit_type == PROP_UNIT_TIME) { /* WARNING - using evil_C :| */ + Scene *scene= CTX_data_scene(but->block->evil_C); return FRA2TIME(value); } else { @@ -1483,14 +1505,14 @@ static double ui_get_but_scale_unit(uiBut *but, double value) void ui_convert_to_unit_alt_name(uiBut *but, char *str, int maxlen) { if(ui_is_but_unit(but)) { + UnitSettings *unit= but->block->unit; int unit_type= uiButGetUnitType(but); char *orig_str; - Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); orig_str= MEM_callocN(sizeof(char)*maxlen + 1, "textedit sub str"); memcpy(orig_str, str, maxlen); - bUnit_ToUnitAltName(str, maxlen, orig_str, scene->unit.system, unit_type>>16); + bUnit_ToUnitAltName(str, maxlen, orig_str, unit->system, unit_type>>16); MEM_freeN(orig_str); } @@ -1498,27 +1520,26 @@ void ui_convert_to_unit_alt_name(uiBut *but, char *str, int maxlen) static void ui_get_but_string_unit(uiBut *but, char *str, int len_max, double value, int pad) { - Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); - int do_split= scene->unit.flag & USER_UNIT_OPT_SPLIT; + UnitSettings *unit= but->block->unit; + int do_split= unit->flag & USER_UNIT_OPT_SPLIT; int unit_type= uiButGetUnitType(but); int precision= but->a2; - if(scene->unit.scale_length<0.0001f) scene->unit.scale_length= 1.0f; // XXX do_versions + if(unit->scale_length<0.0001f) unit->scale_length= 1.0f; // XXX do_versions /* Sanity checks */ if(precision > PRECISION_FLOAT_MAX) precision= PRECISION_FLOAT_MAX; else if(precision==0) precision= 2; - bUnit_AsString(str, len_max, ui_get_but_scale_unit(but, value), precision, scene->unit.system, unit_type>>16, do_split, pad); + bUnit_AsString(str, len_max, ui_get_but_scale_unit(but, value), precision, unit->system, unit_type>>16, do_split, pad); } static float ui_get_but_step_unit(uiBut *but, float step_default) { - Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); int unit_type= uiButGetUnitType(but)>>16; float step; - step = bUnit_ClosestScalar(ui_get_but_scale_unit(but, step_default), scene->unit.system, unit_type); + step = bUnit_ClosestScalar(ui_get_but_scale_unit(but, step_default), but->block->unit->system, unit_type); if(step > 0.0f) { /* -1 is an error value */ return (float)((double)step/ui_get_but_scale_unit(but, 1.0))*100.0f; @@ -1606,12 +1627,11 @@ static int ui_set_but_string_eval_num_unit(bContext *C, uiBut *but, const char * { char str_unit_convert[256]; const int unit_type= uiButGetUnitType(but); - Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert)); /* ugly, use the draw string to get the value, this could cause problems if it includes some text which resolves to a unit */ - bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), but->drawstr, ui_get_but_scale_unit(but, 1.0), scene->unit.system, unit_type>>16); + bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), but->drawstr, ui_get_but_scale_unit(but, 1.0), but->block->unit->system, unit_type>>16); return (BPY_button_exec(C, str_unit_convert, value, TRUE) != -1); } @@ -1962,7 +1982,10 @@ uiBlock *uiBeginBlock(const bContext *C, ARegion *region, const char *name, shor block->active= 1; block->dt= dt; block->evil_C= (void*)C; // XXX - if (scn) block->color_profile= (scn->r.color_mgt_flag & R_COLOR_MANAGEMENT); + if (scn) { + block->color_profile= (scn->r.color_mgt_flag & R_COLOR_MANAGEMENT); + block->unit= &scn->unit; + } BLI_strncpy(block->name, name, sizeof(block->name)); if(region) @@ -2510,12 +2533,10 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, 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) { + const PropertyType proptype= RNA_property_type(prop); uiBut *but; - PropertyType proptype; int freestr= 0, icon= 0; - proptype= RNA_property_type(prop); - /* use rna values if parameters are not specified */ if(!str) { if(type == MENU && proptype == PROP_ENUM) { @@ -2640,9 +2661,14 @@ static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *s UI_DEF_BUT_RNA_DISABLE(but); } + if (but->flag & UI_BUT_UNDO && (ui_but_is_rna_undo(but) == FALSE)) { + but->flag &= ~UI_BUT_UNDO; + } + /* If this button uses units, calculate the step from this */ - if(ui_is_but_unit(but)) + if((proptype == PROP_FLOAT) && ui_is_but_unit(but)) { but->a1= ui_get_but_step_unit(but, but->a1); + } if(freestr) MEM_freeN((void *)str); @@ -2686,6 +2712,7 @@ static uiBut *ui_def_but_operator(uiBlock *block, int type, const char *opname, but= ui_def_but(block, type, -1, str, x1, y1, x2, y2, NULL, 0, 0, 0, 0, tip); but->optype= ot; but->opcontext= opcontext; + but->flag &= ~UI_BUT_UNDO; /* no need for ui_but_is_undo(), we never need undo here */ if(!ot) { but->flag |= UI_BUT_DISABLED; @@ -2715,6 +2742,7 @@ static uiBut *ui_def_but_operator_text(uiBlock *block, int type, const char *opn but= ui_def_but(block, type, -1, str, x1, y1, x2, y2, poin, min, max, a1, a2, tip); but->optype= ot; but->opcontext= opcontext; + but->flag &= ~UI_BUT_UNDO; /* no need for ui_but_is_undo(), we never need undo here */ if(!ot) { but->flag |= UI_BUT_DISABLED; diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 97299a6a766..dd7d2ca765f 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -140,26 +140,25 @@ void uiDrawBox(int mode, float minx, float miny, float maxx, float maxy, float r glEnd(); } -static void round_box_shade_col(float *col1, float *col2, float fac) +static void round_box_shade_col(const float col1[3], float const col2[3], const float fac) { - float col[4]; + float col[3]; col[0]= (fac*col1[0] + (1.0f-fac)*col2[0]); col[1]= (fac*col1[1] + (1.0f-fac)*col2[1]); col[2]= (fac*col1[2] + (1.0f-fac)*col2[2]); - col[3]= (fac*col1[3] + (1.0f-fac)*col2[3]); - glColor4fv(col); + glColor3fv(col); } - /* linear horizontal shade within button or in outline */ /* view2d scrollers use it */ void uiDrawBoxShade(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadetop, float shadedown) { 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}}; - float div= maxy-miny; - float coltop[4], coldown[4], color[4]; + const float div= maxy - miny; + const float idiv= 1.0f / div; + float coltop[3], coldown[3], color[4]; int a; /* mult */ @@ -173,11 +172,9 @@ void uiDrawBoxShade(int mode, float minx, float miny, float maxx, float maxy, fl coltop[0]= color[0]+shadetop; if(coltop[0]>1.0f) coltop[0]= 1.0f; coltop[1]= color[1]+shadetop; if(coltop[1]>1.0f) coltop[1]= 1.0f; coltop[2]= color[2]+shadetop; if(coltop[2]>1.0f) coltop[2]= 1.0f; - coltop[3]= color[3]; coldown[0]= color[0]+shadedown; if(coldown[0]<0.0f) coldown[0]= 0.0f; coldown[1]= color[1]+shadedown; if(coldown[1]<0.0f) coldown[1]= 0.0f; coldown[2]= color[2]+shadedown; if(coldown[2]<0.0f) coldown[2]= 0.0f; - coldown[3]= color[3]; glShadeModel(GL_SMOOTH); glBegin(mode); @@ -189,11 +186,11 @@ void uiDrawBoxShade(int mode, float minx, float miny, float maxx, float maxy, fl glVertex2f(maxx-rad, miny); for(a=0; a<7; a++) { - round_box_shade_col(coltop, coldown, vec[a][1]/div); + round_box_shade_col(coltop, coldown, vec[a][1]*idiv); glVertex2f(maxx-rad+vec[a][0], miny+vec[a][1]); } - round_box_shade_col(coltop, coldown, rad/div); + round_box_shade_col(coltop, coldown, rad*idiv); glVertex2f(maxx, miny+rad); } else { @@ -204,11 +201,11 @@ void uiDrawBoxShade(int mode, float minx, float miny, float maxx, float maxy, fl /* corner right-top */ if(roundboxtype & 2) { - round_box_shade_col(coltop, coldown, (div-rad)/div); + round_box_shade_col(coltop, coldown, (div-rad)*idiv); glVertex2f(maxx, maxy-rad); for(a=0; a<7; a++) { - round_box_shade_col(coltop, coldown, (div-rad+vec[a][1])/div); + round_box_shade_col(coltop, coldown, (div-rad+vec[a][1])*idiv); glVertex2f(maxx-vec[a][1], maxy-rad+vec[a][0]); } round_box_shade_col(coltop, coldown, 1.0); @@ -226,11 +223,11 @@ void uiDrawBoxShade(int mode, float minx, float miny, float maxx, float maxy, fl glVertex2f(minx+rad, maxy); for(a=0; a<7; a++) { - round_box_shade_col(coltop, coldown, (div-vec[a][1])/div); + round_box_shade_col(coltop, coldown, (div-vec[a][1])*idiv); glVertex2f(minx+rad-vec[a][0], maxy-vec[a][1]); } - round_box_shade_col(coltop, coldown, (div-rad)/div); + round_box_shade_col(coltop, coldown, (div-rad)*idiv); glVertex2f(minx, maxy-rad); } else { @@ -241,11 +238,11 @@ void uiDrawBoxShade(int mode, float minx, float miny, float maxx, float maxy, fl /* corner left-bottom */ if(roundboxtype & 8) { - round_box_shade_col(coltop, coldown, rad/div); + round_box_shade_col(coltop, coldown, rad*idiv); glVertex2f(minx, miny+rad); for(a=0; a<7; a++) { - round_box_shade_col(coltop, coldown, (rad-vec[a][1])/div); + round_box_shade_col(coltop, coldown, (rad-vec[a][1])*idiv); glVertex2f(minx+vec[a][1], miny+rad-vec[a][0]); } @@ -267,7 +264,8 @@ void uiDrawBoxVerticalShade(int mode, float minx, float miny, float maxx, float { 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}}; - float div= maxx-minx; + const float div= maxx - minx; + const float idiv= 1.0f / div; float colLeft[3], colRight[3], color[4]; int a; @@ -295,11 +293,11 @@ void uiDrawBoxVerticalShade(int mode, float minx, float miny, float maxx, float glVertex2f(maxx-rad, miny); for(a=0; a<7; a++) { - round_box_shade_col(colLeft, colRight, vec[a][0]/div); + round_box_shade_col(colLeft, colRight, vec[a][0]*idiv); glVertex2f(maxx-rad+vec[a][0], miny+vec[a][1]); } - round_box_shade_col(colLeft, colRight, rad/div); + round_box_shade_col(colLeft, colRight, rad*idiv); glVertex2f(maxx, miny+rad); } else { @@ -314,10 +312,10 @@ void uiDrawBoxVerticalShade(int mode, float minx, float miny, float maxx, float for(a=0; a<7; a++) { - round_box_shade_col(colLeft, colRight, (div-rad-vec[a][0])/div); + round_box_shade_col(colLeft, colRight, (div-rad-vec[a][0])*idiv); glVertex2f(maxx-vec[a][1], maxy-rad+vec[a][0]); } - round_box_shade_col(colLeft, colRight, (div-rad)/div); + round_box_shade_col(colLeft, colRight, (div-rad)*idiv); glVertex2f(maxx-rad, maxy); } else { @@ -327,11 +325,11 @@ void uiDrawBoxVerticalShade(int mode, float minx, float miny, float maxx, float /* corner left-top */ if(roundboxtype & 1) { - round_box_shade_col(colLeft, colRight, (div-rad)/div); + round_box_shade_col(colLeft, colRight, (div-rad)*idiv); glVertex2f(minx+rad, maxy); for(a=0; a<7; a++) { - round_box_shade_col(colLeft, colRight, (div-rad+vec[a][0])/div); + round_box_shade_col(colLeft, colRight, (div-rad+vec[a][0])*idiv); glVertex2f(minx+rad-vec[a][0], maxy-vec[a][1]); } @@ -349,7 +347,7 @@ void uiDrawBoxVerticalShade(int mode, float minx, float miny, float maxx, float glVertex2f(minx, miny+rad); for(a=0; a<7; a++) { - round_box_shade_col(colLeft, colRight, (vec[a][0])/div); + round_box_shade_col(colLeft, colRight, (vec[a][0])*idiv); glVertex2f(minx+vec[a][1], miny+rad-vec[a][0]); } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 15f46b4eee4..173aa98374c 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -2310,13 +2310,13 @@ static float ui_numedit_apply_snapf(uiBut *but, float tempf, float softmin, floa float fac= 1.0f; if(ui_is_but_unit(but)) { - Scene *scene= CTX_data_scene((bContext *)but->block->evil_C); + UnitSettings *unit= but->block->unit; int unit_type= uiButGetUnitType(but)>>16; - if(bUnit_IsValid(scene->unit.system, unit_type)) { - fac= (float)bUnit_BaseScalar(scene->unit.system, unit_type); + if(bUnit_IsValid(unit->system, unit_type)) { + fac= (float)bUnit_BaseScalar(unit->system, unit_type); if(ELEM3(unit_type, B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME)) { - fac /= scene->unit.scale_length; + fac /= unit->scale_length; } } } diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 76a56598e14..ebc8725ad5d 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -332,7 +332,9 @@ struct uiBlock { void *evil_C; // XXX hack for dynamic operator enums float _hsv[3]; // XXX, only access via ui_block_hsv_get() - char color_profile; // color profile for correcting linear colors for display + char color_profile; // color profile for correcting linear colors for display + struct UnitSettings *unit; // unit system, used a lot for numeric buttons so include here rather then fetching through the scene every time. + }; typedef struct uiSafetyRct { diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 4810b3fdf54..3575a8527fc 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -1017,12 +1017,10 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index ui_item_array(layout, block, name, icon, ptr, prop, len, 0, 0, w, h, expand, slider, toggle, icon_only); /* enum item */ else if(type == PROP_ENUM && index == RNA_ENUM_VALUE) { - const char *identifier= RNA_property_identifier(prop); - if(icon && name[0] && !icon_only) uiDefIconTextButR_prop(block, ROW, 0, icon, name, 0, 0, w, h, ptr, prop, -1, 0, value, -1, -1, NULL); else if(icon) - uiDefIconButR(block, ROW, 0, icon, 0, 0, w, h, ptr, identifier, -1, 0, value, -1, -1, NULL); + uiDefIconButR_prop(block, ROW, 0, icon, 0, 0, w, h, ptr, prop, -1, 0, value, -1, -1, NULL); else uiDefButR_prop(block, ROW, 0, name, 0, 0, w, h, ptr, prop, -1, 0, value, -1, -1, NULL); } diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 8bce27e366b..a55ee01202c 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -424,7 +424,8 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) if (unit_type == PROP_UNIT_ROTATION) { if (RNA_property_type(but->rnaprop) == PROP_FLOAT) { - BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Radians: %f", RNA_property_float_get_index(&but->rnapoin, but->rnaprop, but->rnaindex)); + float value= RNA_property_array_check(but->rnaprop) ? RNA_property_float_get_index(&but->rnapoin, but->rnaprop, but->rnaindex) : RNA_property_float_get(&but->rnapoin, but->rnaprop); + BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Radians: %f", value); data->color[data->totline]= 0x888888; data->totline++; } diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index d235fd0c16a..5da875356ea 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -180,7 +180,7 @@ void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y glEnable(GL_BLEND); glGetFloatv(GL_CURRENT_COLOR, color); - color[3]*= 0.125; + color[3] *= 0.125f; glColor4fv(color); /* for each AA step */ |