Mac HiDPI ("retina") handling:

OK - so you have this nice crisp screen, and still you want to add extra 
monitors to the laptop! That means Blender should switch back and forth to HiDPI 
modes, when you move a window to another monitor.

This code makes the pixelsize scale factor a window property, and handles
an event when a window moves to another monitor. It then changes the
native pixelsize nicely and refreshes entire UI.

You can also have one Blender window on high, and other on low resolution.

Stretching a Blender window from 1 monitor to the other works too, but that
is Apple magic handling it.
This commit is contained in:
2013-01-12 17:07:49 +00:00
parent 47ee5f56b6
commit fa759d8ffd
15 changed files with 79 additions and 29 deletions

View File

@@ -377,7 +377,7 @@ static void wm_window_add_ghostwindow(const char *title, wmWindow *win)
/* displays with larger native pixels, like Macbook. Used to scale dpi with */
/* needed here, because it's used before it reads userdef */
U.pixelsize = GHOST_GetNativePixelSize();
U.pixelsize = GHOST_GetNativePixelSize(win->ghostwin);
BKE_userdef_state();
/* store actual window size in blender window */
@@ -595,12 +595,13 @@ int wm_window_fullscreen_toggle_exec(bContext *C, wmOperator *UNUSED(op))
static void wm_convert_cursor_position(wmWindow *win, int *x, int *y)
{
float fac = GHOST_GetNativePixelSize(win->ghostwin);
GHOST_ScreenToClient(win->ghostwin, *x, *y, x, y);
*x *= GHOST_GetNativePixelSize();
*x *= fac;
*y = (win->sizey - 1) - *y;
*y *= GHOST_GetNativePixelSize();
*y *= fac;
}
@@ -661,6 +662,10 @@ void wm_window_make_drawable(bContext *C, wmWindow *win)
printf("%s: set drawable %d\n", __func__, win->winid);
}
GHOST_ActivateWindowDrawingContext(win->ghostwin);
/* this can change per window */
U.pixelsize = GHOST_GetNativePixelSize(win->ghostwin);
BKE_userdef_state();
}
}
@@ -947,6 +952,15 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
break;
}
case GHOST_kEventNativeResolutionChange:
// printf("change, pixel size %f\n", GHOST_GetNativePixelSize(win->ghostwin));
U.pixelsize = GHOST_GetNativePixelSize(win->ghostwin);
BKE_userdef_state();
WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);
break;
case GHOST_kEventTrackpad:
{
GHOST_TEventTrackpadData *pd = data;
@@ -1289,7 +1303,7 @@ void WM_init_native_pixels(int do_it)
void WM_cursor_warp(wmWindow *win, int x, int y)
{
if (win && win->ghostwin) {
float f = GHOST_GetNativePixelSize();
float f = GHOST_GetNativePixelSize(win->ghostwin);
int oldx = x, oldy = y;
x = x / f;
@@ -1308,14 +1322,14 @@ void WM_cursor_warp(wmWindow *win, int x, int y)
/* mac retina opens window in size X, but it has up to 2 x more pixels */
int WM_window_pixels_x(wmWindow *win)
{
float f = GHOST_GetNativePixelSize();
float f = GHOST_GetNativePixelSize(win->ghostwin);
return (int)(f * (float)win->sizex);
}
int WM_window_pixels_y(wmWindow *win)
{
float f = GHOST_GetNativePixelSize();
float f = GHOST_GetNativePixelSize(win->ghostwin);
return (int)(f * (float)win->sizey);