Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface.c124
-rw-r--r--source/blender/editors/interface/interface_layout.c5
-rw-r--r--source/blender/editors/interface/interface_regions.c20
-rw-r--r--source/blender/editors/interface/interface_style.c2
-rw-r--r--source/blender/editors/interface/view2d.c2
5 files changed, 105 insertions, 48 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 37e4cc7616b..30c0f552b72 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -77,6 +77,10 @@
#define PRECISION_FLOAT_MAX 7
#define PRECISION_FLOAT_MAX_POW 10000000 /* pow(10, PRECISION_FLOAT_MAX) */
+/* avoid unneeded calls to ui_get_but_val */
+#define UI_BUT_VALUE_UNSET DBL_MAX
+#define UI_GET_BUT_VALUE_INIT(_but, _value) if(_value == DBL_MAX) { (_value)= ui_get_but_val(_but); }
+
/*
* a full doc with API notes can be found in bf-blender/trunk/blender/doc/guides/interface_API.txt
*
@@ -967,17 +971,16 @@ void uiDrawBlock(const bContext *C, uiBlock *block)
/* ************* EVENTS ************* */
-static void ui_is_but_sel(uiBut *but)
+static void ui_is_but_sel(uiBut *but, double *value)
{
- double value; /* only initialized when needed, to avoid calling when not used */
short push=0, true=1;
if(ELEM3(but->type, TOGN, ICONTOGN, OPTIONN)) true= 0;
if( but->bit ) {
int lvalue;
- value= ui_get_but_val(but);
- lvalue= (int)value;
+ UI_GET_BUT_VALUE_INIT(but, *value)
+ lvalue= (int)*value;
if( BTST(lvalue, (but->bitnr)) ) push= true;
else push= !true;
}
@@ -997,24 +1000,24 @@ static void ui_is_but_sel(uiBut *but)
case BUT_TOGDUAL:
case ICONTOG:
case OPTION:
- value= ui_get_but_val(but);
- if(value != (double)but->hardmin) push= 1;
+ UI_GET_BUT_VALUE_INIT(but, *value)
+ if(*value != (double)but->hardmin) push= 1;
break;
case ICONTOGN:
case TOGN:
case OPTIONN:
- value= ui_get_but_val(but);
- if(value==0.0) push= 1;
+ UI_GET_BUT_VALUE_INIT(but, *value)
+ if(*value==0.0) push= 1;
break;
case ROW:
case LISTROW:
- value= ui_get_but_val(but);
+ UI_GET_BUT_VALUE_INIT(but, *value)
/* support for rna enum buts */
if(but->rnaprop && (RNA_property_flag(but->rnaprop) & PROP_ENUM_FLAG)) {
- if((int)value & (int)but->hardmax) push= 1;
+ if((int)*value & (int)but->hardmax) push= 1;
}
else {
- if(value == (double)but->hardmax) push= 1;
+ if(*value == (double)but->hardmax) push= 1;
}
break;
case COL:
@@ -1385,6 +1388,10 @@ void ui_set_but_val(uiBut *but, double value)
break;
}
}
+
+ /* we can't be sure what RNA set functions actually do,
+ * so leave this unset */
+ value= UI_BUT_VALUE_UNSET;
}
else if(but->pointype==0);
else if(but->type==HSVSLI ) {
@@ -1425,19 +1432,19 @@ void ui_set_but_val(uiBut *but, double value)
/* then set value with possible edit override */
if(but->editval)
- *but->editval= value;
+ value= *but->editval= value;
else if(but->pointype==CHA)
- *((char *)but->poin)= (char)value;
+ value= *((char *)but->poin)= (char)value;
else if(but->pointype==SHO)
- *((short *)but->poin)= (short)value;
+ value= *((short *)but->poin)= (short)value;
else if(but->pointype==INT)
- *((int *)but->poin)= (int)value;
+ value= *((int *)but->poin)= (int)value;
else if(but->pointype==FLO)
- *((float *)but->poin)= (float)value;
+ value= *((float *)but->poin)= (float)value;
}
/* update select flag */
- ui_is_but_sel(but);
+ ui_is_but_sel(but, &value);
}
int ui_get_but_string_max_length(uiBut *but)
@@ -1758,50 +1765,70 @@ static double soft_range_round_down(double value, double max)
void ui_set_but_soft_range(uiBut *but, double value)
{
- PropertyType type;
- double softmin, softmax /*, step, precision*/;
-
+ /* ideally we would not limit this but practially, its more then
+ * enough worst case is very long vectors wont use a smart soft-range
+ * which isnt so bad. */
+
if(but->rnaprop) {
- type= RNA_property_type(but->rnaprop);
+ const PropertyType type= RNA_property_type(but->rnaprop);
+ double softmin, softmax /*, step, precision*/;
+ double value_min= value;
+ double value_max= value;
/* clamp button range to something reasonable in case
* we get -inf/inf from RNA properties */
if(type == PROP_INT) {
int imin, imax, istep;
+ const int array_len= RNA_property_array_length(&but->rnapoin, but->rnaprop);
RNA_property_int_ui_range(&but->rnapoin, but->rnaprop, &imin, &imax, &istep);
softmin= (imin == INT_MIN)? -1e4: imin;
softmax= (imin == INT_MAX)? 1e4: imax;
/*step= istep;*/ /*UNUSED*/
/*precision= 1;*/ /*UNUSED*/
+
+ if(array_len >= 2) {
+ int value_range[2];
+ RNA_property_int_get_array_range(&but->rnapoin, but->rnaprop, value_range);
+ value_min= (double)value_range[0];
+ value_max= (double)value_range[1];
+ }
}
else if(type == PROP_FLOAT) {
float fmin, fmax, fstep, fprecision;
+ const int array_len= RNA_property_array_length(&but->rnapoin, but->rnaprop);
RNA_property_float_ui_range(&but->rnapoin, but->rnaprop, &fmin, &fmax, &fstep, &fprecision);
softmin= (fmin == -FLT_MAX)? (float)-1e4: fmin;
softmax= (fmax == FLT_MAX)? (float)1e4: fmax;
/*step= fstep;*/ /*UNUSED*/
/*precision= fprecision;*/ /*UNUSED*/
+
+ if(array_len >= 2) {
+ float value_range[2];
+ RNA_property_float_get_array_range(&but->rnapoin, but->rnaprop, value_range);
+ value_min= (double)value_range[0];
+ value_max= (double)value_range[1];
+ }
}
else
return;
/* if the value goes out of the soft/max range, adapt the range */
- if(value+1e-10 < softmin) {
- if(value < 0.0)
- softmin= -soft_range_round_up(-value, -softmin);
+ if(value_min+1e-10 < softmin) {
+ if(value_min < 0.0)
+ softmin= -soft_range_round_up(-value_min, -softmin);
else
- softmin= soft_range_round_down(value, softmin);
+ softmin= soft_range_round_down(value_min, softmin);
if(softmin < (double)but->hardmin)
softmin= (double)but->hardmin;
}
- else if(value-1e-10 > softmax) {
- if(value < 0.0)
- softmax= -soft_range_round_down(-value, -softmax);
+ else if(value_max-1e-10 > softmax) {
+ if(value_max < 0.0)
+ softmax= -soft_range_round_down(-value_max, -softmax);
else
- softmax= soft_range_round_up(value, softmax);
+ softmax= soft_range_round_up(value_max, softmax);
if(softmax > (double)but->hardmax)
softmax= but->hardmax;
@@ -1974,17 +2001,19 @@ void uiBlockSetEmboss(uiBlock *block, char dt)
void ui_check_but(uiBut *but)
{
/* if something changed in the button */
- double value;
+ double value= UI_BUT_VALUE_UNSET;
// float okwidth; // UNUSED
// int transopts= ui_translate_buttons();
- ui_is_but_sel(but);
+ ui_is_but_sel(but, &value);
// if(but->type==TEX || but->type==IDPOIN) transopts= 0;
/* only update soft range while not editing */
- if(but->rnaprop && !(but->editval || but->editstr || but->editvec))
- ui_set_but_soft_range(but, ui_get_but_val(but));
+ if(but->rnaprop && !(but->editval || but->editstr || but->editvec)) {
+ UI_GET_BUT_VALUE_INIT(but, value)
+ ui_set_but_soft_range(but, value);
+ }
/* test for min and max, icon sliders, etc */
switch( but->type ) {
@@ -1993,17 +2022,20 @@ void ui_check_but(uiBut *but)
case SCROLL:
case NUMSLI:
case HSVSLI:
- value= ui_get_but_val(but);
+ UI_GET_BUT_VALUE_INIT(but, value)
if(value < (double)but->hardmin) ui_set_but_val(but, but->hardmin);
else if(value > (double)but->hardmax) ui_set_but_val(but, but->hardmax);
break;
case NUMABS:
- value= fabs( ui_get_but_val(but) );
- if(value < (double)but->hardmin) ui_set_but_val(but, but->hardmin);
- else if(value > (double)but->hardmax) ui_set_but_val(but, but->hardmax);
+ {
+ double value_abs;
+ UI_GET_BUT_VALUE_INIT(but, value)
+ value_abs= fabs(value);
+ if(value_abs < (double)but->hardmin) ui_set_but_val(but, but->hardmin);
+ else if(value_abs > (double)but->hardmax) ui_set_but_val(but, but->hardmax);
break;
-
+ }
case ICONTOG:
case ICONTOGN:
if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
@@ -2014,14 +2046,14 @@ void ui_check_but(uiBut *but)
case ICONROW:
if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
- value= ui_get_but_val(but);
+ UI_GET_BUT_VALUE_INIT(but, value)
but->iconadd= (int)value- (int)(but->hardmin);
}
break;
case ICONTEXTROW:
if(!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
- value= ui_get_but_val(but);
+ UI_GET_BUT_VALUE_INIT(but, value)
but->iconadd= (int)value- (int)(but->hardmin);
}
break;
@@ -2038,7 +2070,7 @@ void ui_check_but(uiBut *but)
case ICONTEXTROW:
if(but->x2 - but->x1 > 24) {
- value= ui_get_but_val(but);
+ UI_GET_BUT_VALUE_INIT(but, value)
ui_set_name_menu(but, (int)value);
}
break;
@@ -2048,7 +2080,7 @@ void ui_check_but(uiBut *but)
case HSVSLI:
case NUMABS:
- value= ui_get_but_val(but);
+ UI_GET_BUT_VALUE_INIT(but, value)
if(ui_is_but_float(but)) {
if(value == (double) FLT_MAX) sprintf(but->drawstr, "%sinf", but->str);
@@ -2079,7 +2111,7 @@ void ui_check_but(uiBut *but)
case LABEL:
if(ui_is_but_float(but)) {
int prec;
- value= ui_get_but_val(but);
+ UI_GET_BUT_VALUE_INIT(but, value)
prec= ui_but_float_precision(but, value);
BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s%.*f", but->str, prec, value);
}
@@ -2105,8 +2137,10 @@ void ui_check_but(uiBut *but)
strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);
if (but->flag & UI_SELECT) {
strcat(but->drawstr, "Press a key");
- } else {
- strcat(but->drawstr, WM_key_event_string((short) ui_get_but_val(but)));
+ }
+ else {
+ UI_GET_BUT_VALUE_INIT(but, value)
+ strcat(but->drawstr, WM_key_event_string((short)value));
}
break;
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 55c1488291b..79a90fb9d1d 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -534,7 +534,10 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, const char *n
uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, w-UI_UNIT_X, h);
/* BUTTONS_OT_file_browse calls uiFileBrowseContextProperty */
- but= uiDefIconButO(block, BUT, "BUTTONS_OT_file_browse", WM_OP_INVOKE_DEFAULT, ICON_FILESEL, x, y, UI_UNIT_X, h, NULL);
+ but= uiDefIconButO(block, BUT, subtype==PROP_DIRPATH ?
+ "BUTTONS_OT_directory_browse" :
+ "BUTTONS_OT_file_browse",
+ WM_OP_INVOKE_DEFAULT, ICON_FILESEL, x, y, UI_UNIT_X, h, NULL);
}
else if(flag & UI_ITEM_R_EVENT) {
uiDefButR(block, KEYEVT, 0, name, x, y, w, h, ptr, RNA_property_identifier(prop), index, 0, 0, -1, -1, NULL);
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index 623651083d2..62043f240e4 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -2582,6 +2582,25 @@ void uiPupBlock(bContext *C, uiBlockCreateFunc func, void *arg)
uiPupBlockO(C, func, arg, NULL, 0);
}
+void uiPupBlockEx(bContext *C, uiBlockCreateFunc func, uiBlockCancelFunc cancel_func, void *arg)
+{
+ wmWindow *window= CTX_wm_window(C);
+ uiPopupBlockHandle *handle;
+
+ handle= ui_popup_block_create(C, NULL, NULL, func, NULL, arg);
+ handle->popup= 1;
+ handle->retvalue= 1;
+
+ handle->popup_arg= arg;
+ // handle->popup_func= operator_cb;
+ handle->cancel_func= cancel_func;
+ // handle->opcontext= opcontext;
+
+ UI_add_popup_handlers(C, &window->modalhandlers, handle);
+ WM_event_add_mousemove(C);
+}
+
+#if 0 /* UNUSED */
void uiPupBlockOperator(bContext *C, uiBlockCreateFunc func, wmOperator *op, int opcontext)
{
wmWindow *window= CTX_wm_window(C);
@@ -2599,6 +2618,7 @@ void uiPupBlockOperator(bContext *C, uiBlockCreateFunc func, wmOperator *op, int
UI_add_popup_handlers(C, &window->modalhandlers, handle);
WM_event_add_mousemove(C);
}
+#endif
void uiPupBlockClose(bContext *C, uiBlock *block)
{
diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c
index 2e4106b3c04..5f2a757d2e3 100644
--- a/source/blender/editors/interface/interface_style.c
+++ b/source/blender/editors/interface/interface_style.c
@@ -83,7 +83,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name)
BLI_addtail(styles, style);
BLI_strncpy(style->name, name, MAX_STYLE_NAME);
- style->panelzoom= 1.0;
+ style->panelzoom= 1.0; /* unused */
style->paneltitle.uifont_id= UIFONT_DEFAULT;
style->paneltitle.points= 12;
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index eb522a1d2b8..43bf2f59e04 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -1542,7 +1542,7 @@ static void scroll_printstr(Scene *scene, float x, float y, float val, int power
}
/* draw it */
- BLF_draw_default(x, y, 0.0f, str, sizeof(str)-1);
+ BLF_draw_default_ascii(x, y, 0.0f, str, sizeof(str)-1);
}
/* Draw scrollbars in the given 2d-region */