Cleanup: reserve 'mval' for region-relative pointer coordinates

This commit is contained in:
Campbell Barton
2023-10-17 12:57:00 +11:00
parent f20e38d422
commit 768dedbe5a
6 changed files with 53 additions and 35 deletions

View File

@@ -88,8 +88,8 @@ ImBuf *ED_space_clip_get_stable_buffer(const SpaceClip *sc,
bool ED_space_clip_get_position(const SpaceClip *sc,
const ARegion *region,
int mval[2],
float fpos[2]);
const int mval[2],
float r_fpos[2]);
/**
* Returns color in linear space, matching #ED_space_image_color_sample().
*/
@@ -118,7 +118,10 @@ void ED_clip_point_stable_pos__reverse(const SpaceClip *sc,
/**
* Takes `event->mval`.
*/
void ED_clip_mouse_pos(const SpaceClip *sc, const ARegion *region, const int mval[2], float co[2]);
void ED_clip_mouse_pos(const SpaceClip *sc,
const ARegion *region,
const int mval[2],
float r_co[2]);
bool ED_space_clip_check_show_trackedit(const SpaceClip *sc);
bool ED_space_clip_check_show_maskedit(const SpaceClip *sc);

View File

@@ -53,7 +53,10 @@ void ED_space_image_set_mask(bContext *C, SpaceImage *sima, Mask *mask);
/**
* Returns mouse position in image space.
*/
bool ED_space_image_get_position(SpaceImage *sima, ARegion *region, int mval[2], float fpos[2]);
bool ED_space_image_get_position(SpaceImage *sima,
ARegion *region,
const int mval[2],
float r_fpos[2]);
/**
* Returns color in linear space, matching #ED_space_node_color_sample().
*/

View File

@@ -69,7 +69,7 @@ struct Eyedropper {
int accum_tot;
wmWindow *cb_win;
int cb_win_mval[2];
int cb_win_event_xy[2];
void *draw_handle_sample_text;
char sample_text[MAX_NAME];
@@ -80,7 +80,7 @@ struct Eyedropper {
static void eyedropper_draw_cb(const wmWindow * /*window*/, void *arg)
{
Eyedropper *eye = static_cast<Eyedropper *>(arg);
eyedropper_draw_cursor_text_region(eye->cb_win_mval, eye->sample_text);
eyedropper_draw_cursor_text_region(eye->cb_win_event_xy, eye->sample_text);
}
static bool eyedropper_init(bContext *C, wmOperator *op)
@@ -258,15 +258,15 @@ static bool eyedropper_cryptomatte_sample_fl(bContext *C,
ScrArea *area = nullptr;
int mval[2];
wmWindow *win = WM_window_find_under_cursor(CTX_wm_window(C), event_xy, mval);
int event_xy_win[2];
wmWindow *win = WM_window_find_under_cursor(CTX_wm_window(C), event_xy, event_xy_win);
if (win) {
bScreen *screen = WM_window_get_active_screen(win);
area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mval);
area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event_xy_win);
}
eye->cb_win_mval[0] = mval[0];
eye->cb_win_mval[1] = mval[1];
eye->cb_win_event_xy[0] = event_xy_win[0];
eye->cb_win_event_xy[1] = event_xy_win[1];
if (win && win != eye->cb_win && eye->draw_handle_sample_text) {
WM_draw_cb_exit(eye->cb_win, eye->draw_handle_sample_text);
@@ -279,29 +279,32 @@ static bool eyedropper_cryptomatte_sample_fl(bContext *C,
return false;
}
ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mval);
ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, event_xy_win);
if (!region) {
return false;
}
int region_mval[2] = {mval[0] - region->winrct.xmin, mval[1] - region->winrct.ymin};
const int mval[2] = {
event_xy_win[0] - region->winrct.xmin,
event_xy_win[1] - region->winrct.ymin,
};
float fpos[2] = {-1.0f, -1.0};
switch (area->spacetype) {
case SPACE_IMAGE: {
SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
ED_space_image_get_position(sima, region, region_mval, fpos);
ED_space_image_get_position(sima, region, mval, fpos);
break;
}
case SPACE_NODE: {
Main *bmain = CTX_data_main(C);
SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
ED_space_node_get_position(bmain, snode, region, region_mval, fpos);
ED_space_node_get_position(bmain, snode, region, mval, fpos);
break;
}
case SPACE_CLIP: {
SpaceClip *sc = static_cast<SpaceClip *>(area->spacedata.first);
ED_space_clip_get_position(sc, region, region_mval, fpos);
ED_space_clip_get_position(sc, region, mval, fpos);
break;
}
default: {
@@ -340,33 +343,36 @@ void eyedropper_color_sample_fl(bContext *C, const int event_xy[2], float r_col[
{
ScrArea *area = nullptr;
int mval[2];
wmWindow *win = WM_window_find_under_cursor(CTX_wm_window(C), event_xy, mval);
int event_xy_win[2];
wmWindow *win = WM_window_find_under_cursor(CTX_wm_window(C), event_xy, event_xy_win);
if (win) {
bScreen *screen = WM_window_get_active_screen(win);
area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mval);
area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event_xy_win);
}
if (area) {
ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mval);
ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, event_xy_win);
if (region) {
const int region_mval[2] = {mval[0] - region->winrct.xmin, mval[1] - region->winrct.ymin};
const int mval[2] = {
event_xy_win[0] - region->winrct.xmin,
event_xy_win[1] - region->winrct.ymin,
};
if (area->spacetype == SPACE_IMAGE) {
SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
if (ED_space_image_color_sample(sima, region, region_mval, r_col, nullptr)) {
if (ED_space_image_color_sample(sima, region, mval, r_col, nullptr)) {
return;
}
}
else if (area->spacetype == SPACE_NODE) {
SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
Main *bmain = CTX_data_main(C);
if (ED_space_node_color_sample(bmain, snode, region, region_mval, r_col)) {
if (ED_space_node_color_sample(bmain, snode, region, mval, r_col)) {
return;
}
}
else if (area->spacetype == SPACE_CLIP) {
SpaceClip *sc = static_cast<SpaceClip *>(area->spacedata.first);
if (ED_space_clip_color_sample(sc, region, region_mval, r_col)) {
if (ED_space_clip_color_sample(sc, region, mval, r_col)) {
return;
}
}
@@ -375,8 +381,8 @@ void eyedropper_color_sample_fl(bContext *C, const int event_xy[2], float r_col[
if (win) {
/* Other areas within a Blender window. */
if (!WM_window_pixels_read_sample(C, win, mval, r_col)) {
WM_window_pixels_read_sample_from_offscreen(C, win, mval, r_col);
if (!WM_window_pixels_read_sample(C, win, event_xy_win, r_col)) {
WM_window_pixels_read_sample_from_offscreen(C, win, event_xy_win, r_col);
}
const char *display_device = CTX_data_scene(C)->display_settings.display_device;
ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device);

View File

@@ -394,8 +394,8 @@ static int view_edge_pan_modal(bContext *C, wmOperator *op, const wmEvent *event
View2DEdgePanData *vpd = static_cast<View2DEdgePanData *>(op->customdata);
wmWindow *source_win = CTX_wm_window(C);
int r_mval[2];
wmWindow *target_win = WM_window_find_under_cursor(source_win, event->xy, &r_mval[0]);
int event_xy_target[2];
wmWindow *target_win = WM_window_find_under_cursor(source_win, event->xy, &event_xy_target[0]);
/* Exit if we release the mouse button, hit escape, or enter a different window. */
if (event->val == KM_RELEASE || event->type == EVT_ESCKEY || source_win != target_win) {

View File

@@ -280,8 +280,8 @@ ImBuf *ED_space_clip_get_stable_buffer(const SpaceClip *sc,
bool ED_space_clip_get_position(const SpaceClip *sc,
const ARegion *region,
int mval[2],
float fpos[2])
const int mval[2],
float r_fpos[2])
{
ImBuf *ibuf = ED_space_clip_get_buffer(sc);
if (!ibuf) {
@@ -289,7 +289,7 @@ bool ED_space_clip_get_position(const SpaceClip *sc,
}
/* map the mouse coords to the backdrop image space */
ED_clip_mouse_pos(sc, region, mval, fpos);
ED_clip_mouse_pos(sc, region, mval, r_fpos);
IMB_freeImBuf(ibuf);
return true;
@@ -545,9 +545,12 @@ void ED_clip_point_stable_pos__reverse(const SpaceClip *sc,
r_co[1] = (pos[1] * height * zoomy) + float(sy);
}
void ED_clip_mouse_pos(const SpaceClip *sc, const ARegion *region, const int mval[2], float co[2])
void ED_clip_mouse_pos(const SpaceClip *sc,
const ARegion *region,
const int mval[2],
float r_co[2])
{
ED_clip_point_stable_pos(sc, region, mval[0], mval[1], &co[0], &co[1]);
ED_clip_point_stable_pos(sc, region, mval[0], mval[1], &r_co[0], &r_co[1]);
}
bool ED_space_clip_check_show_trackedit(const SpaceClip *sc)

View File

@@ -3334,7 +3334,10 @@ void IMAGE_OT_unpack(wmOperatorType *ot)
/** \name Sample Image Operator
* \{ */
bool ED_space_image_get_position(SpaceImage *sima, ARegion *region, int mval[2], float fpos[2])
bool ED_space_image_get_position(SpaceImage *sima,
ARegion *region,
const int mval[2],
float r_fpos[2])
{
void *lock;
ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock, 0);
@@ -3344,7 +3347,7 @@ bool ED_space_image_get_position(SpaceImage *sima, ARegion *region, int mval[2],
return false;
}
UI_view2d_region_to_view(&region->v2d, mval[0], mval[1], &fpos[0], &fpos[1]);
UI_view2d_region_to_view(&region->v2d, mval[0], mval[1], &r_fpos[0], &r_fpos[1]);
ED_space_image_release_buffer(sima, ibuf, lock);
return true;