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:
authorCampbell Barton <ideasman42@gmail.com>2018-06-16 16:44:13 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-06-16 16:44:13 +0300
commit73abca1da084cf8bd9ff1e8ba18770d741ca4a4e (patch)
tree3000d3199e9de08827b69b20dd49b52a57f919a5
parentb955747875426c68c43e1f8bc7e4f2792f5bb22f (diff)
UI: minor changes from 2.8
- Option to skip multi-data edits. - Open hold buttons on drag. - Utility function to set default value.
-rw-r--r--source/blender/editors/interface/interface_handlers.c110
-rw-r--r--source/blender/editors/interface/interface_intern.h1
2 files changed, 100 insertions, 11 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 6dcd7547bf5..c5bcc217ccb 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -252,6 +252,9 @@ typedef struct uiHandleButtonMulti {
bool is_proportional;
+ /* In some cases we directly apply the changes to multiple buttons, so we don't want to do it twice. */
+ bool skip;
+
/* before activating, we need to check gesture direction
* accumulate signed cursor movement here so we can tell if this is a vertical motion or not. */
float drag_dir[2];
@@ -491,6 +494,21 @@ bool ui_but_is_editable_as_text(const uiBut *but)
}
+bool ui_but_is_toggle(const uiBut *but)
+{
+ return ELEM(
+ but->type,
+ UI_BTYPE_BUT_TOGGLE,
+ UI_BTYPE_TOGGLE,
+ UI_BTYPE_ICON_TOGGLE,
+ UI_BTYPE_ICON_TOGGLE_N,
+ UI_BTYPE_TOGGLE_N,
+ UI_BTYPE_CHECKBOX,
+ UI_BTYPE_CHECKBOX_N,
+ UI_BTYPE_ROW
+ );
+}
+
static uiBut *ui_but_prev(uiBut *but)
{
while (but->prev) {
@@ -1167,6 +1185,7 @@ static void ui_multibut_states_apply(bContext *C, uiHandleButtonData *data, uiBl
uiBut *but;
BLI_assert(data->multi_data.init == BUTTON_MULTI_INIT_ENABLE);
+ BLI_assert(data->multi_data.skip == false);
for (but = block->buttons.first; but; but = but->next) {
if (but->flag & UI_BUT_DRAG_MULTI) {
@@ -1744,23 +1763,20 @@ static bool ui_but_drag_init(
/* TODO support more button pointer types */
if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
- RNA_property_float_get_array(&but->rnapoin, but->rnaprop, drag_info->color);
+ ui_but_v3_get(but, drag_info->color);
drag_info->gamma_corrected = true;
valid = true;
}
else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
- RNA_property_float_get_array(&but->rnapoin, but->rnaprop, drag_info->color);
+ ui_but_v3_get(but, drag_info->color);
drag_info->gamma_corrected = false;
valid = true;
}
- else if (but->pointype == UI_BUT_POIN_FLOAT) {
+ else if (ELEM(but->pointype, UI_BUT_POIN_FLOAT, UI_BUT_POIN_CHAR)) {
+ ui_but_v3_get(but, drag_info->color);
copy_v3_v3(drag_info->color, (float *)but->poin);
valid = true;
}
- else if (but->pointype == UI_BUT_POIN_CHAR) {
- rgb_uchar_to_float(drag_info->color, (unsigned char *)but->poin);
- valid = true;
- }
if (valid) {
WM_event_start_drag(C, ICON_COLOR, WM_DRAG_COLOR, drag_info, 0.0, WM_DRAG_FREE_DATA);
@@ -2182,7 +2198,9 @@ static void ui_apply_but(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
#ifdef USE_DRAG_MULTINUM
if (data->multi_data.has_mbuts) {
- if (data->multi_data.init == BUTTON_MULTI_INIT_ENABLE) {
+ if ((data->multi_data.init == BUTTON_MULTI_INIT_ENABLE) &&
+ (data->multi_data.skip == false))
+ {
if (data->cancel) {
ui_multibut_restore(C, data, block);
}
@@ -7506,8 +7524,9 @@ static bool ui_region_contains_point_px(ARegion *ar, int x, int y)
ui_window_to_region(ar, &mx, &my);
/* check if in the rect */
- if (!BLI_rcti_isect_pt(&v2d->mask, mx, my))
+ if (!BLI_rcti_isect_pt(&v2d->mask, mx, my)) {
return false;
+ }
}
return true;
@@ -8356,6 +8375,37 @@ static void ui_handle_button_activate(bContext *C, ARegion *ar, uiBut *but, uiBu
/************ handle events for an activated button ***********/
+static bool ui_button_value_default(uiBut *but, double *r_value)
+{
+ if (but->rnaprop != NULL && ui_but_is_rna_valid(but)) {
+ int type = RNA_property_type(but->rnaprop);
+ if (ELEM(type, PROP_FLOAT, PROP_INT)) {
+ double default_value;
+ switch (type) {
+ case PROP_INT:
+ if (RNA_property_array_check(but->rnaprop)) {
+ default_value = (double)RNA_property_int_get_default_index(&but->rnapoin, but->rnaprop, but->rnaindex);
+ }
+ else {
+ default_value = (double)RNA_property_int_get_default(&but->rnapoin, but->rnaprop);
+ }
+ break;
+ case PROP_FLOAT:
+ if (RNA_property_array_check(but->rnaprop)) {
+ default_value = (double)RNA_property_float_get_default_index(&but->rnapoin, but->rnaprop, but->rnaindex);
+ }
+ else {
+ default_value = (double)RNA_property_float_get_default(&but->rnapoin, but->rnaprop);
+ }
+ break;
+ }
+ *r_value = default_value;
+ return true;
+ }
+ }
+ return false;
+}
+
static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
{
uiHandleButtonData *data = but->active;
@@ -8467,6 +8517,19 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
/* deselect the button when moving the mouse away */
/* also de-activate for buttons that only show higlights */
if (ui_but_contains_point_px(ar, but, event->x, event->y)) {
+
+ /* Drag on a hold button (used in the toolbar) now opens it immediately. */
+ if (data->hold_action_timer) {
+ if (but->flag & UI_SELECT) {
+ if ((abs(event->x - event->prevx)) > 2 ||
+ (abs(event->y - event->prevy)) > 2)
+ {
+ WM_event_remove_timer(data->wm, data->window, data->hold_action_timer);
+ data->hold_action_timer = WM_event_add_timer(data->wm, data->window, TIMER, 0.0f);
+ }
+ }
+ }
+
if (!(but->flag & UI_SELECT)) {
but->flag |= (UI_SELECT | UI_ACTIVE);
data->cancel = false;
@@ -8542,6 +8605,29 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
uiBut *post_but = data->postbut;
uiButtonActivateType post_type = data->posttype;
+ /* Reset the button value when empty text is typed. */
+ if ((data->cancel == false) && (data->str != NULL) && (data->str[0] == '\0') &&
+ (but->rnaprop && ELEM(RNA_property_type(but->rnaprop), PROP_FLOAT, PROP_INT)))
+ {
+ MEM_SAFE_FREE(data->str);
+ ui_button_value_default(but, &data->value);
+
+#ifdef USE_DRAG_MULTINUM
+ if (data->multi_data.mbuts) {
+ for (LinkNode *l = data->multi_data.mbuts; l; l = l->next) {
+ uiButMultiState *state = l->link;
+ uiBut *but_iter = state->but;
+ double default_value;
+
+ if (ui_button_value_default(but_iter, &default_value)) {
+ ui_but_value_set(but_iter, default_value);
+ }
+ }
+ }
+ data->multi_data.skip = true;
+#endif
+ }
+
button_activate_exit(C, but, data, (post_but == NULL), false);
/* for jumping to the next button with tab while text editing */
@@ -10111,8 +10197,10 @@ static int ui_handler_region_menu(bContext *C, const wmEvent *event, void *UNUSE
{
/* if mouse moves to a different root-level menu button,
* open it to replace the current menu */
- ui_handle_button_activate(C, ar, but_other, BUTTON_ACTIVATE_OVER);
- button_activate_state(C, but_other, BUTTON_STATE_MENU_OPEN);
+ if ((but_other->flag & UI_BUT_DISABLED) == 0) {
+ ui_handle_button_activate(C, ar, but_other, BUTTON_ACTIVATE_OVER);
+ button_activate_state(C, but_other, BUTTON_STATE_MENU_OPEN);
+ }
}
else if (data->state == BUTTON_STATE_MENU_OPEN) {
int retval;
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index c1adaf4c764..cd39c0d38a9 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -679,6 +679,7 @@ extern uiBut *ui_but_find_active_in_region(struct ARegion *ar);
extern uiBut *ui_but_find_mouse_over(struct ARegion *ar, const struct wmEvent *event);
bool ui_but_is_editable(const uiBut *but);
bool ui_but_is_editable_as_text(const uiBut *but);
+bool ui_but_is_toggle(const uiBut *but);
void ui_but_pie_dir_visual(RadialDirection dir, float vec[2]);
void ui_but_pie_dir(RadialDirection dir, float vec[2]);
float ui_block_calc_pie_segment(struct uiBlock *block, const float event_xy[2]);