diff options
Diffstat (limited to 'source/blender/editors/interface/interface_handlers.c')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 148 |
1 files changed, 116 insertions, 32 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index ae5af185442..c5275ea98b5 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -81,6 +81,7 @@ static void ui_add_link(bContext *C, uiBut *from, uiBut *to); #define BUTTON_TOOLTIP_DELAY 0.500 #define BUTTON_FLASH_DELAY 0.020 +#define MENU_SCROLL_INTERVAL 0.1 #define BUTTON_AUTO_OPEN_THRESH 0.3 #define BUTTON_MOUSE_TOWARDS_THRESH 1.0 @@ -262,14 +263,12 @@ static int ui_is_a_warp_but(uiBut *but) static int ui_is_utf8_but(uiBut *but) { if (but->rnaprop) { - int subtype= RNA_property_subtype(but->rnaprop); - - if(ELEM3(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) { - return TRUE; - } + const int subtype= RNA_property_subtype(but->rnaprop); + return !(ELEM3(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)); + } + else { + return !(but->flag & UI_BUT_NO_UTF8); } - - return !(but->flag & UI_BUT_NO_UTF8); } /* ********************** button apply/revert ************************/ @@ -300,7 +299,7 @@ static void ui_apply_but_func(bContext *C, uiBut *but) after->func_arg3= but->func_arg3; after->funcN= but->funcN; - after->func_argN= but->func_argN; + after->func_argN= MEM_dupallocN(but->func_argN); after->rename_func= but->rename_func; after->rename_arg1= but->rename_arg1; @@ -404,6 +403,8 @@ static void ui_apply_but_funcs_after(bContext *C) after.func(C, after.func_arg1, after.func_arg2); if(after.funcN) after.funcN(C, after.func_argN, after.func_arg2); + if(after.func_argN) + MEM_freeN(after.func_argN); if(after.handle_func) after.handle_func(C, after.handle_func_arg, after.retval); @@ -1679,7 +1680,7 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data) static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data) { if(but) { - if(!ui_is_utf8_but(but)) { + if(ui_is_utf8_but(but)) { int strip= BLI_utf8_invalid_strip(but->editstr, strlen(but->editstr)); /* not a file?, strip non utf-8 chars */ if(strip) { @@ -1878,7 +1879,6 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle if(but->autocomplete_func || data->searchbox) { changed= ui_textedit_autocomplete(C, but, data); update= 1; /* do live update for tab key */ - retval= WM_UI_HANDLER_BREAK; } /* the hotkey here is not well defined, was G.qual so we check all */ else if(event->shift || event->ctrl || event->alt || event->oskey) { @@ -1894,7 +1894,15 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle } if(event->ascii && (retval == WM_UI_HANDLER_CONTINUE)) { - changed= ui_textedit_type_ascii(but, data, event->ascii); + char ascii = event->ascii; + + /* exception that's useful for number buttons, some keyboard + numpads have a comma instead of a period */ + if(ELEM3(but->type, NUM, NUMABS, NUMSLI)) + if(event->type == PADPERIOD && ascii == ',') + ascii = '.'; + + changed= ui_textedit_type_ascii(but, data, ascii); retval= WM_UI_HANDLER_BREAK; } @@ -2316,8 +2324,8 @@ static float ui_numedit_apply_snapf(uiBut *but, float tempf, float softmin, floa if(fac != 1.0f) { /* snap in unit-space */ tempf /= fac; - softmin /= fac; - softmax /= fac; + /* softmin /= fac; */ /* UNUSED */ + /* softmax /= fac; */ /* UNUSED */ softrange /= fac; } @@ -3460,13 +3468,13 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap, CurveMapping *cumap= (CurveMapping*)but->poin; CurveMap *cuma= cumap->cm+cumap->cur; CurveMapPoint *cmp= cuma->curve; - float fx, fy, zoomx, zoomy, offsx, offsy; + float fx, fy, zoomx, zoomy /*, offsx, offsy */ /* UNUSED */; int a, changed= 0; zoomx= (but->x2-but->x1)/(cumap->curr.xmax-cumap->curr.xmin); zoomy= (but->y2-but->y1)/(cumap->curr.ymax-cumap->curr.ymin); - offsx= cumap->curr.xmin; - offsy= cumap->curr.ymin; + /* offsx= cumap->curr.xmin; */ + /* offsy= cumap->curr.ymin; */ if(snap) { float d[2]; @@ -4022,12 +4030,9 @@ static int ui_do_but_CHARTAB(bContext *UNUSED(C), uiBlock *UNUSED(block), uiBut static int ui_do_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data, wmEvent *event) -{ - ARegion *ar= CTX_wm_region(C); - - but->linkto[0]= event->x-ar->winrct.xmin; - but->linkto[1]= event->y-ar->winrct.ymin; - +{ + VECCOPY2D(but->linkto, event->mval); + if(data->state == BUTTON_STATE_HIGHLIGHT) { if(event->type == LEFTMOUSE && event->val==KM_PRESS) { button_activate_state(C, but, BUTTON_STATE_WAIT_RELEASE); @@ -4445,10 +4450,10 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event) } /* reset to default */ /* XXX hardcoded keymap check.... */ - else if(ELEM(event->type, ZEROKEY, PAD0) && event->val == KM_PRESS) { - /* ctrl-0 = for arrays, only the active one gets done (vs whole array for just 0) */ + else if(ELEM(event->type, DELKEY, PADPERIOD) && event->val == KM_PRESS) { + /* ctrl+del - reset active button; del - reset a whole array*/ if (!(ELEM3(but->type, HSVCIRCLE, HSVCUBE, HISTOGRAM))) - ui_set_but_default(C, but, !event->ctrl); + ui_set_but_default(C, !event->ctrl); } /* handle menu */ else if(event->type == RIGHTMOUSE && event->val == KM_PRESS) { @@ -4746,6 +4751,8 @@ static uiBut *ui_but_find_mouse_over(ARegion *ar, int x, int y) continue; if(but->flag & UI_HIDDEN) continue; + if(but->flag & UI_SCROLLED) + continue; if(ui_but_contains_pt(but, mx, my)) butover= but; } @@ -5534,10 +5541,6 @@ static int ui_mouse_motion_towards_check(uiBlock *block, uiPopupBlockHandle *men int closer; if(!menu->dotowards) return 0; - if((block->direction & UI_TOP) || (block->direction & UI_DOWN)) { - menu->dotowards= 0; - return menu->dotowards; - } /* verify that we are moving towards one of the edges of the * menu block, in other words, in the triangle formed by the @@ -5579,6 +5582,76 @@ static int ui_mouse_motion_towards_check(uiBlock *block, uiPopupBlockHandle *men return menu->dotowards; } +static char ui_menu_scroll_test(uiBlock *block, int my) +{ + if(block->flag & (UI_BLOCK_CLIPTOP|UI_BLOCK_CLIPBOTTOM)) { + if(block->flag & UI_BLOCK_CLIPTOP) + if(my > block->maxy-14) + return 't'; + if(block->flag & UI_BLOCK_CLIPBOTTOM) + if(my < block->miny+14) + return 'b'; + } + return 0; +} + +static int ui_menu_scroll(ARegion *ar, uiBlock *block, int my) +{ + char test= ui_menu_scroll_test(block, my); + + if(test) { + uiBut *b1= block->buttons.first; + uiBut *b2= block->buttons.last; + uiBut *bnext; + uiBut *bprev; + int dy= 0; + + /* get first and last visible buttons */ + while(b1 && ui_but_next(b1) && (b1->flag & UI_SCROLLED)) + b1= ui_but_next(b1); + while(b2 && ui_but_prev(b2) && (b2->flag & UI_SCROLLED)) + b2= ui_but_prev(b2); + /* skips separators */ + bnext= ui_but_next(b1); + bprev= ui_but_prev(b2); + + if(bnext==NULL || bprev==NULL) + return 0; + + if(test=='t') { + /* bottom button is first button */ + if(b1->y1 < b2->y1) + dy= bnext->y1 - b1->y1; + /* bottom button is last button */ + else + dy= bprev->y1 - b2->y1; + } + else if(test=='b') { + /* bottom button is first button */ + if(b1->y1 < b2->y1) + dy= b1->y1 - bnext->y1; + /* bottom button is last button */ + else + dy= b2->y1 - bprev->y1; + } + if(dy) { + + for(b1= block->buttons.first; b1; b1= b1->next) { + b1->y1 -= dy; + b1->y2 -= dy; + } + /* set flags again */ + ui_popup_block_scrolltest(block); + + ED_region_tag_redraw(ar); + + return 1; + } + } + + return 0; +} + static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle *menu, int UNUSED(topmenu)) { ARegion *ar; @@ -5610,11 +5683,22 @@ static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle * and don't handle events */ ui_mouse_motion_towards_init(menu, mx, my, 1); } - else if(event->type != TIMER) { + else if(event->type == TIMER) { + if(event->customdata == menu->scrolltimer) + ui_menu_scroll(ar, block, my); + } + else { /* for ui_mouse_motion_towards_block */ - if(event->type == MOUSEMOVE) + if(event->type == MOUSEMOVE) { ui_mouse_motion_towards_init(menu, mx, my, 0); - + + /* add menu scroll timer, if needed */ + if(ui_menu_scroll_test(block, my)) + if(menu->scrolltimer==NULL) + menu->scrolltimer= + WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, MENU_SCROLL_INTERVAL); + } + /* first block own event func */ if(block->block_event_func && block->block_event_func(C, block, event)); /* events not for active search menu button */ |