diff options
author | Ton Roosendaal <ton@blender.org> | 2008-12-15 19:54:47 +0300 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2008-12-15 19:54:47 +0300 |
commit | a16df53619a2ab3b41c0cbcf6f9e01a9bf370c9c (patch) | |
tree | a96b757fd2a791c242b6ace94b22e465bac9b1d2 /source/blender/editors | |
parent | c13bb258b1149d8bbfb97b896a58cd748e7cd861 (diff) |
2.5
Mouse cursors now work again
- centralized screen-level cursor changes, no more operator
running for it.
- spacetypes have callback to check/set individual cursor
types. Use notifier SCREEN_CHANGED to make sure it works
on mode changes etc.
- new calls WM_cursor_modal() and WM_cursor_restore() to
make temporarily cursor types during modes.
- used above for view2d cursors.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/interface/view2d_ops.c | 20 | ||||
-rw-r--r-- | source/blender/editors/screen/area.c | 1 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_edit.c | 85 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_intern.h | 5 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 91 | ||||
-rw-r--r-- | source/blender/editors/space_text/space_text.c | 13 |
6 files changed, 109 insertions, 106 deletions
diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index d84932c82fe..3c9172b8a28 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -209,14 +209,12 @@ static int view_pan_invoke(bContext *C, wmOperator *op, wmEvent *event) RNA_int_set(op->ptr, "deltax", 0); RNA_int_set(op->ptr, "deltay", 0); -#if 0 // XXX - enable this when cursors are working properly if (v2d->keepofs & V2D_LOCKOFS_X) - WM_set_cursor(C, BC_NS_SCROLLCURSOR); + WM_cursor_modal(C->window, BC_NS_SCROLLCURSOR); else if (v2d->keepofs & V2D_LOCKOFS_Y) - WM_set_cursor(C, BC_EW_SCROLLCURSOR); + WM_cursor_modal(C->window, BC_EW_SCROLLCURSOR); else - WM_set_cursor(C, BC_NSEW_SCROLLCURSOR); -#endif // XXX - enable this when cursors are working properly + WM_cursor_modal(C->window, BC_NSEW_SCROLLCURSOR); /* add temp handler */ WM_event_add_modal_handler(C, &C->window->handlers, op); @@ -251,7 +249,7 @@ static int view_pan_modal(bContext *C, wmOperator *op, wmEvent *event) RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty)); view_pan_exit(C, op); - //WM_set_cursor(C, CURSOR_STD); // XXX - enable this when cursors are working properly + WM_cursor_restore(C->window); return OPERATOR_FINISHED; } @@ -689,14 +687,12 @@ static int view_zoomdrag_invoke(bContext *C, wmOperator *op, wmEvent *event) RNA_float_set(op->ptr, "deltax", 0); RNA_float_set(op->ptr, "deltay", 0); -#if 0 // XXX - enable this when cursors are working properly if (v2d->keepofs & V2D_LOCKOFS_X) - WM_set_cursor(C, BC_NS_SCROLLCURSOR); + WM_cursor_modal(C->window, BC_NS_SCROLLCURSOR); else if (v2d->keepofs & V2D_LOCKOFS_Y) - WM_set_cursor(C, BC_EW_SCROLLCURSOR); + WM_cursor_modal(C->window, BC_EW_SCROLLCURSOR); else - WM_set_cursor(C, BC_NSEW_SCROLLCURSOR); -#endif // XXX - enable this when cursors are working properly + WM_cursor_modal(C->window, BC_NSEW_SCROLLCURSOR); /* add temp handler */ WM_event_add_modal_handler(C, &C->window->handlers, op); @@ -784,7 +780,7 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, wmEvent *event) /* free customdata */ view_zoomdrag_exit(C, op); - //WM_set_cursor(C, CURSOR_STD); // XXX - enable this when cursors are working properly + WM_cursor_restore(C->window); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index fc6ed8cee54..da7c38819a2 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -503,6 +503,7 @@ static void newspace(bContext *C, ScrArea *sa, int type) sa->spacetype= type; sa->butspacetype= type; + sa->type= st; /* check previously stored space */ for (sl= sa->spacedata.first; sl; sl= sl->next) diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index 1c0b8932d94..2cf480dc204 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -236,6 +236,39 @@ void removenotused_scredges(bScreen *sc) } } +int scredge_is_horizontal(ScrEdge *se) +{ + return (se->v1->vec.y == se->v2->vec.y); +} + +ScrEdge *screen_find_active_scredge(bScreen *sc, int mx, int my) +{ + ScrEdge *se; + + for (se= sc->edgebase.first; se; se= se->next) { + if (scredge_is_horizontal(se)) { + short min, max; + min= MIN2(se->v1->vec.x, se->v2->vec.x); + max= MAX2(se->v1->vec.x, se->v2->vec.x); + + if (abs(my-se->v1->vec.y)<=2 && mx>=min && mx<=max) + return se; + } + else { + short min, max; + min= MIN2(se->v1->vec.y, se->v2->vec.y); + max= MAX2(se->v1->vec.y, se->v2->vec.y); + + if (abs(mx-se->v1->vec.x)<=2 && my>=min && my<=max) + return se; + } + } + + return NULL; +} + + + /* adds no space data */ static ScrArea *screen_addarea(bScreen *sc, ScrVert *v1, ScrVert *v2, ScrVert *v3, ScrVert *v4, short headertype, short spacetype) { @@ -962,6 +995,8 @@ void ED_screen_refresh(wmWindowManager *wm, wmWindow *win) if(G.f & G_DEBUG) printf("set screen\n"); win->screen->do_refresh= 0; + /* cursor types too */ + ED_screen_set_subwinactive(win); } /* file read, set all screens, ... */ @@ -1017,6 +1052,29 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen) C->window= prevwin; } +/* case when on area-edge or in azones */ +static void screen_cursor_set(wmWindow *win, wmEvent *event) +{ + ScrArea *sa; + + for(sa= win->screen->areabase.first; sa; sa= sa->next) + if(is_in_area_actionzone(sa, event->x, event->y)) + break; + + if(sa) { + WM_cursor_set(win, CURSOR_EDIT); + } + else { + ScrEdge *actedge= screen_find_active_scredge(win->screen, event->x, event->y); + + if (actedge && scredge_is_horizontal(actedge)) { + WM_cursor_set(win, CURSOR_Y_MOVE); + } else { + WM_cursor_set(win, CURSOR_X_MOVE); + } + } +} + /* called in wm_event_system.c. sets state var in screen */ void ED_screen_set_subwinactive(wmWindow *win) @@ -1024,15 +1082,16 @@ void ED_screen_set_subwinactive(wmWindow *win) if(win->screen) { wmEvent *event= win->eventstate; ScrArea *sa; + ARegion *ar; int oldswin= win->screen->subwinactive; for(sa= win->screen->areabase.first; sa; sa= sa->next) { if(event->x > sa->totrct.xmin && event->x < sa->totrct.xmax) if(event->y > sa->totrct.ymin && event->y < sa->totrct.ymax) - break; + if(NULL==is_in_area_actionzone(sa, event->x, event->y)) + break; } if(sa) { - ARegion *ar; for(ar= sa->regionbase.first; ar; ar= ar->next) { if(BLI_in_rcti(&ar->winrct, event->x, event->y)) win->screen->subwinactive= ar->swinid; @@ -1043,9 +1102,8 @@ void ED_screen_set_subwinactive(wmWindow *win) /* check for redraw headers */ if(oldswin!=win->screen->subwinactive) { - + for(sa= win->screen->areabase.first; sa; sa= sa->next) { - ARegion *ar; int do_draw= 0; for(ar= sa->regionbase.first; ar; ar= ar->next) @@ -1059,6 +1117,25 @@ void ED_screen_set_subwinactive(wmWindow *win) } } } + + /* cursors, for time being set always on edges, otherwise aregion doesnt switch */ + if(win->screen->subwinactive==win->screen->mainwin) { + screen_cursor_set(win, event); + } + else if(oldswin!=win->screen->subwinactive) { + /* cursor space type switching */ + for(sa= win->screen->areabase.first; sa; sa= sa->next) { + for(ar= sa->regionbase.first; ar; ar= ar->next) { + if(ar->swinid==win->screen->subwinactive) { + if(sa->type->cursor) + sa->type->cursor(win, ar); + else + WM_cursor_set(win, CURSOR_STD); + } + } + + } + } } } diff --git a/source/blender/editors/screen/screen_intern.h b/source/blender/editors/screen/screen_intern.h index d228748d873..855fe7c9b50 100644 --- a/source/blender/editors/screen/screen_intern.h +++ b/source/blender/editors/screen/screen_intern.h @@ -46,6 +46,11 @@ void removenotused_scrverts(bScreen *sc); void removedouble_scrverts(bScreen *sc); void removedouble_scredges(bScreen *sc); void removenotused_scredges(bScreen *sc); +int scredge_is_horizontal(ScrEdge *se); +ScrEdge *screen_find_active_scredge(bScreen *sc, int mx, int my); + +AZone *is_in_area_actionzone(ScrArea *sa, int x, int y); + #endif /* ED_SCREEN_INTERN_H */ diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 1f7563b4824..d16ad075bf3 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -118,7 +118,7 @@ static ScrArea *screen_areahascursor(bScreen *scr, int x, int y) } -static AZone *is_in_area_actionzone(ScrArea *sa, int x, int y) +AZone *is_in_area_actionzone(ScrArea *sa, int x, int y) { AZone *az= NULL; int i= 0; @@ -232,78 +232,6 @@ void ED_SCR_OT_actionzone(wmOperatorType *ot) ot->poll= ED_operator_areaactive; } -/* ****************** cursor near edge operator ********************************* */ - -static int scredge_is_horizontal(ScrEdge *se) -{ - return (se->v1->vec.y == se->v2->vec.y); -} - -static ScrEdge *screen_find_active_scredge(bScreen *sc, int mx, int my) -{ - ScrEdge *se; - - for (se= sc->edgebase.first; se; se= se->next) { - if (scredge_is_horizontal(se)) { - short min, max; - min= MIN2(se->v1->vec.x, se->v2->vec.x); - max= MAX2(se->v1->vec.x, se->v2->vec.x); - - if (abs(my-se->v1->vec.y)<=2 && mx>=min && mx<=max) - return se; - } - else { - short min, max; - min= MIN2(se->v1->vec.y, se->v2->vec.y); - max= MAX2(se->v1->vec.y, se->v2->vec.y); - - if (abs(mx-se->v1->vec.x)<=2 && my>=min && my<=max) - return se; - } - } - - return NULL; -} - - -/* operator cb */ -static int screen_cursor_test(bContext *C, wmOperator *op, wmEvent *event) -{ - if (C->screen->subwinactive==C->screen->mainwin) { - ScrEdge *actedge= screen_find_active_scredge(C->screen, event->x, event->y); - - if (actedge && scredge_is_horizontal(actedge)) { - WM_set_cursor(C, CURSOR_Y_MOVE); - } else { - WM_set_cursor(C, CURSOR_X_MOVE); - } - } - else { - ScrArea *sa= NULL; - AZone *az= NULL; - - for(sa= C->screen->areabase.first; sa; sa= sa->next) { - az= is_in_area_actionzone(sa, event->x, event->y); - if(az!=NULL) break; - } - - if(az!=NULL) WM_set_cursor(C, CURSOR_EDIT); - else WM_set_cursor(C, CURSOR_STD); - } - - return OPERATOR_PASS_THROUGH; -} - -static void ED_SCR_OT_cursor_type(wmOperatorType *ot) -{ - ot->name= "Cursor type"; - ot->idname= "ED_SCR_OT_cursor_type"; - - ot->invoke= screen_cursor_test; - ot->poll= ED_operator_screenactive; -} - - /* *********** Rip area operator ****************** */ @@ -1224,12 +1152,6 @@ static int region_split_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static int region_split_invoke(bContext *C, wmOperator *op, wmEvent *evt) -{ - return region_split_exec(C, op); -} - - void ED_SCR_OT_region_split(wmOperatorType *ot) { PropertyRNA *prop; @@ -1240,8 +1162,6 @@ void ED_SCR_OT_region_split(wmOperatorType *ot) /* api callbacks */ ot->exec= region_split_exec; - ot->invoke= region_split_invoke; - ot->poll= ED_operator_areaactive; prop= RNA_def_property(ot->srna, "dir", PROP_ENUM, PROP_NONE); @@ -1346,7 +1266,6 @@ void ED_SCR_OT_border_select(wmOperatorType *ot) void ED_operatortypes_screen(void) { /* generic UI stuff */ - WM_operatortype_append(ED_SCR_OT_cursor_type); WM_operatortype_append(ED_SCR_OT_actionzone); WM_operatortype_append(ED_SCR_OT_repeat_last); @@ -1367,9 +1286,7 @@ void ED_operatortypes_screen(void) void ED_keymap_screen(wmWindowManager *wm) { ListBase *keymap= WM_keymap_listbase(wm, "Screen", 0, 0); - wmKeymapItem *kmi; - WM_keymap_verify_item(keymap, "ED_SCR_OT_cursor_type", MOUSEMOVE, 0, 0, 0); WM_keymap_verify_item(keymap, "ED_SCR_OT_actionzone", LEFTMOUSE, KM_PRESS, 0, 0); WM_keymap_verify_item(keymap, "ED_SCR_OT_area_move", LEFTMOUSE, KM_PRESS, 0, 0); @@ -1378,10 +1295,8 @@ void ED_keymap_screen(wmWindowManager *wm) WM_keymap_verify_item(keymap, "ED_SCR_OT_area_rip", RKEY, KM_PRESS, KM_ALT, 0); /* tests */ - kmi= WM_keymap_add_item(keymap, "ED_SCR_OT_region_split", SKEY, KM_PRESS, 0, 0); - RNA_enum_set(kmi->ptr, "dir", 'h'); - kmi= WM_keymap_add_item(keymap, "ED_SCR_OT_region_split", SKEY, KM_PRESS, KM_SHIFT, 0); - RNA_enum_set(kmi->ptr, "dir", 'v'); + RNA_enum_set(WM_keymap_add_item(keymap, "ED_SCR_OT_region_split", SKEY, KM_PRESS, 0, 0)->ptr, "dir", 'h'); + RNA_enum_set(WM_keymap_add_item(keymap, "ED_SCR_OT_region_split", SKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "dir", 'v'); WM_keymap_add_item(keymap, "ED_SCR_OT_region_flip", F5KEY, KM_PRESS, 0, 0); WM_keymap_verify_item(keymap, "ED_SCR_OT_repeat_last", F4KEY, KM_PRESS, 0, 0); } diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 54ec53b2434..5b52e43d0f2 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -153,12 +153,20 @@ static void text_main_area_draw(const bContext *C, ARegion *ar) /* scrollers? */ } -void text_operatortypes(void) +static void text_operatortypes(void) { } -void text_keymap(struct wmWindowManager *wm) +static void text_cursor(wmWindow *win, ARegion *ar) +{ + if(ar->regiontype==RGN_TYPE_WINDOW) + WM_cursor_set(win, BC_TEXTEDITCURSOR); + else + WM_cursor_set(win, CURSOR_STD); +} + +static void text_keymap(struct wmWindowManager *wm) { } @@ -209,6 +217,7 @@ void ED_spacetype_text(void) st->init= text_init; st->duplicate= text_duplicate; st->operatortypes= text_operatortypes; + st->cursor= text_cursor; st->keymap= text_keymap; /* regions: main window */ |