Refactor: add a function to access the window size in pixels
Replace uses of WM_window_native_pixel_x,y with WM_window_native_pixel_size() which returns an int2 for convenience and avoids an unnecessary call to GHOST_GetNativePixelSize(..).
This commit is contained in:
@@ -323,12 +323,11 @@ 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_native_pixel_x(window);
|
||||
const int height = WM_window_native_pixel_y(window);
|
||||
const rcti winrct = {0, width - 1, 0, height - 1};
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(window);
|
||||
const rcti winrct = {0, win_size[0] - 1, 0, win_size[1] - 1};
|
||||
|
||||
wmGetProjectionMatrix(block->winmat, &winrct);
|
||||
block->aspect = 2.0f / fabsf(width * block->winmat[0][0]);
|
||||
block->aspect = 2.0f / fabsf(win_size[0] * block->winmat[0][0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,16 +474,16 @@ 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_native_pixel_x(window);
|
||||
const int ymax = WM_window_native_pixel_y(window);
|
||||
/* Clamp to the window size. */
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(window);
|
||||
|
||||
ui_block_bounds_calc(block);
|
||||
|
||||
const int width = BLI_rctf_size_x(&block->rect);
|
||||
const int height = BLI_rctf_size_y(&block->rect);
|
||||
|
||||
const int startx = (xmax * 0.5f) - (width * 0.5f);
|
||||
const int starty = (ymax * 0.5f) - (height * 0.5f);
|
||||
const int startx = (win_size[0] * 0.5f) - (width * 0.5f);
|
||||
const int starty = (win_size[1] * 0.5f) - (height * 0.5f);
|
||||
|
||||
UI_block_translate(block, startx - block->rect.xmin, starty - block->rect.ymin);
|
||||
|
||||
@@ -513,8 +512,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_native_pixel_x(window);
|
||||
const int ymax = WM_window_native_pixel_y(window);
|
||||
/* Clamp to the window size. */
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(window);
|
||||
|
||||
int oldwidth = BLI_rctf_size_x(&block->rect);
|
||||
int oldheight = BLI_rctf_size_y(&block->rect);
|
||||
@@ -553,8 +552,8 @@ static void ui_block_bounds_calc_popup(
|
||||
const int margin = UI_SCREEN_MARGIN;
|
||||
rect_bounds.xmin = margin;
|
||||
rect_bounds.ymin = margin;
|
||||
rect_bounds.xmax = xmax - margin;
|
||||
rect_bounds.ymax = ymax - UI_POPUP_MENU_TOP;
|
||||
rect_bounds.xmax = win_size[0] - margin;
|
||||
rect_bounds.ymax = win_size[1] - UI_POPUP_MENU_TOP;
|
||||
|
||||
int ofs_dummy[2];
|
||||
BLI_rcti_clamp(&rect, &rect_bounds, ofs_dummy);
|
||||
|
||||
@@ -145,12 +145,13 @@ 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_native_pixel_x(window);
|
||||
const int win_y = WM_window_native_pixel_y(window);
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(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);
|
||||
const float max_size_y = max_ff(size_y, handle->max_size_y);
|
||||
const blender::float2 max_size = {
|
||||
max_ff(size_x, handle->max_size_x),
|
||||
max_ff(size_y, handle->max_size_y),
|
||||
};
|
||||
|
||||
short dir1 = 0, dir2 = 0;
|
||||
|
||||
@@ -158,21 +159,21 @@ static void ui_popup_block_position(wmWindow *window,
|
||||
bool left = false, right = false, top = false, down = false;
|
||||
|
||||
/* check if there's space at all */
|
||||
if (butrct.xmin - max_size_x + center_x > 0.0f) {
|
||||
if (butrct.xmin - max_size[0] + center_x > 0.0f) {
|
||||
left = true;
|
||||
}
|
||||
if (butrct.xmax + max_size_x - center_x < win_x) {
|
||||
if (butrct.xmax + max_size[0] - center_x < win_size[0]) {
|
||||
right = true;
|
||||
}
|
||||
if (butrct.ymin - max_size_y + center_y > 0.0f) {
|
||||
if (butrct.ymin - max_size[1] + center_y > 0.0f) {
|
||||
down = true;
|
||||
}
|
||||
if (butrct.ymax + max_size_y - center_y < win_y) {
|
||||
if (butrct.ymax + max_size[1] - center_y < win_size[1]) {
|
||||
top = true;
|
||||
}
|
||||
|
||||
if (top == 0 && down == 0) {
|
||||
if (butrct.ymin - max_size_y < win_y - butrct.ymax - max_size_y) {
|
||||
if (butrct.ymin - max_size[1] < win_size[1] - butrct.ymax - max_size[1]) {
|
||||
top = true;
|
||||
}
|
||||
else {
|
||||
@@ -267,9 +268,11 @@ static void ui_popup_block_position(wmWindow *window,
|
||||
else if (dir1 == UI_DIR_UP) {
|
||||
offset_y = (butrct.ymax - block->rect.ymin) - offset_overlap;
|
||||
|
||||
if (but->type == UI_BTYPE_COLOR && block->rect.ymax + offset_y > win_y - UI_POPUP_MENU_TOP) {
|
||||
if (but->type == UI_BTYPE_COLOR &&
|
||||
block->rect.ymax + offset_y > win_size[1] - UI_POPUP_MENU_TOP)
|
||||
{
|
||||
/* Shift this down, aligning the top edge close to the window top. */
|
||||
offset_y = win_y - block->rect.ymax - UI_POPUP_MENU_TOP;
|
||||
offset_y = win_size[1] - block->rect.ymax - UI_POPUP_MENU_TOP;
|
||||
/* All four corners should be rounded since this no longer button-aligned. */
|
||||
block->direction = UI_DIR_CENTER_Y;
|
||||
dir1 = UI_DIR_CENTER_Y;
|
||||
@@ -371,7 +374,7 @@ static void ui_popup_block_position(wmWindow *window,
|
||||
const bool fully_aligned_with_button = BLI_rctf_size_x(&block->rect) <=
|
||||
BLI_rctf_size_x(&butrct) + 1;
|
||||
const bool off_screen_left = (block->rect.xmin < 0);
|
||||
const bool off_screen_right = (block->rect.xmax > win_x);
|
||||
const bool off_screen_right = (block->rect.xmax > win_size[0]);
|
||||
|
||||
if (fully_aligned_with_button) {
|
||||
/* Popup is neither left or right from the button. */
|
||||
@@ -479,12 +482,11 @@ static void ui_popup_block_clip(wmWindow *window, uiBlock *block)
|
||||
return;
|
||||
}
|
||||
|
||||
const int winx = WM_window_native_pixel_x(window);
|
||||
const int winy = WM_window_native_pixel_y(window);
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(window);
|
||||
|
||||
/* shift to left if outside of view */
|
||||
if (block->rect.xmax > winx - margin) {
|
||||
const float xofs = winx - margin - block->rect.xmax;
|
||||
if (block->rect.xmax > win_size[0] - margin) {
|
||||
const float xofs = win_size[0] - margin - block->rect.xmax;
|
||||
block->rect.xmin += xofs;
|
||||
block->rect.xmax += xofs;
|
||||
}
|
||||
@@ -498,8 +500,8 @@ static void ui_popup_block_clip(wmWindow *window, uiBlock *block)
|
||||
if (block->rect.ymin < margin) {
|
||||
block->rect.ymin = margin;
|
||||
}
|
||||
if (block->rect.ymax > winy - UI_POPUP_MENU_TOP) {
|
||||
block->rect.ymax = winy - UI_POPUP_MENU_TOP;
|
||||
if (block->rect.ymax > win_size[1] - UI_POPUP_MENU_TOP) {
|
||||
block->rect.ymax = win_size[1] - UI_POPUP_MENU_TOP;
|
||||
}
|
||||
|
||||
/* ensure menu items draw inside left/right boundary */
|
||||
@@ -724,29 +726,28 @@ 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_native_pixel_x(window);
|
||||
const int winy = WM_window_native_pixel_y(window);
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(window);
|
||||
|
||||
copy_v2_v2(block->pie_data.pie_center_init, block->pie_data.pie_center_spawned);
|
||||
|
||||
/* only try translation if area is large enough */
|
||||
int x_offset = 0;
|
||||
if (BLI_rctf_size_x(&block->rect) < winx - (2.0f * win_width)) {
|
||||
if (BLI_rctf_size_x(&block->rect) < win_size[0] - (2.0f * win_width)) {
|
||||
if (block->rect.xmin < win_width) {
|
||||
x_offset += win_width - block->rect.xmin;
|
||||
}
|
||||
if (block->rect.xmax > winx - win_width) {
|
||||
x_offset += winx - win_width - block->rect.xmax;
|
||||
if (block->rect.xmax > win_size[0] - win_width) {
|
||||
x_offset += win_size[0] - win_width - block->rect.xmax;
|
||||
}
|
||||
}
|
||||
|
||||
int y_offset = 0;
|
||||
if (BLI_rctf_size_y(&block->rect) < winy - (2.0f * win_width)) {
|
||||
if (BLI_rctf_size_y(&block->rect) < win_size[1] - (2.0f * win_width)) {
|
||||
if (block->rect.ymin < win_width) {
|
||||
y_offset += win_width - block->rect.ymin;
|
||||
}
|
||||
if (block->rect.ymax > winy - win_width) {
|
||||
y_offset += winy - win_width - block->rect.ymax;
|
||||
if (block->rect.ymax > win_size[1] - win_width) {
|
||||
y_offset += win_size[1] - win_width - block->rect.ymax;
|
||||
}
|
||||
}
|
||||
/* if we are offsetting set up initial data for timeout functionality */
|
||||
@@ -763,9 +764,9 @@ uiBlock *ui_popup_block_refresh(bContext *C,
|
||||
}
|
||||
|
||||
region->winrct.xmin = 0;
|
||||
region->winrct.xmax = winx;
|
||||
region->winrct.xmax = win_size[0];
|
||||
region->winrct.ymin = 0;
|
||||
region->winrct.ymax = winy;
|
||||
region->winrct.ymax = win_size[1];
|
||||
|
||||
ui_block_calc_pie_segment(block, block->pie_data.pie_center_init);
|
||||
|
||||
|
||||
@@ -1208,8 +1208,7 @@ 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_native_pixel_x(win);
|
||||
const int winy = WM_window_native_pixel_y(win);
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
const uiStyle *style = UI_style_get();
|
||||
rcti rect_i;
|
||||
int font_flag = 0;
|
||||
@@ -1234,7 +1233,7 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
|
||||
|
||||
UI_fontstyle_set(&data->fstyle);
|
||||
|
||||
data->wrap_width = min_ii(UI_TIP_MAXWIDTH * U.pixelsize, winx - (UI_TIP_PADDING * 2));
|
||||
data->wrap_width = min_ii(UI_TIP_MAXWIDTH * U.pixelsize, win_size[0] - (UI_TIP_PADDING * 2));
|
||||
|
||||
font_flag |= BLF_WORD_WRAP;
|
||||
BLF_enable(data->fstyle.uifont_id, font_flag);
|
||||
@@ -1326,9 +1325,9 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
|
||||
init_rect.ymax = init_rect_overlap->ymax + pad;
|
||||
rcti rect_clamp;
|
||||
rect_clamp.xmin = 0;
|
||||
rect_clamp.xmax = winx;
|
||||
rect_clamp.xmax = win_size[0];
|
||||
rect_clamp.ymin = 0;
|
||||
rect_clamp.ymax = winy;
|
||||
rect_clamp.ymax = win_size[1];
|
||||
/* try right. */
|
||||
const int size_x = BLI_rcti_size_x(&rect_i);
|
||||
const int size_y = BLI_rcti_size_y(&rect_i);
|
||||
@@ -1410,9 +1409,9 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
|
||||
const int pad = max_ff(1.0f, U.pixelsize) * 5;
|
||||
rcti rect_clamp;
|
||||
rect_clamp.xmin = pad;
|
||||
rect_clamp.xmax = winx - pad;
|
||||
rect_clamp.xmax = win_size[0] - pad;
|
||||
rect_clamp.ymin = pad + (UI_UNIT_Y * 2);
|
||||
rect_clamp.ymax = winy - pad;
|
||||
rect_clamp.ymax = win_size[1] - pad;
|
||||
int offset_dummy[2];
|
||||
BLI_rcti_clamp(&rect_i, &rect_clamp, offset_dummy);
|
||||
}
|
||||
|
||||
@@ -170,8 +170,7 @@ void ED_screen_draw_edges(wmWindow *win)
|
||||
return;
|
||||
}
|
||||
|
||||
const int winsize_x = WM_window_native_pixel_x(win);
|
||||
const int winsize_y = WM_window_native_pixel_y(win);
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
float col[4], corner_scale, edge_thickness;
|
||||
int verts_per_corner = 0;
|
||||
|
||||
@@ -213,7 +212,7 @@ void ED_screen_draw_edges(wmWindow *win)
|
||||
GPU_batch_uniform_4fv(batch, "color", col);
|
||||
|
||||
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
||||
drawscredge_area(area, winsize_x, winsize_y, edge_thickness);
|
||||
drawscredge_area(area, win_size[0], win_size[1], edge_thickness);
|
||||
}
|
||||
|
||||
GPU_blend(GPU_BLEND_NONE);
|
||||
|
||||
@@ -1214,10 +1214,11 @@ static int screen_global_header_size()
|
||||
|
||||
static void screen_global_topbar_area_refresh(wmWindow *win, bScreen *screen)
|
||||
{
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
const short size = screen_global_header_size();
|
||||
rcti rect;
|
||||
|
||||
BLI_rcti_init(&rect, 0, WM_window_native_pixel_x(win) - 1, 0, WM_window_native_pixel_y(win) - 1);
|
||||
BLI_rcti_init(&rect, 0, win_size[0] - 1, 0, win_size[1] - 1);
|
||||
rect.ymin = rect.ymax - size;
|
||||
|
||||
screen_global_area_refresh(
|
||||
@@ -1226,12 +1227,13 @@ static void screen_global_topbar_area_refresh(wmWindow *win, bScreen *screen)
|
||||
|
||||
static void screen_global_statusbar_area_refresh(wmWindow *win, bScreen *screen)
|
||||
{
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
const short size_min = 1;
|
||||
const short size_max = 0.85f * screen_global_header_size();
|
||||
const short size = (screen->flag & SCREEN_COLLAPSE_STATUSBAR) ? size_min : size_max;
|
||||
rcti rect;
|
||||
|
||||
BLI_rcti_init(&rect, 0, WM_window_native_pixel_x(win) - 1, 0, WM_window_native_pixel_y(win) - 1);
|
||||
BLI_rcti_init(&rect, 0, win_size[0] - 1, 0, win_size[1] - 1);
|
||||
rect.ymax = rect.ymin + size_max;
|
||||
|
||||
screen_global_area_refresh(
|
||||
|
||||
@@ -632,8 +632,9 @@ 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_native_pixel_x(win) / UI_SCALE_FAC;
|
||||
r_win_size[1] = WM_window_native_pixel_y(win) / UI_SCALE_FAC;
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
r_win_size[0] = win_size[0] / UI_SCALE_FAC;
|
||||
r_win_size[1] = win_size[1] / UI_SCALE_FAC;
|
||||
|
||||
*r_is_maximized = WM_window_is_maximized(win);
|
||||
}
|
||||
|
||||
@@ -272,6 +272,9 @@ bool WM_window_pixels_read_sample(bContext *C, wmWindow *win, const int pos[2],
|
||||
*/
|
||||
int WM_window_native_pixel_x(const wmWindow *win);
|
||||
int WM_window_native_pixel_y(const wmWindow *win);
|
||||
|
||||
blender::int2 WM_window_native_pixel_size(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.
|
||||
|
||||
@@ -507,11 +507,11 @@ 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_native_pixel_x(win);
|
||||
const int winsize_y = WM_window_native_pixel_y(win);
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(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)
|
||||
if (event->xy[0] < 0 || event->xy[1] < 0 || event->xy[0] > win_size[0] ||
|
||||
event->xy[1] > win_size[1])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1197,10 +1197,9 @@ 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_native_pixel_x(win);
|
||||
const int height = WM_window_native_pixel_y(win);
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
GPUOffScreen *offscreen = GPU_offscreen_create(
|
||||
width, height, false, desired_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
|
||||
win_size[0], win_size[1], false, desired_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
|
||||
|
||||
if (offscreen) {
|
||||
GPUTexture *texture = GPU_offscreen_color_texture(offscreen);
|
||||
@@ -1285,12 +1284,11 @@ 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_native_pixel_x(win);
|
||||
r_size[1] = WM_window_native_pixel_y(win);
|
||||
const uint rect_len = r_size[0] * r_size[1];
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
const uint rect_len = win_size[0] * win_size[1];
|
||||
uint8_t *rect = static_cast<uint8_t *>(MEM_mallocN(4 * sizeof(uint8_t) * rect_len, __func__));
|
||||
|
||||
GPU_frontbuffer_read_color(0, 0, r_size[0], r_size[1], 4, GPU_DATA_UBYTE, rect);
|
||||
GPU_frontbuffer_read_color(0, 0, win_size[0], win_size[1], 4, GPU_DATA_UBYTE, rect);
|
||||
|
||||
if (setup_context) {
|
||||
if (wm->windrawable) {
|
||||
@@ -1306,6 +1304,9 @@ uint8_t *WM_window_pixels_read_from_frontbuffer(const wmWindowManager *wm,
|
||||
for (i = 0, cp += 3; i < rect_len; i++, cp += 4) {
|
||||
*cp = 0xff;
|
||||
}
|
||||
|
||||
r_size[0] = win_size[0];
|
||||
r_size[1] = win_size[1];
|
||||
return rect;
|
||||
}
|
||||
|
||||
@@ -1348,25 +1349,27 @@ 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_native_pixel_x(win);
|
||||
r_size[1] = WM_window_native_pixel_y(win);
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
|
||||
/* Determine desired offscreen format depending on HDR availability. */
|
||||
eGPUTextureFormat desired_format = get_hdr_framebuffer_format(WM_window_get_active_scene(win));
|
||||
|
||||
GPUOffScreen *offscreen = GPU_offscreen_create(
|
||||
r_size[0], r_size[1], false, desired_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
|
||||
win_size[0], win_size[1], false, desired_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
|
||||
if (UNLIKELY(!offscreen)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const uint rect_len = r_size[0] * r_size[1];
|
||||
const uint rect_len = win_size[0] * win_size[1];
|
||||
uint8_t *rect = static_cast<uint8_t *>(MEM_mallocN(4 * sizeof(uint8_t) * rect_len, __func__));
|
||||
GPU_offscreen_bind(offscreen, false);
|
||||
wm_draw_window_onscreen(C, win, -1);
|
||||
GPU_offscreen_unbind(offscreen, false);
|
||||
GPU_offscreen_read_color(offscreen, GPU_DATA_UBYTE, rect);
|
||||
GPU_offscreen_free(offscreen);
|
||||
|
||||
r_size[0] = win_size[0];
|
||||
r_size[1] = win_size[1];
|
||||
return rect;
|
||||
}
|
||||
|
||||
@@ -1376,17 +1379,17 @@ 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_native_pixel_x(win), WM_window_native_pixel_y(win)};
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
zero_v3(r_col);
|
||||
|
||||
/* While this shouldn't happen, return in the case it does. */
|
||||
BLI_assert(uint(pos[0]) < uint(size[0]) && uint(pos[1]) < uint(size[1]));
|
||||
if (!(uint(pos[0]) < uint(size[0]) && uint(pos[1]) < uint(size[1]))) {
|
||||
BLI_assert(uint(pos[0]) < uint(win_size[0]) && uint(pos[1]) < uint(win_size[1]));
|
||||
if (!(uint(pos[0]) < uint(win_size[0]) && uint(pos[1]) < uint(win_size[1]))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GPUOffScreen *offscreen = GPU_offscreen_create(
|
||||
size[0], size[1], false, GPU_RGBA8, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
|
||||
win_size[0], win_size[1], false, GPU_RGBA8, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
|
||||
if (UNLIKELY(!offscreen)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2724,10 +2724,8 @@ static eHandlerActionFlag wm_handler_fileselect_do(bContext *C,
|
||||
switch (val) {
|
||||
case EVT_FILESELECT_FULL_OPEN: {
|
||||
wmWindow *win = CTX_wm_window(C);
|
||||
const int window_center[2] = {
|
||||
WM_window_native_pixel_x(win) / 2,
|
||||
WM_window_native_pixel_y(win) / 2,
|
||||
};
|
||||
const blender::int2 window_size = WM_window_native_pixel_size(win);
|
||||
const blender::int2 window_center = window_size / 2;
|
||||
|
||||
const rcti window_rect = {
|
||||
/*xmin*/ window_center[0],
|
||||
@@ -5450,9 +5448,10 @@ static wmWindow *wm_event_cursor_other_windows(wmWindowManager *wm, wmWindow *wi
|
||||
/* In order to use window size and mouse position (pixels), we have to use a WM function. */
|
||||
|
||||
/* Check if outside, include top window bar. */
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
int event_xy[2] = {UNPACK2(event->xy)};
|
||||
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)
|
||||
if (event_xy[0] < 0 || event_xy[1] < 0 || event_xy[0] > win_size[0] ||
|
||||
event_xy[1] > win_size[1] + 30)
|
||||
{
|
||||
/* Let's skip windows having modal handlers now. */
|
||||
/* Potential XXX ugly... I wouldn't have added a `modalhandlers` list
|
||||
|
||||
@@ -509,8 +509,7 @@ 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_native_pixel_x(win);
|
||||
const int winsize_y = WM_window_native_pixel_y(win);
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
|
||||
float x1, x2, y1, y2;
|
||||
|
||||
@@ -531,18 +530,18 @@ static void wm_gesture_draw_cross(wmWindow *win, wmGesture *gt)
|
||||
|
||||
immBegin(GPU_PRIM_LINES, 4);
|
||||
|
||||
x1 = float(rect->xmin - winsize_x);
|
||||
x1 = float(rect->xmin - win_size[0]);
|
||||
y1 = float(rect->ymin);
|
||||
x2 = float(rect->xmin + winsize_x);
|
||||
x2 = float(rect->xmin + win_size[0]);
|
||||
y2 = y1;
|
||||
|
||||
immVertex2f(shdr_pos, x1, y1);
|
||||
immVertex2f(shdr_pos, x2, y2);
|
||||
|
||||
x1 = float(rect->xmin);
|
||||
y1 = float(rect->ymin - winsize_y);
|
||||
y1 = float(rect->ymin - win_size[1]);
|
||||
x2 = x1;
|
||||
y2 = float(rect->ymin + winsize_y);
|
||||
y2 = float(rect->ymin + win_size[1]);
|
||||
|
||||
immVertex2f(shdr_pos, x1, y1);
|
||||
immVertex2f(shdr_pos, x2, y2);
|
||||
|
||||
@@ -51,7 +51,9 @@ void wm_stereo3d_draw_sidebyside(wmWindow *win, int view)
|
||||
|
||||
immBindBuiltinProgram(GPU_SHADER_3D_IMAGE);
|
||||
|
||||
int soffx = WM_window_native_pixel_x(win) * 0.5f;
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
|
||||
int soffx = win_size[0] / 2;
|
||||
if (view == STEREO_LEFT_ID) {
|
||||
if (!cross_eyed) {
|
||||
soffx = 0;
|
||||
@@ -63,12 +65,9 @@ void wm_stereo3d_draw_sidebyside(wmWindow *win, int view)
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
const float halfy = GLA_PIXEL_OFS / sizey;
|
||||
const float halfx = GLA_PIXEL_OFS / win_size[0];
|
||||
const float halfy = GLA_PIXEL_OFS / win_size[1];
|
||||
|
||||
/* Texture is already bound to GL_TEXTURE0 unit. */
|
||||
|
||||
@@ -78,13 +77,13 @@ void wm_stereo3d_draw_sidebyside(wmWindow *win, int view)
|
||||
immVertex2f(pos, soffx, 0.0f);
|
||||
|
||||
immAttr2f(texcoord, 1.0f + halfx, halfy);
|
||||
immVertex2f(pos, soffx + (sizex * 0.5f), 0.0f);
|
||||
immVertex2f(pos, soffx + (win_size[0] * 0.5f), 0.0f);
|
||||
|
||||
immAttr2f(texcoord, 1.0f + halfx, 1.0f + halfy);
|
||||
immVertex2f(pos, soffx + (sizex * 0.5f), sizey);
|
||||
immVertex2f(pos, soffx + (win_size[0] * 0.5f), win_size[1]);
|
||||
|
||||
immAttr2f(texcoord, halfx, 1.0f + halfy);
|
||||
immVertex2f(pos, soffx, sizey);
|
||||
immVertex2f(pos, soffx, win_size[1]);
|
||||
|
||||
immEnd();
|
||||
|
||||
@@ -99,20 +98,19 @@ void wm_stereo3d_draw_topbottom(wmWindow *win, int view)
|
||||
|
||||
immBindBuiltinProgram(GPU_SHADER_3D_IMAGE);
|
||||
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
|
||||
int soffy;
|
||||
if (view == STEREO_LEFT_ID) {
|
||||
soffy = WM_window_native_pixel_y(win) * 0.5f;
|
||||
soffy = win_size[1] * 0.5f;
|
||||
}
|
||||
else { /* #STEREO_RIGHT_ID. */
|
||||
soffy = 0;
|
||||
}
|
||||
|
||||
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;
|
||||
const float halfy = GLA_PIXEL_OFS / sizey;
|
||||
const float halfx = GLA_PIXEL_OFS / win_size[0];
|
||||
const float halfy = GLA_PIXEL_OFS / win_size[1];
|
||||
|
||||
/* Texture is already bound to GL_TEXTURE0 unit. */
|
||||
|
||||
@@ -122,13 +120,13 @@ void wm_stereo3d_draw_topbottom(wmWindow *win, int view)
|
||||
immVertex2f(pos, 0.0f, soffy);
|
||||
|
||||
immAttr2f(texcoord, 1.0f + halfx, halfy);
|
||||
immVertex2f(pos, sizex, soffy);
|
||||
immVertex2f(pos, win_size[0], soffy);
|
||||
|
||||
immAttr2f(texcoord, 1.0f + halfx, 1.0f + halfy);
|
||||
immVertex2f(pos, sizex, soffy + (sizey * 0.5f));
|
||||
immVertex2f(pos, win_size[0], soffy + (win_size[1] * 0.5f));
|
||||
|
||||
immAttr2f(texcoord, halfx, 1.0f + halfy);
|
||||
immVertex2f(pos, 0.0f, soffy + (sizey * 0.5f));
|
||||
immVertex2f(pos, 0.0f, soffy + (win_size[1] * 0.5f));
|
||||
|
||||
immEnd();
|
||||
|
||||
|
||||
@@ -73,13 +73,12 @@ void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct
|
||||
|
||||
void wmWindowViewport(const wmWindow *win)
|
||||
{
|
||||
int width = WM_window_native_pixel_x(win);
|
||||
int height = WM_window_native_pixel_y(win);
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
|
||||
GPU_viewport(0, 0, width, height);
|
||||
GPU_scissor(0, 0, width, height);
|
||||
GPU_viewport(0, 0, win_size[0], win_size[1]);
|
||||
GPU_scissor(0, 0, win_size[0], win_size[1]);
|
||||
|
||||
wmOrtho2_pixelspace(width, height);
|
||||
wmOrtho2_pixelspace(win_size[0], win_size[1]);
|
||||
GPU_matrix_identity_set();
|
||||
}
|
||||
|
||||
|
||||
@@ -2736,6 +2736,13 @@ int WM_window_native_pixel_y(const wmWindow *win)
|
||||
return int(fac * float(win->sizey));
|
||||
}
|
||||
|
||||
blender::int2 WM_window_native_pixel_size(const wmWindow *win)
|
||||
{
|
||||
const float fac = GHOST_GetNativePixelSize(static_cast<GHOST_WindowHandle>(win->ghostwin));
|
||||
|
||||
return blender::int2(int(fac * float(win->sizex)), int(fac * float(win->sizey)));
|
||||
}
|
||||
|
||||
void WM_window_native_pixel_coords(const wmWindow *win, int *x, int *y)
|
||||
{
|
||||
const float fac = GHOST_GetNativePixelSize(static_cast<GHOST_WindowHandle>(win->ghostwin));
|
||||
@@ -2746,7 +2753,8 @@ void WM_window_native_pixel_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_native_pixel_x(win), 0, WM_window_native_pixel_y(win));
|
||||
const blender::int2 win_size = WM_window_native_pixel_size(win);
|
||||
BLI_rcti_init(r_rect, 0, win_size[0], 0, win_size[1]);
|
||||
}
|
||||
void WM_window_screen_rect_calc(const wmWindow *win, rcti *r_rect)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user