Cleanup: early return, reduce right-shift

This commit is contained in:
Campbell Barton 2022-08-18 14:45:47 +10:00
parent f5234474bd
commit fcd72756ab
2 changed files with 88 additions and 81 deletions

View File

@ -78,50 +78,51 @@ static void wm_block_splash_add_label(uiBlock *block, const char *label, int x,
static void wm_block_splash_image_roundcorners_add(ImBuf *ibuf)
{
uchar *rct = (uchar *)ibuf->rect;
if (!rct) {
return;
}
if (rct) {
bTheme *btheme = UI_GetTheme();
const float roundness = btheme->tui.wcol_menu_back.roundness * U.dpi_fac;
const int size = roundness * 20;
bTheme *btheme = UI_GetTheme();
const float roundness = btheme->tui.wcol_menu_back.roundness * U.dpi_fac;
const int size = roundness * 20;
if (size < ibuf->x && size < ibuf->y) {
/* Y-axis initial offset. */
rct += 4 * (ibuf->y - size) * ibuf->x;
if (size < ibuf->x && size < ibuf->y) {
/* Y-axis initial offset. */
rct += 4 * (ibuf->y - size) * ibuf->x;
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++, rct += 4) {
const float pixel = 1.0 / size;
const float u = pixel * x;
const float v = pixel * y;
const float distance = sqrt(u * u + v * v);
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++, rct += 4) {
const float pixel = 1.0 / size;
const float u = pixel * x;
const float v = pixel * y;
const float distance = sqrt(u * u + v * v);
/* Pointer offset to the alpha value of pixel. */
/* NOTE: the left corner is flipped in the X-axis. */
const int offset_l = 4 * (size - x - x - 1) + 3;
const int offset_r = 4 * (ibuf->x - size) + 3;
/* Pointer offset to the alpha value of pixel. */
/* NOTE: the left corner is flipped in the X-axis. */
const int offset_l = 4 * (size - x - x - 1) + 3;
const int offset_r = 4 * (ibuf->x - size) + 3;
if (distance > 1.0) {
rct[offset_l] = 0;
rct[offset_r] = 0;
}
else {
/* Create a single pixel wide transition for anti-aliasing.
* Invert the distance and map its range [0, 1] to [0, pixel]. */
const float fac = (1.0 - distance) * size;
if (fac > 1.0) {
continue;
}
const uchar alpha = unit_float_to_uchar_clamp(fac);
rct[offset_l] = alpha;
rct[offset_r] = alpha;
}
if (distance > 1.0) {
rct[offset_l] = 0;
rct[offset_r] = 0;
}
else {
/* Create a single pixel wide transition for anti-aliasing.
* Invert the distance and map its range [0, 1] to [0, pixel]. */
const float fac = (1.0 - distance) * size;
/* X-axis offset to the next row. */
rct += 4 * (ibuf->x - size);
if (fac > 1.0) {
continue;
}
const uchar alpha = unit_float_to_uchar_clamp(fac);
rct[offset_l] = alpha;
rct[offset_r] = alpha;
}
}
/* X-axis offset to the next row. */
rct += 4 * (ibuf->x - size);
}
}
}

View File

@ -155,28 +155,30 @@ static void wm_window_check_size(rcti *rect)
static void wm_ghostwindow_destroy(wmWindowManager *wm, wmWindow *win)
{
if (win->ghostwin) {
/* Prevents non-drawable state of main windows (bugs T22967,
* T25071 and possibly T22477 too). Always clear it even if
* this window was not the drawable one, because we mess with
* drawing context to discard the GW context. */
wm_window_clear_drawable(wm);
if (win == wm->winactive) {
wm->winactive = NULL;
}
/* We need this window's opengl context active to discard it. */
GHOST_ActivateWindowDrawingContext(win->ghostwin);
GPU_context_active_set(win->gpuctx);
/* Delete local GPU context. */
GPU_context_discard(win->gpuctx);
GHOST_DisposeWindow(g_system, win->ghostwin);
win->ghostwin = NULL;
win->gpuctx = NULL;
if (UNLIKELY(!win->ghostwin)) {
return;
}
/* Prevents non-drawable state of main windows (bugs T22967,
* T25071 and possibly T22477 too). Always clear it even if
* this window was not the drawable one, because we mess with
* drawing context to discard the GW context. */
wm_window_clear_drawable(wm);
if (win == wm->winactive) {
wm->winactive = NULL;
}
/* We need this window's opengl context active to discard it. */
GHOST_ActivateWindowDrawingContext(win->ghostwin);
GPU_context_active_set(win->gpuctx);
/* Delete local GPU context. */
GPU_context_discard(win->gpuctx);
GHOST_DisposeWindow(g_system, win->ghostwin);
win->ghostwin = NULL;
win->gpuctx = NULL;
}
void wm_window_free(bContext *C, wmWindowManager *wm, wmWindow *win)
@ -2035,36 +2037,40 @@ void WM_init_native_pixels(bool do_it)
void WM_init_tablet_api(void)
{
if (g_system) {
switch (U.tablet_api) {
case USER_TABLET_NATIVE:
GHOST_SetTabletAPI(g_system, GHOST_kTabletWinPointer);
break;
case USER_TABLET_WINTAB:
GHOST_SetTabletAPI(g_system, GHOST_kTabletWintab);
break;
case USER_TABLET_AUTOMATIC:
default:
GHOST_SetTabletAPI(g_system, GHOST_kTabletAutomatic);
break;
}
if (UNLIKELY(!g_system)) {
return;
}
switch (U.tablet_api) {
case USER_TABLET_NATIVE:
GHOST_SetTabletAPI(g_system, GHOST_kTabletWinPointer);
break;
case USER_TABLET_WINTAB:
GHOST_SetTabletAPI(g_system, GHOST_kTabletWintab);
break;
case USER_TABLET_AUTOMATIC:
default:
GHOST_SetTabletAPI(g_system, GHOST_kTabletAutomatic);
break;
}
}
void WM_cursor_warp(wmWindow *win, int x, int y)
{
if (win && win->ghostwin) {
int oldx = x, oldy = y;
wm_cursor_position_to_ghost_client_coords(win, &x, &y);
GHOST_SetCursorPosition(g_system, win->ghostwin, x, y);
win->eventstate->prev_xy[0] = oldx;
win->eventstate->prev_xy[1] = oldy;
win->eventstate->xy[0] = oldx;
win->eventstate->xy[1] = oldy;
if (!(win && win->ghostwin)) {
return;
}
int oldx = x, oldy = y;
wm_cursor_position_to_ghost_client_coords(win, &x, &y);
GHOST_SetCursorPosition(g_system, win->ghostwin, x, y);
win->eventstate->prev_xy[0] = oldx;
win->eventstate->prev_xy[1] = oldy;
win->eventstate->xy[0] = oldx;
win->eventstate->xy[1] = oldy;
}
/** \} */