diff options
author | Ton Roosendaal <ton@blender.org> | 2008-11-18 16:51:02 +0300 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2008-11-18 16:51:02 +0300 |
commit | 13ac9079cccff2364c42ffdc708ea951dbe410ca (patch) | |
tree | 16226593a5d676f32a4ddd6f4000e84d233fa2be /source | |
parent | c3da1af01c1584a8e23b9c6875bcb784fec00ed5 (diff) |
Cleanup of area-rip operator
- moved from WM to Screen code (it uses active area)
- less code :) result of cleaning some calls
- added WM_window_open() to WM API for this
- now opens new window on top of area, and leaves old screen unaffected
(simple, atomic, the 'do not think for user' convention :)
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/ED_screen.h | 1 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_edit.c | 82 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 3 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm.c | 4 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 11 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_window.c | 162 | ||||
-rw-r--r-- | source/blender/windowmanager/wm_window.h | 2 |
9 files changed, 134 insertions, 134 deletions
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index b5b059c7a00..a6c45ed17be 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -59,7 +59,6 @@ void ED_screen_gesture(struct wmWindow *win); void ED_screen_refresh(struct wmWindowManager *wm, struct wmWindow *win); void ED_screen_do_listen(struct wmWindow *win, struct wmNotifier *note); bScreen *ED_screen_duplicate(struct wmWindow *win, bScreen *sc); -bScreen *ED_screen_riparea(struct wmWindow *win, bScreen *sc, struct ScrArea *sa); void ED_screen_set_subwinactive(struct wmWindow *win); void ED_screen_exit(struct bContext *C, struct wmWindow *window, bScreen *screen); diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index 46cc0723624..4c255b8362c 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -492,6 +492,7 @@ static void select_connected_scredge(bScreen *sc, ScrEdge *edge) } } +/* adds no space data */ static ScrArea *screen_addarea(bScreen *sc, ScrVert *v1, ScrVert *v2, ScrVert *v3, ScrVert *v4, short headertype, short spacetype) { ScrArea *sa= MEM_callocN(sizeof(ScrArea), "addscrarea"); @@ -520,14 +521,18 @@ static void screen_delarea(bScreen *sc, ScrArea *sa) */ int screen_join_areas(bScreen *scr, ScrArea *sa1, ScrArea *sa2); -static bScreen *addscreen_area(wmWindow *win, char *name, short headertype, short spacetype) +/* empty screen, with 1 dummy area without spacedata */ +/* uses window size */ +static bScreen *screen_add(wmWindow *win, char *name) { bScreen *sc; ScrVert *sv1, *sv2, *sv3, *sv4; sc= alloc_libblock(&G.main->screen, ID_SCR, name); - sc->scene= G.scene; + sc->do_refresh= 1; + + win->screen= sc; sv1= screen_addvert(sc, 0, 0); sv2= screen_addvert(sc, 0, win->sizey-1); @@ -539,16 +544,12 @@ static bScreen *addscreen_area(wmWindow *win, char *name, short headertype, shor screen_addedge(sc, sv3, sv4); screen_addedge(sc, sv4, sv1); - screen_addarea(sc, sv1, sv2, sv3, sv4, headertype, spacetype); + /* dummy type, no spacedata */ + screen_addarea(sc, sv1, sv2, sv3, sv4, HEADERDOWN, SPACE_INFO); return sc; } -static bScreen *addscreen(wmWindow *win, char *name) -{ - return addscreen_area(win, name, HEADERDOWN, SPACE_INFO); -} - static void screen_copy(bScreen *to, bScreen *from) { ScrVert *s1, *s2; @@ -597,42 +598,61 @@ static void screen_copy(bScreen *to, bScreen *from) } -bScreen *ED_screen_riparea(struct wmWindow *win, bScreen *sc, struct ScrArea *sa) -{ - bScreen *newsc=NULL; - ScrArea *newa; - ScrArea *tsa; +/* *********** Rip area operator ****************** */ - if(sc->full != SCREENNORMAL) return NULL; /* XXX handle this case! */ - - /* make new screen: */ - newsc= addscreen_area(win, sc->id.name+2, sa->headertype, sa->spacetype); - /* new area is first (and only area) added to new win */ - newa = (ScrArea *)newsc->areabase.first; - area_copy_data(newa, sa, 0); +/* operator callback */ +/* (ton) removed attempt to merge ripped area with another, don't think this is desired functionality. + conventions: 'atomic' and 'dont think for user' :) */ +static int screen_area_rip_op(bContext *C, wmOperator *op) +{ + wmWindow *win; + bScreen *newsc; + rcti rect; + + /* poll() checks area context, but we don't accept full-area windows */ + if(C->screen->full != SCREENNORMAL) + return OPERATOR_CANCELLED; + + /* adds window to WM */ + rect= C->area->totrct; + BLI_translate_rcti(&rect, C->window->posx, C->window->posy); + win= WM_window_open(C, &rect); + + /* allocs new screen and adds to newly created window, using window size */ + newsc= screen_add(win, C->screen->id.name+2); + + /* copy area to new screen */ + area_copy_data((ScrArea *)newsc->areabase.first, C->area, 0); + + /* screen, areas init */ + WM_event_add_notifier(C->wm, win, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL); + + return OPERATOR_FINISHED; +} - /*remove the original area if possible*/ - for(tsa= sc->areabase.first; tsa; tsa= tsa->next) { - if (screen_join_areas(sc,tsa,sa)) - break; - } - removedouble_scredges(sc); - removenotused_scredges(sc); - removenotused_scrverts(sc); - return newsc; +void ED_SCR_OT_area_rip(wmOperatorType *ot) +{ + ot->name= "Rip Area into New Window"; + ot->idname= "ED_SCR_OT_area_rip"; + + ot->invoke= NULL; //WM_operator_confirm; + ot->exec= screen_area_rip_op; + ot->poll= ED_operator_areaactive; } +/* ********************************************* */ + bScreen *ED_screen_duplicate(wmWindow *win, bScreen *sc) { bScreen *newsc; if(sc->full != SCREENNORMAL) return NULL; /* XXX handle this case! */ - /* make new screen: */ - newsc= addscreen(win, sc->id.name+2); + /* make new empty screen: */ + newsc= screen_add(win, sc->id.name+2); /* copy all data */ screen_copy(newsc, sc); diff --git a/source/blender/editors/screen/screen_intern.h b/source/blender/editors/screen/screen_intern.h index 8f9a9877c89..b8e37a65a54 100644 --- a/source/blender/editors/screen/screen_intern.h +++ b/source/blender/editors/screen/screen_intern.h @@ -43,6 +43,7 @@ void ED_SCR_OT_move_areas(wmOperatorType *ot); void ED_SCR_OT_split_area(wmOperatorType *ot); void ED_SCR_OT_join_areas(wmOperatorType *ot); void ED_SCR_OT_actionzone(wmOperatorType *ot); +void ED_SCR_OT_area_rip(wmOperatorType *ot); #endif /* ED_SCREEN_INTERN_H */ diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index cf6352a724e..1857450313a 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -90,6 +90,7 @@ void ED_operatortypes_screen(void) WM_operatortype_append(ED_SCR_OT_move_areas); WM_operatortype_append(ED_SCR_OT_split_area); WM_operatortype_append(ED_SCR_OT_join_areas); + WM_operatortype_append(ED_SCR_OT_area_rip); } /* called in spacetypes.c */ @@ -101,5 +102,6 @@ void ED_keymap_screen(wmWindowManager *wm) WM_keymap_verify_item(&wm->screenkeymap, "ED_SCR_OT_move_areas", LEFTMOUSE, KM_PRESS, 0, 0); WM_keymap_verify_item(&wm->screenkeymap, "ED_SCR_OT_split_area", EVT_ACTIONZONE, 0, 0, 0); /* action tria */ WM_keymap_verify_item(&wm->screenkeymap, "ED_SCR_OT_join_areas", EVT_ACTIONZONE, 0, 0, 0); /* action tria */ + WM_keymap_verify_item(&wm->windowkeymap, "ED_SCR_OT_area_rip", RKEY, KM_PRESS, KM_ALT, 0); } diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 6df1601bd98..cf022e20660 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -35,6 +35,7 @@ struct bContext; struct wmEvent; struct wmEventHandler; struct wmGesture; +struct rcti; /* general API */ void WM_setprefsize (int stax, int stay, int sizx, int sizy); @@ -43,6 +44,8 @@ void WM_init (struct bContext *C); void WM_exit (struct bContext *C); void WM_main (struct bContext *C); +wmWindow *WM_window_open (struct bContext *C, struct rcti *rect); + /* files */ int WM_read_homefile (struct bContext *C, int from_memory); int WM_write_homefile (struct bContext *C, struct wmOperator *op); diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index a162670b226..d1429fc4f7f 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -81,7 +81,6 @@ static void wm_window_keymap(wmWindowManager *wm) { /* note, this doesn't replace existing keymap items */ WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_window_duplicate", AKEY, KM_PRESS, 0, 0); - WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_window_rip", RKEY, KM_PRESS, KM_ALT, 0); WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_window_fullscreen_toggle", FKEY, KM_PRESS, 0, 0); WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0); @@ -120,7 +119,8 @@ void wm_add_default(bContext *C) C->wm= wm; - win= wm_window_new(C, C->screen); + win= wm_window_new(C); + win->screen= C->screen; wm->winactive= win; wm_window_make_drawable(C, win); } diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 3c7465e1912..6e65e4917eb 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -98,16 +98,6 @@ static void WM_OT_window_duplicate(wmOperatorType *ot) ot->poll= WM_operator_winactive; } -static void WM_OT_window_rip(wmOperatorType *ot) -{ - ot->name= "Rip Area into New Window"; - ot->idname= "WM_OT_window_rip"; - - ot->invoke= wm_window_rip_op; //WM_operator_confirm; - ot->exec= NULL; - ot->poll= WM_operator_winactive; -} - static void WM_OT_save_homefile(wmOperatorType *ot) { ot->name= "Save User Settings"; @@ -266,7 +256,6 @@ void wm_operatortype_free(void) void wm_operatortype_init(void) { WM_operatortype_append(WM_OT_window_duplicate); - WM_operatortype_append(WM_OT_window_rip); WM_operatortype_append(WM_OT_save_homefile); WM_operatortype_append(WM_OT_window_fullscreen_toggle); WM_operatortype_append(WM_OT_exit_blender); diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 259e16a389a..687540d106f 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -21,7 +21,7 @@ * on ghostwinlay.c (C) 2001-2002 by NaN Holding BV * All rights reserved. * - * Contributor(s): Blender Foundation + * Contributor(s): Blender Foundation, 2008 * * ***** END GPL LICENSE BLOCK ***** */ @@ -125,118 +125,46 @@ static int find_free_winid(wmWindowManager *wm) } /* dont change context itself */ -wmWindow *wm_window_new(bContext *C, bScreen *screen) +wmWindow *wm_window_new(bContext *C) { wmWindow *win= MEM_callocN(sizeof(wmWindow), "window"); BLI_addtail(&C->wm->windows, win); win->winid= find_free_winid(C->wm); - win->screen= screen; return win; } + /* part of wm_window.c api */ wmWindow *wm_window_copy(bContext *C, wmWindow *winorig) { - wmWindow *win= wm_window_new(C, winorig->screen); + wmWindow *win= wm_window_new(C); win->posx= winorig->posx+10; win->posy= winorig->posy; win->sizex= winorig->sizex; win->sizey= winorig->sizey; - win->screen= ED_screen_duplicate(win, win->screen); + win->screen= ED_screen_duplicate(win, winorig->screen); win->screen->do_refresh= 1; win->screen->do_draw= 1; return win; } -/* operator callback */ -int wm_window_duplicate_op(bContext *C, wmOperator *op) -{ - wm_window_copy(C, C->window); - wm_check(C); - - return OPERATOR_FINISHED; -} - -wmWindow *wm_window_rip(bContext *C, wmWindow *winorig) -{ - wmWindow *win= wm_window_new(C, winorig->screen); - - win->posx= winorig->posx+10; - win->posy= winorig->posy; - win->sizex= C->area->winx; - win->sizey= C->area->winy; - - win->screen= ED_screen_riparea(win, win->screen, C->area); - C->area = NULL; /* is removed */ - win->screen->do_refresh= 1; - win->screen->do_draw= 1; - - return win; -} -/* operator callback */ -int wm_window_rip_op(bContext *C, wmOperator *op, wmEvent *event) -{ - /* need to make sure area is set in the current context */ - if (!C->area) { - ScrArea *sa= C->window->screen->areabase.first; - for(; sa; sa= sa->next) { - if(BLI_in_rcti(&sa->totrct, event->x, event->y)) { - C->area = sa; - break; - } - } - if(C->area==NULL) - return OPERATOR_CANCELLED; - } - - wm_window_rip(C, C->window); - wm_check(C); - WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL); - return OPERATOR_FINISHED; -} - - -/* fullscreen operator callback */ -int wm_window_fullscreen_toggle_op(bContext *C, wmOperator *op) -{ - GHOST_TWindowState state = GHOST_GetWindowState(C->window->ghostwin); - if(state!=GHOST_kWindowStateFullScreen) - GHOST_SetWindowState(C->window->ghostwin, GHOST_kWindowStateFullScreen); - else - GHOST_SetWindowState(C->window->ghostwin, GHOST_kWindowStateNormal); - - return OPERATOR_FINISHED; - -} - /* this is event from ghost */ static void wm_window_close(bContext *C, wmWindow *win) { BLI_remlink(&C->wm->windows, win); wm_window_free(C, win); - + if(C->wm->windows.first==NULL) WM_exit(C); } - -/* exit blender */ -int wm_exit_blender_op(bContext *C, wmOperator *op) -{ - wmWindow *win= C->wm->windows.first; - while(win) { - wm_window_close(C, win); - win= win->next; - } - return OPERATOR_FINISHED; -} - -static void wm_window_open(wmWindowManager *wm, char *title, wmWindow *win) +/* belongs to below */ +static void wm_window_add_ghostwindow(wmWindowManager *wm, char *title, wmWindow *win) { GHOST_WindowHandle ghostwin; GHOST_TWindowState inital_state; @@ -245,10 +173,10 @@ static void wm_window_open(wmWindowManager *wm, char *title, wmWindow *win) wm_get_screensize(&scr_w, &scr_h); posy= (scr_h - win->posy - win->sizey); -// inital_state = GHOST_kWindowStateFullScreen; -// inital_state = GHOST_kWindowStateMaximized; - inital_state = GHOST_kWindowStateNormal; - + // inital_state = GHOST_kWindowStateFullScreen; + // inital_state = GHOST_kWindowStateMaximized; + inital_state = GHOST_kWindowStateNormal; + #ifdef __APPLE__ { extern int macPrefState; /* creator.c */ @@ -263,7 +191,7 @@ static void wm_window_open(wmWindowManager *wm, char *title, wmWindow *win) 0 /* no stereo */); if (ghostwin) { - + win->ghostwin= ghostwin; GHOST_SetWindowUserData(ghostwin, win); /* pointer back */ @@ -278,13 +206,14 @@ static void wm_window_open(wmWindowManager *wm, char *title, wmWindow *win) glClearColor(.55, .55, .55, 0.0); glClear(GL_COLOR_BUFFER_BIT); wm_window_swap_buffers(win); - + /* standard state vars for window */ glEnable(GL_SCISSOR_TEST); } } /* for wmWindows without ghostwin, open these and clear */ +/* window size is read from window, if 0 it uses prefsize */ void wm_window_add_ghostwindows(wmWindowManager *wm) { wmWindow *win; @@ -296,7 +225,7 @@ void wm_window_add_ghostwindows(wmWindowManager *wm) #ifdef __APPLE__ { extern void wm_set_apple_prefsize(int, int); /* wm_apple.c */ - + wm_set_apple_prefsize(prefsizx, prefsizy); } #else @@ -315,11 +244,68 @@ void wm_window_add_ghostwindows(wmWindowManager *wm) win->sizey= prefsizy; win->windowstate= 0; } - wm_window_open(wm, "Blender", win); + wm_window_add_ghostwindow(wm, "Blender", win); } } } +/* new window, no screen yet, but we open ghostwindow for it */ +/* also gets the window level handlers */ +/* area-rip calls this */ +wmWindow *WM_window_open(bContext *C, rcti *rect) +{ + wmWindow *win= wm_window_new(C); + + win->posx= rect->xmin; + win->posy= rect->ymin; + win->sizex= rect->xmax - rect->xmin; + win->sizey= rect->ymax - rect->ymin; + + wm_window_add_ghostwindow(C->wm, "Blender", win); + + return win; +} + + +/* ****************** Operators ****************** */ + +/* operator callback */ +int wm_window_duplicate_op(bContext *C, wmOperator *op) +{ + wm_window_copy(C, C->window); + wm_check(C); + + return OPERATOR_FINISHED; +} + + +/* fullscreen operator callback */ +int wm_window_fullscreen_toggle_op(bContext *C, wmOperator *op) +{ + GHOST_TWindowState state = GHOST_GetWindowState(C->window->ghostwin); + if(state!=GHOST_kWindowStateFullScreen) + GHOST_SetWindowState(C->window->ghostwin, GHOST_kWindowStateFullScreen); + else + GHOST_SetWindowState(C->window->ghostwin, GHOST_kWindowStateNormal); + + return OPERATOR_FINISHED; + +} + + +/* exit blender */ +int wm_exit_blender_op(bContext *C, wmOperator *op) +{ + wmWindow *win= C->wm->windows.first; + while(win) { + wm_window_close(C, win); + win= win->next; + } + + return OPERATOR_FINISHED; +} + + /* ************ events *************** */ static int query_qual(char qual) diff --git a/source/blender/windowmanager/wm_window.h b/source/blender/windowmanager/wm_window.h index df77bdc0082..b02a16304cb 100644 --- a/source/blender/windowmanager/wm_window.h +++ b/source/blender/windowmanager/wm_window.h @@ -34,7 +34,7 @@ struct bScreen; /* *************** internal api ************** */ void wm_ghost_init (bContext *C); -wmWindow *wm_window_new (bContext *C, struct bScreen *screen); +wmWindow *wm_window_new (bContext *C); void wm_window_free (bContext *C, wmWindow *win); void wm_window_add_ghostwindows (wmWindowManager *wm); void wm_window_process_events (int wait_for_event); |