Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_window.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| win->sizey = sizey; | win->sizey = sizey; | ||||
| win->posx = posx; | win->posx = posx; | ||||
| win->posy = posy; | win->posy = posy; | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| /** | |||||
| * new window, no screen yet, but we open ghostwindow for it, | |||||
| * also gets the window level handlers | |||||
| * \note area-rip calls this. | |||||
| * \return the window or NULL. | |||||
| */ | |||||
| wmWindow *WM_window_open(bContext *C, const rcti *rect) | |||||
| { | |||||
| wmWindowManager *wm = CTX_wm_manager(C); | |||||
| wmWindow *win_prev = CTX_wm_window(C); | |||||
| wmWindow *win = wm_window_new(CTX_data_main(C), wm, win_prev, false); | |||||
| const float native_pixel_size = GHOST_GetNativePixelSize(win_prev->ghostwin); | |||||
| win->posx = rect->xmin / native_pixel_size; | |||||
| win->posy = rect->ymin / native_pixel_size; | |||||
| win->sizex = BLI_rcti_size_x(rect) / native_pixel_size; | |||||
| win->sizey = BLI_rcti_size_y(rect) / native_pixel_size; | |||||
| WM_check(C); | |||||
| if (win->ghostwin) { | |||||
| return win; | |||||
| } | |||||
| wm_window_close(C, wm, win); | |||||
| CTX_wm_window_set(C, win_prev); | |||||
| return NULL; | |||||
| } | |||||
| /** | /** | ||||
| * Uses `screen->temp` tag to define what to do, currently it limits | * Uses `screen->temp` tag to define what to do, currently it limits | ||||
| * to only one "temp" window for render out, preferences, filewindow, etc... | * to only one "temp" window for render out, preferences, filewindow, etc... | ||||
| * | * | ||||
| * \param space_type: SPACE_VIEW3D, SPACE_INFO, ... (eSpace_Type) | * \param space_type: SPACE_VIEW3D, SPACE_INFO, ... (eSpace_Type) | ||||
| * \return the window or NULL in case of failure. | * \return the window or NULL in case of failure. | ||||
| */ | */ | ||||
| wmWindow *WM_window_open_temp(bContext *C, | wmWindow *WM_window_open(bContext *C, | ||||
| const char *title, | const char *title, | ||||
| int x, | int x, | ||||
| int y, | int y, | ||||
| int sizex, | int sizex, | ||||
| int sizey, | int sizey, | ||||
| int space_type, | int space_type, | ||||
| bool dialog) | bool dialog, | ||||
| bool temp, | |||||
| WindowAlignment alignment) | |||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| wmWindow *win_prev = CTX_wm_window(C); | wmWindow *win_prev = CTX_wm_window(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| rcti rect; | |||||
| /* convert to native OS window coordinates */ | |||||
| const float native_pixel_size = GHOST_GetNativePixelSize(win_prev->ghostwin); | const float native_pixel_size = GHOST_GetNativePixelSize(win_prev->ghostwin); | ||||
| x /= native_pixel_size; | /* convert to native OS window coordinates */ | ||||
| y /= native_pixel_size; | rect.xmin = win_prev->posx + (x / native_pixel_size); | ||||
| rect.ymin = win_prev->posy + (y / native_pixel_size); | |||||
| sizex /= native_pixel_size; | sizex /= native_pixel_size; | ||||
| sizey /= native_pixel_size; | sizey /= native_pixel_size; | ||||
| /* calculate position */ | if (alignment == WIN_ALIGN_LOCATION_CENTER) { | ||||
| rcti rect; | /* Window centered around x,y location. */ | ||||
| rect.xmin = x + win_prev->posx - sizex / 2; | rect.xmin -= sizex / 2; | ||||
| rect.ymin = y + win_prev->posy - sizey / 2; | rect.ymin -= sizey / 2; | ||||
| } | |||||
| else if (alignment == WIN_ALIGN_PARENT_CENTER) { | |||||
| /* Centered within parent. X,Y as offsets from there. */ | |||||
| rect.xmin += (win_prev->sizex - sizex) / 2; | |||||
| rect.ymin += (win_prev->sizey - sizey) / 2; | |||||
| } | |||||
| else { | |||||
| /* Positioned absolutely within parent bounds. */ | |||||
| } | |||||
| rect.xmax = rect.xmin + sizex; | rect.xmax = rect.xmin + sizex; | ||||
| rect.ymax = rect.ymin + sizey; | rect.ymax = rect.ymin + sizey; | ||||
| /* changes rect to fit within desktop */ | |||||
| wm_window_check_position(&rect); | |||||
| /* Reuse temporary windows when they share the same title. */ | /* Reuse temporary windows when they share the same title. */ | ||||
| wmWindow *win = NULL; | wmWindow *win = NULL; | ||||
| LISTBASE_FOREACH (wmWindow *, win_iter, &wm->windows) { | if (temp) { | ||||
| if (WM_window_is_temp_screen(win_iter)) { | LISTBASE_FOREACH (wmWindow *, win_iter, &wm->windows) { | ||||
| char *wintitle = GHOST_GetTitle(win_iter->ghostwin); | if (WM_window_is_temp_screen(win_iter)) { | ||||
| if (strcmp(title, wintitle) == 0) { | char *wintitle = GHOST_GetTitle(win_iter->ghostwin); | ||||
| win = win_iter; | if (strcmp(title, wintitle) == 0) { | ||||
| win = win_iter; | |||||
| } | |||||
| free(wintitle); | |||||
| } | } | ||||
| free(wintitle); | |||||
| } | } | ||||
| } | } | ||||
| /* add new window? */ | /* add new window? */ | ||||
| if (win == NULL) { | if (win == NULL) { | ||||
| win = wm_window_new(bmain, wm, win_prev, dialog); | win = wm_window_new(bmain, wm, win_prev, dialog); | ||||
| win->posx = rect.xmin; | win->posx = rect.xmin; | ||||
| win->posy = rect.ymin; | win->posy = rect.ymin; | ||||
| *win->stereo3d_format = *win_prev->stereo3d_format; | |||||
| } | } | ||||
| bScreen *screen = WM_window_get_active_screen(win); | bScreen *screen = WM_window_get_active_screen(win); | ||||
| win->sizex = BLI_rcti_size_x(&rect); | win->sizex = BLI_rcti_size_x(&rect); | ||||
| win->sizey = BLI_rcti_size_y(&rect); | win->sizey = BLI_rcti_size_y(&rect); | ||||
| if (WM_window_get_active_workspace(win) == NULL) { | if (WM_window_get_active_workspace(win) == NULL) { | ||||
| Show All 11 Lines | |||||
| } | } | ||||
| /* Set scene and view layer to match original window. */ | /* Set scene and view layer to match original window. */ | ||||
| STRNCPY(win->view_layer_name, view_layer->name); | STRNCPY(win->view_layer_name, view_layer->name); | ||||
| if (WM_window_get_active_scene(win) != scene) { | if (WM_window_get_active_scene(win) != scene) { | ||||
| ED_screen_scene_change(C, win, scene); | ED_screen_scene_change(C, win, scene); | ||||
| } | } | ||||
| screen->temp = 1; | screen->temp = temp; | ||||
| /* make window active, and validate/resize */ | /* make window active, and validate/resize */ | ||||
| CTX_wm_window_set(C, win); | CTX_wm_window_set(C, win); | ||||
| const bool new_window = (win->ghostwin == NULL); | const bool new_window = (win->ghostwin == NULL); | ||||
| if (new_window) { | if (new_window) { | ||||
| wm_window_ghostwindow_ensure(wm, win, dialog); | wm_window_ghostwindow_ensure(wm, win, dialog); | ||||
| } | } | ||||
| WM_check(C); | WM_check(C); | ||||
| /* It's possible `win->ghostwin == NULL`. | /* It's possible `win->ghostwin == NULL`. | ||||
| * instead of attempting to cleanup here (in a half finished state), | * instead of attempting to cleanup here (in a half finished state), | ||||
| * finish setting up the screen, then free it at the end of the function, | * finish setting up the screen, then free it at the end of the function, | ||||
| * to avoid having to take into account a partially-created window. | * to avoid having to take into account a partially-created window. | ||||
| */ | */ | ||||
| /* ensure it shows the right spacetype editor */ | /* ensure it shows the right spacetype editor */ | ||||
| ScrArea *area = screen->areabase.first; | if (space_type != SPACE_EMPTY) { | ||||
| CTX_wm_area_set(C, area); | ScrArea *area = screen->areabase.first; | ||||
| CTX_wm_area_set(C, area); | |||||
| ED_area_newspace(C, area, space_type, false); | ED_area_newspace(C, area, space_type, false); | ||||
| } | |||||
| ED_screen_change(C, screen); | ED_screen_change(C, screen); | ||||
| if (!new_window) { | if (!new_window) { | ||||
| /* Set size in GHOST window and then update size and position from GHOST, | /* Set size in GHOST window and then update size and position from GHOST, | ||||
| * in case they where changed by GHOST to fit the monitor/screen. */ | * in case they where changed by GHOST to fit the monitor/screen. */ | ||||
| wm_window_set_size(win, win->sizex, win->sizey); | wm_window_set_size(win, win->sizex, win->sizey); | ||||
| wm_window_update_size_position(win); | wm_window_update_size_position(win); | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||