WM API: Improve naming of WM_window_pixels_* functions

The WM API has WM_window_pixels_{x,y,coords}` functions that returns the
window size/point coordinate in the host native pixel size.

As "pixels" in itself doesn't really mean anything the intent of
these functions wasn't really clear. To clarify this, this commit
renames their prefix from `WM_window_pixels_` to
`WM_window_native_pixel_`.

Pull Request: https://projects.blender.org/blender/blender/pulls/125994
This commit is contained in:
Jonas Holzman
2024-08-07 22:30:31 +02:00
committed by Harley Acheson
parent ecc3d1db4e
commit 6bb2e5a691
17 changed files with 59 additions and 59 deletions

View File

@@ -323,8 +323,8 @@ static void ui_update_window_matrix(const wmWindow *window, const ARegion *regio
else {
/* No sub-window created yet, for menus for example, so we use the main
* window instead, since buttons are created there anyway. */
const int width = WM_window_pixels_x(window);
const int height = WM_window_pixels_y(window);
const int width = WM_window_native_pixel_x(window);
const int height = WM_window_native_pixel_y(window);
const rcti winrct = {0, width - 1, 0, height - 1};
wmGetProjectionMatrix(block->winmat, &winrct);
@@ -475,8 +475,8 @@ static void ui_block_bounds_calc_centered(wmWindow *window, uiBlock *block)
/* NOTE: this is used for the splash where window bounds event has not been
* updated by ghost, get the window bounds from ghost directly */
const int xmax = WM_window_pixels_x(window);
const int ymax = WM_window_pixels_y(window);
const int xmax = WM_window_native_pixel_x(window);
const int ymax = WM_window_native_pixel_y(window);
ui_block_bounds_calc(block);
@@ -513,8 +513,8 @@ static void ui_block_bounds_calc_popup(
/* compute mouse position with user defined offset */
ui_block_bounds_calc(block);
const int xmax = WM_window_pixels_x(window);
const int ymax = WM_window_pixels_y(window);
const int xmax = WM_window_native_pixel_x(window);
const int ymax = WM_window_native_pixel_y(window);
int oldwidth = BLI_rctf_size_x(&block->rect);
int oldheight = BLI_rctf_size_y(&block->rect);
@@ -4313,7 +4313,7 @@ static void ui_def_but_rna__menu(bContext *C, uiLayout *layout, void *but_p)
}
/* If the estimated width is greater than available size, collapse to one column. */
if (columns > 1 && text_width > WM_window_pixels_x(win)) {
if (columns > 1 && text_width > WM_window_native_pixel_x(win)) {
columns = 1;
rows = totitems;
}

View File

@@ -145,8 +145,8 @@ static void ui_popup_block_position(wmWindow *window,
const int center_x = (block->direction & UI_DIR_CENTER_X) ? size_x / 2 : 0;
const int center_y = (block->direction & UI_DIR_CENTER_Y) ? size_y / 2 : 0;
const int win_x = WM_window_pixels_x(window);
const int win_y = WM_window_pixels_y(window);
const int win_x = WM_window_native_pixel_x(window);
const int win_y = WM_window_native_pixel_y(window);
/* Take into account maximum size so we don't have to flip on refresh. */
const float max_size_x = max_ff(size_x, handle->max_size_x);
@@ -479,8 +479,8 @@ static void ui_popup_block_clip(wmWindow *window, uiBlock *block)
return;
}
const int winx = WM_window_pixels_x(window);
const int winy = WM_window_pixels_y(window);
const int winx = WM_window_native_pixel_x(window);
const int winy = WM_window_native_pixel_y(window);
/* shift to left if outside of view */
if (block->rect.xmax > winx - margin) {
@@ -724,8 +724,8 @@ uiBlock *ui_popup_block_refresh(bContext *C,
if (block->flag & UI_BLOCK_PIE_MENU) {
const int win_width = UI_SCREEN_MARGIN;
const int winx = WM_window_pixels_x(window);
const int winy = WM_window_pixels_y(window);
const int winx = WM_window_native_pixel_x(window);
const int winy = WM_window_native_pixel_y(window);
copy_v2_v2(block->pie_data.pie_center_init, block->pie_data.pie_center_spawned);

View File

@@ -802,7 +802,7 @@ static void ui_searchbox_region_layout_fn(const bContext *C, ARegion *region)
BLI_rcti_translate(&rect_i, butregion->winrct.xmin, butregion->winrct.ymin);
int winx = WM_window_pixels_x(win);
int winx = WM_window_native_pixel_x(win);
// winy = WM_window_pixels_y(win); /* UNUSED */
// wm_window_get_size(win, &winx, &winy);

View File

@@ -1208,8 +1208,8 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
{
const float pad_px = UI_TIP_PADDING;
wmWindow *win = CTX_wm_window(C);
const int winx = WM_window_pixels_x(win);
const int winy = WM_window_pixels_y(win);
const int winx = WM_window_native_pixel_x(win);
const int winy = WM_window_native_pixel_y(win);
const uiStyle *style = UI_style_get();
rcti rect_i;
int font_flag = 0;

View File

@@ -1022,7 +1022,7 @@ static void area_azone_init(wmWindow *win, const bScreen *screen, ScrArea *area)
#ifdef __APPLE__
if (!WM_window_is_fullscreen(win) &&
((coords[i][0] == 0 && coords[i][1] == 0) ||
(coords[i][0] == WM_window_pixels_x(win) && coords[i][1] == 0)))
(coords[i][0] == WM_window_native_pixel_x(win) && coords[i][1] == 0)))
{
continue;
}

View File

@@ -166,8 +166,8 @@ void ED_screen_draw_edges(wmWindow *win)
return;
}
const int winsize_x = WM_window_pixels_x(win);
const int winsize_y = WM_window_pixels_y(win);
const int winsize_x = WM_window_native_pixel_x(win);
const int winsize_y = WM_window_native_pixel_y(win);
float col[4], corner_scale, edge_thickness;
int verts_per_corner = 0;

View File

@@ -1208,7 +1208,7 @@ static void screen_global_topbar_area_refresh(wmWindow *win, bScreen *screen)
const short size = screen_global_header_size();
rcti rect;
BLI_rcti_init(&rect, 0, WM_window_pixels_x(win) - 1, 0, WM_window_pixels_y(win) - 1);
BLI_rcti_init(&rect, 0, WM_window_native_pixel_x(win) - 1, 0, WM_window_native_pixel_y(win) - 1);
rect.ymin = rect.ymax - size;
screen_global_area_refresh(
@@ -1222,7 +1222,7 @@ static void screen_global_statusbar_area_refresh(wmWindow *win, bScreen *screen)
const short size = (screen->flag & SCREEN_COLLAPSE_STATUSBAR) ? size_min : size_max;
rcti rect;
BLI_rcti_init(&rect, 0, WM_window_pixels_x(win) - 1, 0, WM_window_pixels_y(win) - 1);
BLI_rcti_init(&rect, 0, WM_window_native_pixel_x(win) - 1, 0, WM_window_native_pixel_y(win) - 1);
rect.ymax = rect.ymin + size_max;
screen_global_area_refresh(

View File

@@ -3845,8 +3845,8 @@ static AreaDockTarget area_docking_target(sAreaJoinData *jd, const wmEvent *even
int win1_posy = jd->win1->posy;
int win2_posx = jd->win2->posx;
int win2_posy = jd->win2->posy;
WM_window_pixels_coords(jd->win1, &win1_posx, &win1_posy);
WM_window_pixels_coords(jd->win2, &win2_posx, &win2_posy);
WM_window_native_pixel_coords(jd->win1, &win1_posx, &win1_posy);
WM_window_native_pixel_coords(jd->win2, &win2_posx, &win2_posy);
const int x = event->xy[0] + win1_posx - win2_posx - jd->sa2->totrct.xmin;
const int y = event->xy[1] + win1_posy - win2_posy - jd->sa2->totrct.ymin;

View File

@@ -632,8 +632,8 @@ void ED_fileselect_window_params_get(const wmWindow *win, int r_win_size[2], boo
/* Get DPI/pixel-size independent size to be stored in preferences. */
WM_window_set_dpi(win); /* Ensure the DPI is taken from the right window. */
r_win_size[0] = WM_window_pixels_x(win) / UI_SCALE_FAC;
r_win_size[1] = WM_window_pixels_y(win) / UI_SCALE_FAC;
r_win_size[0] = WM_window_native_pixel_x(win) / UI_SCALE_FAC;
r_win_size[1] = WM_window_native_pixel_y(win) / UI_SCALE_FAC;
*r_is_maximized = WM_window_is_maximized(win);
}

View File

@@ -273,9 +273,9 @@ bool WM_window_pixels_read_sample(bContext *C, wmWindow *win, const int pos[2],
*
* \note macOS retina opens window in size X, but it has up to 2 x more pixels.
*/
int WM_window_pixels_x(const wmWindow *win);
int WM_window_pixels_y(const wmWindow *win);
void WM_window_pixels_coords(const wmWindow *win, int *x, int *y);
int WM_window_native_pixel_x(const wmWindow *win);
int WM_window_native_pixel_y(const wmWindow *win);
void WM_window_native_pixel_coords(const wmWindow *win, int *x, int *y);
/**
* Get boundaries usable by all window contents, including global areas.
*/

View File

@@ -507,8 +507,8 @@ static wmDropBox *wm_dropbox_active(bContext *C, wmDrag *drag, const wmEvent *ev
static void wm_drop_update_active(bContext *C, wmDrag *drag, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
const int winsize_x = WM_window_pixels_x(win);
const int winsize_y = WM_window_pixels_y(win);
const int winsize_x = WM_window_native_pixel_x(win);
const int winsize_y = WM_window_native_pixel_y(win);
/* For multi-window drags, we only do this if mouse inside. */
if (event->xy[0] < 0 || event->xy[1] < 0 || event->xy[0] > winsize_x || event->xy[1] > winsize_y)
@@ -1088,7 +1088,7 @@ static void wm_drag_draw_tooltip(bContext *C, wmWindow *win, wmDrag *drag, const
return;
}
const int winsize_y = WM_window_pixels_y(win);
const int winsize_y = WM_window_native_pixel_y(win);
int x, y;
if (drag->imb) {
const int icon_width = wm_drag_imbuf_icon_width_get(drag);

View File

@@ -352,7 +352,7 @@ static void wm_software_cursor_draw(wmWindow *win, const GrabState *grab_state)
}
}
if (grab_state->wrap_axis & GHOST_kAxisY) {
const int height = WM_window_pixels_y(win);
const int height = WM_window_native_pixel_y(win);
const int min = height - grab_state->bounds[1];
const int max = height - grab_state->bounds[3];
if (min != max) {
@@ -1197,8 +1197,8 @@ static void wm_draw_window(bContext *C, wmWindow *win)
/* For side-by-side and top-bottom, we need to render each view to an
* an off-screen texture and then draw it. This used to happen for all
* stereo methods, but it's less efficient than drawing directly. */
const int width = WM_window_pixels_x(win);
const int height = WM_window_pixels_y(win);
const int width = WM_window_native_pixel_x(win);
const int height = WM_window_native_pixel_y(win);
GPUOffScreen *offscreen = GPU_offscreen_create(
width, height, false, desired_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
@@ -1285,8 +1285,8 @@ uint8_t *WM_window_pixels_read_from_frontbuffer(const wmWindowManager *wm,
GPU_context_active_set(static_cast<GPUContext *>(win->gpuctx));
}
r_size[0] = WM_window_pixels_x(win);
r_size[1] = WM_window_pixels_y(win);
r_size[0] = WM_window_native_pixel_x(win);
r_size[1] = WM_window_native_pixel_y(win);
const uint rect_len = r_size[0] * r_size[1];
uint8_t *rect = static_cast<uint8_t *>(MEM_mallocN(4 * sizeof(uint8_t) * rect_len, __func__));
@@ -1348,8 +1348,8 @@ uint8_t *WM_window_pixels_read_from_offscreen(bContext *C, wmWindow *win, int r_
* So provide an alternative to #WM_window_pixels_read that avoids using the front-buffer. */
/* Draw into an off-screen buffer and read its contents. */
r_size[0] = WM_window_pixels_x(win);
r_size[1] = WM_window_pixels_y(win);
r_size[0] = WM_window_native_pixel_x(win);
r_size[1] = WM_window_native_pixel_y(win);
/* Determine desired offscreen format depending on HDR availability. */
eGPUTextureFormat desired_format = get_hdr_framebuffer_format(WM_window_get_active_scene(win));
@@ -1376,7 +1376,7 @@ bool WM_window_pixels_read_sample_from_offscreen(bContext *C,
float r_col[3])
{
/* A version of #WM_window_pixels_read_from_offscreen that reads a single sample. */
const int size[2] = {WM_window_pixels_x(win), WM_window_pixels_y(win)};
const int size[2] = {WM_window_native_pixel_x(win), WM_window_native_pixel_y(win)};
zero_v3(r_col);
/* While this shouldn't happen, return in the case it does. */

View File

@@ -2721,8 +2721,8 @@ static eHandlerActionFlag wm_handler_fileselect_do(bContext *C,
case EVT_FILESELECT_FULL_OPEN: {
wmWindow *win = CTX_wm_window(C);
const int window_center[2] = {
WM_window_pixels_x(win) / 2,
WM_window_pixels_y(win) / 2,
WM_window_native_pixel_x(win) / 2,
WM_window_native_pixel_y(win) / 2,
};
const rcti window_rect = {
@@ -5419,8 +5419,8 @@ static wmWindow *wm_event_cursor_other_windows(wmWindowManager *wm, wmWindow *wi
/* Check if outside, include top window bar. */
int event_xy[2] = {UNPACK2(event->xy)};
if (event_xy[0] < 0 || event_xy[1] < 0 || event_xy[0] > WM_window_pixels_x(win) ||
event_xy[1] > WM_window_pixels_y(win) + 30)
if (event_xy[0] < 0 || event_xy[1] < 0 || event_xy[0] > WM_window_native_pixel_x(win) ||
event_xy[1] > WM_window_native_pixel_y(win) + 30)
{
/* Let's skip windows having modal handlers now. */
/* Potential XXX ugly... I wouldn't have added a `modalhandlers` list

View File

@@ -501,8 +501,8 @@ static void wm_gesture_draw_polyline(wmGesture *gt)
static void wm_gesture_draw_cross(wmWindow *win, wmGesture *gt)
{
const rcti *rect = static_cast<const rcti *>(gt->customdata);
const int winsize_x = WM_window_pixels_x(win);
const int winsize_y = WM_window_pixels_y(win);
const int winsize_x = WM_window_native_pixel_x(win);
const int winsize_y = WM_window_native_pixel_y(win);
float x1, x2, y1, y2;

View File

@@ -51,7 +51,7 @@ void wm_stereo3d_draw_sidebyside(wmWindow *win, int view)
immBindBuiltinProgram(GPU_SHADER_3D_IMAGE);
int soffx = WM_window_pixels_x(win) * 0.5f;
int soffx = WM_window_native_pixel_x(win) * 0.5f;
if (view == STEREO_LEFT_ID) {
if (!cross_eyed) {
soffx = 0;
@@ -63,8 +63,8 @@ void wm_stereo3d_draw_sidebyside(wmWindow *win, int view)
}
}
const int sizex = WM_window_pixels_x(win);
const int sizey = WM_window_pixels_y(win);
const int sizex = WM_window_native_pixel_x(win);
const int sizey = WM_window_native_pixel_y(win);
/* `wmOrtho` for the screen has this same offset. */
const float halfx = GLA_PIXEL_OFS / sizex;
@@ -101,14 +101,14 @@ void wm_stereo3d_draw_topbottom(wmWindow *win, int view)
int soffy;
if (view == STEREO_LEFT_ID) {
soffy = WM_window_pixels_y(win) * 0.5f;
soffy = WM_window_native_pixel_y(win) * 0.5f;
}
else { /* #STEREO_RIGHT_ID. */
soffy = 0;
}
const int sizex = WM_window_pixels_x(win);
const int sizey = WM_window_pixels_y(win);
const int sizex = WM_window_native_pixel_x(win);
const int sizey = WM_window_native_pixel_y(win);
/* `wmOrtho` for the screen has this same offset. */
const float halfx = GLA_PIXEL_OFS / sizex;
@@ -173,7 +173,7 @@ void wm_stereo3d_mouse_offset_apply(wmWindow *win, int r_mouse_xy[2])
}
if (win->stereo3d_format->display_mode == S3D_DISPLAY_SIDEBYSIDE) {
const int half_x = WM_window_pixels_x(win) / 2;
const int half_x = WM_window_native_pixel_x(win) / 2;
/* Right half of the screen. */
if (r_mouse_xy[0] > half_x) {
r_mouse_xy[0] -= half_x;
@@ -181,7 +181,7 @@ void wm_stereo3d_mouse_offset_apply(wmWindow *win, int r_mouse_xy[2])
r_mouse_xy[0] *= 2;
}
else if (win->stereo3d_format->display_mode == S3D_DISPLAY_TOPBOTTOM) {
const int half_y = WM_window_pixels_y(win) / 2;
const int half_y = WM_window_native_pixel_y(win) / 2;
/* Upper half of the screen. */
if (r_mouse_xy[1] > half_y) {
r_mouse_xy[1] -= half_y;

View File

@@ -73,8 +73,8 @@ void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct
void wmWindowViewport(wmWindow *win)
{
int width = WM_window_pixels_x(win);
int height = WM_window_pixels_y(win);
int width = WM_window_native_pixel_x(win);
int height = WM_window_native_pixel_y(win);
GPU_viewport(0, 0, width, height);
GPU_scissor(0, 0, width, height);

View File

@@ -2670,20 +2670,20 @@ void WM_cursor_warp(wmWindow *win, int x, int y)
/** \name Window Size (public)
* \{ */
int WM_window_pixels_x(const wmWindow *win)
int WM_window_native_pixel_x(const wmWindow *win)
{
const float fac = GHOST_GetNativePixelSize(static_cast<GHOST_WindowHandle>(win->ghostwin));
return int(fac * float(win->sizex));
}
int WM_window_pixels_y(const wmWindow *win)
int WM_window_native_pixel_y(const wmWindow *win)
{
const float fac = GHOST_GetNativePixelSize(static_cast<GHOST_WindowHandle>(win->ghostwin));
return int(fac * float(win->sizey));
}
void WM_window_pixels_coords(const wmWindow *win, int *x, int *y)
void WM_window_native_pixel_coords(const wmWindow *win, int *x, int *y)
{
const float fac = GHOST_GetNativePixelSize(static_cast<GHOST_WindowHandle>(win->ghostwin));
@@ -2693,7 +2693,7 @@ void WM_window_pixels_coords(const wmWindow *win, int *x, int *y)
void WM_window_rect_calc(const wmWindow *win, rcti *r_rect)
{
BLI_rcti_init(r_rect, 0, WM_window_pixels_x(win), 0, WM_window_pixels_y(win));
BLI_rcti_init(r_rect, 0, WM_window_native_pixel_x(win), 0, WM_window_native_pixel_y(win));
}
void WM_window_screen_rect_calc(const wmWindow *win, rcti *r_rect)
{