Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_dragdrop.c
| Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid) | ||||
| dm->regionid = regionid; | dm->regionid = regionid; | ||||
| BLI_addtail(&dropboxes, dm); | BLI_addtail(&dropboxes, dm); | ||||
| return &dm->dropboxes; | return &dm->dropboxes; | ||||
| } | } | ||||
| wmDropBox *WM_dropbox_add(ListBase *lb, | wmDropBox *WM_dropbox_add(ListBase *lb, | ||||
| const char *idname, | const char *idname, | ||||
| bool (*poll)(bContext *, wmDrag *, const wmEvent *, const char **), | bool (*poll)(bContext *, wmDrag *, const wmEvent *), | ||||
| void (*copy)(wmDrag *, wmDropBox *), | void (*copy)(wmDrag *, wmDropBox *), | ||||
| void (*cancel)(struct Main *, wmDrag *, wmDropBox *)) | void (*cancel)(struct Main *, wmDrag *, wmDropBox *), | ||||
| WMDropboxTooltipFunc tooltip) | |||||
| { | { | ||||
| wmDropBox *drop = MEM_callocN(sizeof(wmDropBox), "wmDropBox"); | wmDropBox *drop = MEM_callocN(sizeof(wmDropBox), "wmDropBox"); | ||||
| drop->poll = poll; | drop->poll = poll; | ||||
| drop->copy = copy; | drop->copy = copy; | ||||
| drop->cancel = cancel; | drop->cancel = cancel; | ||||
| drop->tooltip = tooltip; | |||||
| drop->ot = WM_operatortype_find(idname, 0); | drop->ot = WM_operatortype_find(idname, 0); | ||||
| drop->opcontext = WM_OP_INVOKE_DEFAULT; | drop->opcontext = WM_OP_INVOKE_DEFAULT; | ||||
| if (drop->ot == NULL) { | if (drop->ot == NULL) { | ||||
| MEM_freeN(drop); | MEM_freeN(drop); | ||||
| printf("Error: dropbox with unknown operator: %s\n", idname); | printf("Error: dropbox with unknown operator: %s\n", idname); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | |||||
| void WM_drag_free_list(struct ListBase *lb) | void WM_drag_free_list(struct ListBase *lb) | ||||
| { | { | ||||
| wmDrag *drag; | wmDrag *drag; | ||||
| while ((drag = BLI_pophead(lb))) { | while ((drag = BLI_pophead(lb))) { | ||||
| WM_drag_free(drag); | WM_drag_free(drag); | ||||
| } | } | ||||
| } | } | ||||
| static const char *dropbox_active(bContext *C, | static char *dropbox_tooltip(bContext *C, | ||||
| wmDrag *drag, | |||||
| const wmEvent *event, | |||||
| const wmDropBox *drop) | |||||
| { | |||||
| char *tooltip = NULL; | |||||
| if (drop->tooltip) { | |||||
| tooltip = drop->tooltip(C, drag, event); | |||||
| } | |||||
| if (!tooltip) { | |||||
| tooltip = BLI_strdup(WM_operatortype_name(drop->ot, drop->ptr)); | |||||
| } | |||||
| /* XXX Doing translation here might not be ideal, but later we have no more | |||||
| * access to ot (and hence op context)... */ | |||||
| return tooltip; | |||||
| } | |||||
| static wmDropBox *dropbox_active(bContext *C, | |||||
| ListBase *handlers, | ListBase *handlers, | ||||
| wmDrag *drag, | wmDrag *drag, | ||||
| const wmEvent *event) | const wmEvent *event) | ||||
| { | { | ||||
| LISTBASE_FOREACH (wmEventHandler *, handler_base, handlers) { | LISTBASE_FOREACH (wmEventHandler *, handler_base, handlers) { | ||||
| if (handler_base->type == WM_HANDLER_TYPE_DROPBOX) { | if (handler_base->type == WM_HANDLER_TYPE_DROPBOX) { | ||||
| wmEventHandler_Dropbox *handler = (wmEventHandler_Dropbox *)handler_base; | wmEventHandler_Dropbox *handler = (wmEventHandler_Dropbox *)handler_base; | ||||
| if (handler->dropboxes) { | if (handler->dropboxes) { | ||||
| LISTBASE_FOREACH (wmDropBox *, drop, handler->dropboxes) { | LISTBASE_FOREACH (wmDropBox *, drop, handler->dropboxes) { | ||||
| const char *tooltip = NULL; | if (drop->poll(C, drag, event) && | ||||
| if (drop->poll(C, drag, event, &tooltip) && | |||||
| WM_operator_poll_context(C, drop->ot, drop->opcontext)) { | WM_operator_poll_context(C, drop->ot, drop->opcontext)) { | ||||
| /* XXX Doing translation here might not be ideal, but later we have no more | return drop; | ||||
| * access to ot (and hence op context)... */ | |||||
| return (tooltip) ? tooltip : WM_operatortype_name(drop->ot, drop->ptr); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* return active operator name when mouse is in box */ | /* return active operator tooltip/name when mouse is in box */ | ||||
| static const char *wm_dropbox_active(bContext *C, wmDrag *drag, const wmEvent *event) | static char *wm_dropbox_active(bContext *C, wmDrag *drag, const wmEvent *event) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| wmDropBox *drop = dropbox_active(C, &win->handlers, drag, event); | |||||
| if (!drop) { | |||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| ARegion *region = CTX_wm_region(C); | drop = dropbox_active(C, &area->handlers, drag, event); | ||||
| const char *name; | |||||
| name = dropbox_active(C, &win->handlers, drag, event); | |||||
| if (name) { | |||||
| return name; | |||||
| } | } | ||||
| if (!drop) { | |||||
| name = dropbox_active(C, &area->handlers, drag, event); | ARegion *region = CTX_wm_region(C); | ||||
| if (name) { | drop = dropbox_active(C, ®ion->handlers, drag, event); | ||||
| return name; | |||||
| } | } | ||||
| if (drop) { | |||||
| name = dropbox_active(C, ®ion->handlers, drag, event); | return dropbox_tooltip(C, drag, event, drop); | ||||
| if (name) { | |||||
| return name; | |||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| static void wm_drop_operator_options(bContext *C, wmDrag *drag, const wmEvent *event) | static void wm_drop_operator_options(bContext *C, wmDrag *drag, const wmEvent *event) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| const int winsize_x = WM_window_pixels_x(win); | const int winsize_x = WM_window_pixels_x(win); | ||||
| const int winsize_y = WM_window_pixels_y(win); | const int winsize_y = WM_window_pixels_y(win); | ||||
| /* for multiwin drags, we only do this if mouse inside */ | /* for multiwin drags, we only do this if mouse inside */ | ||||
| if (event->x < 0 || event->y < 0 || event->x > winsize_x || event->y > winsize_y) { | if (event->x < 0 || event->y < 0 || event->x > winsize_x || event->y > winsize_y) { | ||||
| return; | return; | ||||
| } | } | ||||
| drag->opname[0] = 0; | drag->tooltip[0] = 0; | ||||
| /* check buttons (XXX todo rna and value) */ | /* check buttons (XXX todo rna and value) */ | ||||
| if (UI_but_active_drop_name(C)) { | if (UI_but_active_drop_name(C)) { | ||||
| BLI_strncpy(drag->opname, IFACE_("Paste name"), sizeof(drag->opname)); | BLI_strncpy(drag->tooltip, IFACE_("Paste name"), sizeof(drag->tooltip)); | ||||
| } | } | ||||
| else { | else { | ||||
| const char *opname = wm_dropbox_active(C, drag, event); | char *tooltip = wm_dropbox_active(C, drag, event); | ||||
| if (opname) { | if (tooltip) { | ||||
| BLI_strncpy(drag->opname, opname, sizeof(drag->opname)); | BLI_strncpy(drag->tooltip, tooltip, sizeof(drag->tooltip)); | ||||
| MEM_freeN(tooltip); | |||||
| // WM_cursor_modal_set(win, WM_CURSOR_COPY); | // WM_cursor_modal_set(win, WM_CURSOR_COPY); | ||||
| } | } | ||||
| // else | // else | ||||
| // WM_cursor_modal_restore(win); | // WM_cursor_modal_restore(win); | ||||
| /* unsure about cursor type, feels to be too much */ | /* unsure about cursor type, feels to be too much */ | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | if (rect) { | ||||
| int w = UI_fontstyle_string_width(fstyle, wm_drag_name(drag)); | int w = UI_fontstyle_string_width(fstyle, wm_drag_name(drag)); | ||||
| drag_rect_minmax(rect, x, y, x + w, y + iconsize); | drag_rect_minmax(rect, x, y, x + w, y + iconsize); | ||||
| } | } | ||||
| else { | else { | ||||
| UI_fontstyle_draw_simple(fstyle, x, y, wm_drag_name(drag), text_col); | UI_fontstyle_draw_simple(fstyle, x, y, wm_drag_name(drag), text_col); | ||||
| } | } | ||||
| /* operator name with roundbox */ | /* operator name with roundbox */ | ||||
| if (drag->opname[0]) { | if (drag->tooltip[0]) { | ||||
| if (drag->imb) { | if (drag->imb) { | ||||
| x = cursorx - drag->sx / 2; | x = cursorx - drag->sx / 2; | ||||
| if (cursory + drag->sy / 2 + padding + iconsize < winsize_y) { | if (cursory + drag->sy / 2 + padding + iconsize < winsize_y) { | ||||
| y = cursory + drag->sy / 2 + padding; | y = cursory + drag->sy / 2 + padding; | ||||
| } | } | ||||
| else { | else { | ||||
| y = cursory - drag->sy / 2 - padding - iconsize - padding - iconsize; | y = cursory - drag->sy / 2 - padding - iconsize - padding - iconsize; | ||||
| Show All 10 Lines | if (drag->tooltip[0]) { | ||||
| } | } | ||||
| } | } | ||||
| if (rect) { | if (rect) { | ||||
| int w = UI_fontstyle_string_width(fstyle, wm_drag_name(drag)); | int w = UI_fontstyle_string_width(fstyle, wm_drag_name(drag)); | ||||
| drag_rect_minmax(rect, x, y, x + w, y + iconsize); | drag_rect_minmax(rect, x, y, x + w, y + iconsize); | ||||
| } | } | ||||
| else { | else { | ||||
| wm_drop_operator_draw(drag->opname, x, y); | wm_drop_operator_draw(drag->tooltip, x, y); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| GPU_blend(GPU_BLEND_NONE); | GPU_blend(GPU_BLEND_NONE); | ||||
| } | } | ||||