Refactor temp-space opening for optional fullscreen mode

Will be put to use in followup commits.
This commit is contained in:
Julian Eisel 2019-09-18 14:21:32 +02:00
parent e2cbf8b117
commit 95373e2749
9 changed files with 84 additions and 62 deletions

View File

@ -238,6 +238,14 @@ struct ScrArea *ED_screen_state_toggle(struct bContext *C,
struct wmWindow *win,
struct ScrArea *sa,
const short state);
ScrArea *ED_screen_temp_space_open(struct bContext *C,
const char *title,
int x,
int y,
int sizex,
int sizey,
eSpace_Type space_type,
int display_type);
void ED_screens_header_tools_menu_create(struct bContext *C, struct uiLayout *layout, void *arg);
void ED_screens_footer_tools_menu_create(struct bContext *C, struct uiLayout *layout, void *arg);
void ED_screens_navigation_bar_tools_menu_create(struct bContext *C,

View File

@ -36,6 +36,8 @@
#include "BKE_screen.h"
#include "BKE_report.h"
#include "BLT_translation.h"
#include "WM_api.h"
#include "WM_types.h"
@ -154,7 +156,8 @@ ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports)
}
/* changes context! */
if (WM_window_open_temp(C, mx, my, sizex, sizey, WM_WINDOW_RENDER) == NULL) {
if (WM_window_open_temp(C, IFACE_("Blender Render"), mx, my, sizex, sizey, SPACE_IMAGE) ==
NULL) {
BKE_report(reports, RPT_ERROR, "Failed to open window!");
return NULL;
}

View File

@ -1346,6 +1346,39 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *sa, const s
return sc->areabase.first;
}
/**
* Wrapper to open a temporary space either as fullscreen space, or as separate window, as defined
* by \a display_type.
*
* \param title: Title to set for the window, if a window is spawned.
* \param x, y: Position of the window, if a window is spawned.
* \param sizex, sizey: Dimensions of the window, if a window is spawned.
*/
ScrArea *ED_screen_temp_space_open(bContext *C,
const char *title,
int x,
int y,
int sizex,
int sizey,
eSpace_Type space_type,
int display_type)
{
ScrArea *sa = NULL;
switch (display_type) {
case USER_TEMP_SPACE_DISPLAY_WINDOW:
if (WM_window_open_temp(C, title, x, y, sizex, sizey, (int)space_type)) {
sa = CTX_wm_area(C);
}
break;
case USER_TEMP_SPACE_DISPLAY_FULLSCREEN:
sa = ED_screen_full_newspace(C, CTX_wm_area(C), (int)space_type);
break;
}
return sa;
}
/* update frame rate info for viewport drawing */
void ED_refresh_viewport_fps(bContext *C)
{

View File

@ -4833,7 +4833,9 @@ static int userpref_show_invoke(bContext *C, wmOperator *op, const wmEvent *even
int sizey = 520 * UI_DPI_FAC;
/* changes context! */
if (WM_window_open_temp(C, event->x, event->y, sizex, sizey, WM_WINDOW_USERPREFS) != NULL) {
if (WM_window_open_temp(
C, IFACE_("Blender Preferences"), event->x, event->y, sizex, sizey, SPACE_USERPREF) !=
NULL) {
/* The header only contains the editor switcher and looks empty.
* So hiding in the temp window makes sense. */
ScrArea *area = CTX_wm_area(C);
@ -4882,7 +4884,11 @@ static int drivers_editor_show_invoke(bContext *C, wmOperator *op, const wmEvent
but = UI_context_active_but_prop_get(C, &ptr, &prop, &index);
/* changes context! */
if (WM_window_open_temp(C, event->x, event->y, sizex, sizey, WM_WINDOW_DRIVERS) != NULL) {
if (WM_window_open_temp(
C, IFACE_("Blender Drivers Editor"), event->x, event->y, sizex, sizey, SPACE_GRAPH) !=
NULL) {
ED_drivers_editor_init(C, CTX_wm_area(C));
/* activate driver F-Curve for the property under the cursor */
if (but) {
FCurve *fcu;
@ -4938,7 +4944,9 @@ static int info_log_show_invoke(bContext *C, wmOperator *op, const wmEvent *even
int shift_y = 480;
/* changes context! */
if (WM_window_open_temp(C, event->x, event->y + shift_y, sizex, sizey, WM_WINDOW_INFO) != NULL) {
if (WM_window_open_temp(
C, IFACE_("Blender Info Log"), event->x, event->y + shift_y, sizex, sizey, SPACE_INFO) !=
NULL) {
return OPERATOR_FINISHED;
}
else {

View File

@ -1202,6 +1202,11 @@ typedef enum eUserpref_FactorDisplay {
USER_FACTOR_AS_PERCENTAGE = 1,
} eUserpref_FactorDisplay;
typedef enum eUserpref_TempSpaceDisplayType {
USER_TEMP_SPACE_DISPLAY_FULLSCREEN,
USER_TEMP_SPACE_DISPLAY_WINDOW,
} eUserpref_TempSpaceDisplayType;
#ifdef __cplusplus
}
#endif

View File

@ -4044,6 +4044,20 @@ static void rna_def_userdef_view(BlenderRNA *brna)
{0, NULL, 0, NULL, NULL},
};
static const EnumPropertyItem temp_space_display_types[] = {
{USER_TEMP_SPACE_DISPLAY_FULLSCREEN,
"SCREEN", /* Could be FULLSCREEN, but keeping it consistent with render_display_types */
0,
"Full Screen",
"Open the temporary editor in a maximized screen"},
{USER_TEMP_SPACE_DISPLAY_WINDOW,
"WINDOW",
0,
"New Window",
"Open the temporary editor in a new window"},
{0, NULL, 0, NULL, NULL},
};
PropertyRNA *prop;
StructRNA *srna;

View File

@ -153,18 +153,9 @@ void WM_opengl_context_dispose(void *context);
void WM_opengl_context_activate(void *context);
void WM_opengl_context_release(void *context);
/* defines for 'type' WM_window_open_temp */
enum {
WM_WINDOW_RENDER = 1,
WM_WINDOW_USERPREFS,
WM_WINDOW_DRIVERS,
WM_WINDOW_INFO,
WM_WINDOW_FILESEL,
};
struct wmWindow *WM_window_open(struct bContext *C, const struct rcti *rect);
struct wmWindow *WM_window_open_temp(
struct bContext *C, int x, int y, int sizex, int sizey, int type);
struct bContext *C, const char *title, int x, int y, int sizex, int sizey, int space_type);
void WM_window_set_dpi(wmWindow *win);
bool WM_stereo3d_enabled(struct wmWindow *win, bool only_fullscreen_test);

View File

@ -58,6 +58,8 @@
#include "BKE_sound.h"
#include "BLT_translation.h"
#include "ED_fileselect.h"
#include "ED_info.h"
#include "ED_screen.h"
@ -2346,11 +2348,12 @@ static int wm_handler_fileselect_do(bContext *C,
const int sizey = 600 * UI_DPI_FAC;
if (WM_window_open_temp(C,
IFACE_("Blender File View"),
WM_window_pixels_x(win) / 2,
WM_window_pixels_y(win) / 2,
sizex,
sizey,
WM_WINDOW_FILESEL) != NULL) {
SPACE_FILE) != NULL) {
ScrArea *area = CTX_wm_area(C);
ARegion *region_header = BKE_area_find_region_type(area, RGN_TYPE_HEADER);

View File

@ -792,10 +792,11 @@ wmWindow *WM_window_open(bContext *C, const rcti *rect)
* Uses `screen->temp` tag to define what to do, currently it limits
* to only one "temp" window for render out, preferences, filewindow, etc...
*
* \param type: WM_WINDOW_RENDER, WM_WINDOW_USERPREFS...
* \return the window or NULL.
* \param space_type: SPACE_VIEW3D, SPACE_INFO, ... (eSpace_Type)
* \return the window or NULL in case of failure.
*/
wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, int type)
wmWindow *WM_window_open_temp(
bContext *C, const char *title, int x, int y, int sizex, int sizey, int space_type)
{
Main *bmain = CTX_data_main(C);
wmWindow *win_prev = CTX_wm_window(C);
@ -804,8 +805,6 @@ wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, i
ScrArea *sa;
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
eSpace_Type space_type = SPACE_EMPTY;
const char *title;
/* convert to native OS window coordinates */
const float native_pixel_size = GHOST_GetNativePixelSize(win_prev->ghostwin);
@ -885,53 +884,11 @@ wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, i
sa = screen->areabase.first;
CTX_wm_area_set(C, sa);
if (type == WM_WINDOW_RENDER) {
space_type = SPACE_IMAGE;
}
else if (type == WM_WINDOW_DRIVERS) {
space_type = SPACE_GRAPH;
}
else if (type == WM_WINDOW_USERPREFS) {
space_type = SPACE_USERPREF;
}
else if (type == WM_WINDOW_FILESEL) {
space_type = SPACE_FILE;
}
else if (type == WM_WINDOW_INFO) {
space_type = SPACE_INFO;
}
else {
BLI_assert(false);
}
ED_area_newspace(C, sa, space_type, false);
ED_screen_change(C, screen);
ED_screen_refresh(CTX_wm_manager(C), win); /* test scale */
/* do additional setup for specific editor type */
if (type == WM_WINDOW_DRIVERS) {
ED_drivers_editor_init(C, sa);
}
if (sa->spacetype == SPACE_IMAGE) {
title = IFACE_("Blender Render");
}
else if (ELEM(sa->spacetype, SPACE_OUTLINER, SPACE_USERPREF)) {
title = IFACE_("Blender Preferences");
}
else if (sa->spacetype == SPACE_FILE) {
title = IFACE_("Blender File View");
}
else if (sa->spacetype == SPACE_GRAPH) {
title = IFACE_("Blender Drivers Editor");
}
else if (sa->spacetype == SPACE_INFO) {
title = IFACE_("Blender Info Log");
}
else {
title = "Blender";
}
if (win->ghostwin) {
GHOST_SetTitle(win->ghostwin, title);
return win;