Fix image cache margin calculation

This margin was inconsistently calculated: only taking the
visible region and interface scale into account in some cases.
This commit is contained in:
Campbell Barton 2021-10-19 12:22:06 +11:00
parent a3457704fb
commit b74f2c7d74
6 changed files with 26 additions and 20 deletions

View File

@ -53,13 +53,13 @@ float ED_space_image_increment_snap_value(const int grid_dimesnions,
const float zoom_factor);
/* image_edit.c, exported for transform */
struct Image *ED_space_image(struct SpaceImage *sima);
struct Image *ED_space_image(const struct SpaceImage *sima);
void ED_space_image_set(struct Main *bmain,
struct SpaceImage *sima,
struct Image *ima,
bool automatic);
void ED_space_image_auto_set(const struct bContext *C, struct SpaceImage *sima);
struct Mask *ED_space_image_get_mask(struct SpaceImage *sima);
struct Mask *ED_space_image_get_mask(const struct SpaceImage *sima);
void ED_space_image_set_mask(struct bContext *C, struct SpaceImage *sima, struct Mask *mask);
bool ED_space_image_get_position(struct SpaceImage *sima,
@ -136,7 +136,10 @@ void ED_image_draw_info(struct Scene *scene,
const int *zp,
const float *zpf);
bool ED_space_image_show_cache(struct SpaceImage *sima);
bool ED_space_image_show_cache(const struct SpaceImage *sima);
bool ED_space_image_show_cache_and_mval_over(const struct SpaceImage *sima,
struct ARegion *region,
const int mval[2]);
bool ED_image_should_save_modified(const struct Main *bmain);
int ED_image_save_all_modified_info(const struct Main *bmain, struct ReportList *reports);

View File

@ -500,7 +500,7 @@ void draw_image_main_helpers(const bContext *C, ARegion *region)
}
}
bool ED_space_image_show_cache(SpaceImage *sima)
bool ED_space_image_show_cache(const SpaceImage *sima)
{
Image *image = ED_space_image(sima);
Mask *mask = NULL;
@ -516,6 +516,17 @@ bool ED_space_image_show_cache(SpaceImage *sima)
return true;
}
bool ED_space_image_show_cache_and_mval_over(const SpaceImage *sima,
ARegion *region,
const int mval[2])
{
const rcti *rect_visible = ED_region_visible_rect(region);
if (mval[1] > rect_visible->ymin + (16 * UI_DPI_FAC)) {
return false;
}
return ED_space_image_show_cache(sima);
}
void draw_image_cache(const bContext *C, ARegion *region)
{
SpaceImage *sima = CTX_wm_space_image(C);

View File

@ -52,7 +52,7 @@
#include "WM_types.h"
/* NOTE: image_panel_properties() uses pointer to sima->image directly. */
Image *ED_space_image(SpaceImage *sima)
Image *ED_space_image(const SpaceImage *sima)
{
return sima->image;
}
@ -113,7 +113,7 @@ void ED_space_image_auto_set(const bContext *C, SpaceImage *sima)
}
}
Mask *ED_space_image_get_mask(SpaceImage *sima)
Mask *ED_space_image_get_mask(const SpaceImage *sima)
{
return sima->mask_info.mask;
}

View File

@ -3628,13 +3628,8 @@ static int change_frame_invoke(bContext *C, wmOperator *op, const wmEvent *event
ARegion *region = CTX_wm_region(C);
if (region->regiontype == RGN_TYPE_WINDOW) {
SpaceImage *sima = CTX_wm_space_image(C);
/* Local coordinate visible rect inside region, to accommodate overlapping ui. */
const rcti *rect_visible = ED_region_visible_rect(region);
const int region_bottom = rect_visible->ymin;
if (event->mval[1] > (region_bottom + 16 * UI_DPI_FAC) || !ED_space_image_show_cache(sima)) {
const SpaceImage *sima = CTX_wm_space_image(C);
if (!ED_space_image_show_cache_and_mval_over(sima, region, event->mval)) {
return OPERATOR_PASS_THROUGH;
}
}

View File

@ -491,9 +491,8 @@ int ED_imbuf_sample_invoke(bContext *C, wmOperator *op, const wmEvent *event)
if (sa && sa->spacetype == SPACE_IMAGE) {
SpaceImage *sima = CTX_wm_space_image(C);
if (region->regiontype == RGN_TYPE_WINDOW) {
if (event->mval[1] <= 16 && ED_space_image_show_cache(sima)) {
if (ED_space_image_show_cache_and_mval_over(sima, region, event->mval)) {
return OPERATOR_PASS_THROUGH;
}
}

View File

@ -1765,11 +1765,9 @@ static int uv_set_2d_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *e
float location[2];
if (region->regiontype == RGN_TYPE_WINDOW) {
if (event->mval[1] <= 16) {
SpaceImage *sima = CTX_wm_space_image(C);
if (sima && ED_space_image_show_cache(sima)) {
return OPERATOR_PASS_THROUGH;
}
SpaceImage *sima = CTX_wm_space_image(C);
if (sima && ED_space_image_show_cache_and_mval_over(sima, region, event->mval)) {
return OPERATOR_PASS_THROUGH;
}
}