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 :)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
/* *********** Rip area operator ****************** */
|
||||
|
||||
|
||||
/* 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)
|
||||
{
|
||||
bScreen *newsc=NULL;
|
||||
ScrArea *newa;
|
||||
ScrArea *tsa;
|
||||
|
||||
if(sc->full != SCREENNORMAL) return NULL; /* XXX handle this case! */
|
||||
wmWindow *win;
|
||||
bScreen *newsc;
|
||||
rcti rect;
|
||||
|
||||
/* 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);
|
||||
|
||||
/*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;
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user